14
4
Steganographic Squares
Your job is to take in a string, and generate an NxN
image that represents this string. You must also write the algorithm that takes in the image and turns it back into a string as well. The scoring will be will include the byte count of both algorithms:
"Encryption" Algorithm + "Decryption" Algorithm.
You should post each separately, with byte-counts for both the encryption and decryption algorithms displayed individually.
Example Algorithm
For instance, here's the "Programming Puzzles and Code Golf" using a simple ASCII based steganographic algorithm in the Blue channel:
#2e7250,#6ea972,#04eb6f,#0fc767,#74ab72,#ee6161
#b73b6d,#1aae6d,#f37169,#bda56e,#1fe367,#e99620
#706450,#0d3575,#146b7a,#4ea47a,#2a856c,#95d065
#3f2d73,#cef720,#bab661,#d1b86e,#f22564,#12b820
#0f3d43,#c86e6f,#1ee864,#a66565,#247c20,#c3bb47
#0e296f,#89d46c,#585b66,#c08f20,#455c20,#136f20
You can see the blue channel simply holds the ascii values for this image:
50 = 80(P) 72 = 114(r) 6f = 111(o) 67 = 103(g) 72 = 114(r) 61 = 97(a)
6d = 109(m) 6d = 109(m) 69 = 105(i) 6e = 110(n) 67 = 103(g) 20 = 32( )
50 = 80(P) 75 = 117(u) 7a = 122(z) 7a = 122(z) 6c = 108(l) 65 = 101(e)
73 = 115(s) 20 = 32( ) 61 = 97(a) 6e = 110(n) 64 = 100(d) 20 = 32( )
43 = 67(C) 6f = 111(o) 64 = 100(d) 65 = 101(e) 20 = 32( ) 47 = 71(G)
6f = 111(o) 6c = 108(l) 66 = 102(f) 20 = 32( ) 20 = 32( ) 20 = 32( )
While the rest of the channels hold randomly generated values to "spice up" the variety of colors in the image. When pulling the message back out of the image, we can just simply ignore the other channel values, and pull the hex bit in the blue channel, reconstructing the string:
"Programming Puzzles and Code Golf"
Notice the spaces that were used to pad the string in the square are not included in the final decrypted output. While you must pad the string in the image, you may assume that the input string will not end with spaces.
Rules
- You must encode 1 character per pixel, the channel chosen to encode the char is arbitrary.
- The channels of the other RGB colors must be randomized, other than the one you're choosing to encode the string into; this means your final non-encoded channels would need to be between
0x0000-0xFFFF
(randomly chosen). - Expressing the final result as a 2D array of RGB color values is fine
0x000000-0xFFFFFF
, no need to use image creation unless you want to have fun with it or if it's less bytes. If you choose to output as hex strings, prefix the hex string with#
E.G.#FFFFFF
or#05AB1E
. You may separate with tabs, commas, or anything else that would be horizontally sensible, but it must maintain the square pattern; in other words, you must use appropriate newline separation. - The output must be in a square, and the string must be padded with spaces at the end to accomodate this. This means that
N≈SQRT(Input#Length())
. If the input length is not a perfect square, you should round up onN
and pad with spaces. - As stated previously, if you are padding with spaces in the image, you must not include the padded characters in the final "decrypted" output.
- You can assume that:
- The input string will not end with spaces.
- The input string will only use printable ASCII characters.
- This is code-golf, lowest byte count wins.
Just to clarify, solutions must encode/decode exactly one character per pixel? – ETHproductions – 2016-11-12T16:00:25.333
@ETHproductions that sounds like a good follow-up challenge, but for the purpose of this competition, you pick an encoding channel and encode 1 character per pixel. – Magic Octopus Urn – 2016-11-12T16:03:12.023
I'm probably not going to use this, but: is it OK to "overpad" the image with more spaces than necessary? And is it OK to assume that the image will have the same amount of overpadding as the encoder would generate? – None – 2016-12-01T17:48:16.630
@ais523 I cannot see how this type of approach would do anything but require more bytes to implement. I'm going to go with no though, as the challenge is too old to make large changes like that. – Magic Octopus Urn – 2016-12-01T18:05:26.690
1Right, I wasn't sure if it was allowed in the original question, rather than recommending a change. (I was thinking about packing the input into a rectangle, which has easier and thus possibly byte-shorter coordinate calculations than packing it into a square, then padding the rectangle out to a larger square.) – None – 2016-12-01T18:19:00.007
What is meant by the line Expressing the final result as a 2D array of RGB color values is fine? Can the output of the encoder be a 2D array or does it need to be formatted in a square? – Emigna – 2016-12-06T10:19:54.430
@Emigna see the Jelly answer. – Magic Octopus Urn – 2016-12-06T14:42:18.673
You should probably remove the text about 2D arrays being fine if it's not allowed. It only adds confusion (at least it did for me). – Emigna – 2016-12-06T14:50:52.270
@Emigna it *IS* allowed, see the Jelly answer here: http://codegolf.stackexchange.com/a/102159/59376
– Magic Octopus Urn – 2016-12-06T15:16:31.323Ah sorry, I misunderstood you. At a glance I didn't see the commas in the Jelly answer so I figured you meant the opposite. – Emigna – 2016-12-06T15:20:38.943