2
1
In Applied Cryptography by Bruce Schneier (which I have been reading quite a lot recently), a protocol for splitting secrets is discussed. Here is a brief description:
- Trent generates a random byte string, R, the same length as the message, M.
- Trent XORS M with R to make S.
- He gives R to Alice and S to Bob.
Your task is to, given an input, split the input into two output files or print the split secret to STDOUT. One output/part of output should contain the random string; the other should contain the original input XOR'd with the random string. Input and output may be to/from files or to/from STDIN/STDOUT. Outputting to STDERR is also allowed.
There are a few restrictions, however:
- Your program must take 1 input (1 input filename & 2 outputs if doing file I/O), and output the random string and the original string XOR'd with that random string into the other.
- Your program must be cryptographically secure. All random number generators must be cryptographically secure. For example,
/dev/random
is fine, but the Mersenne Twister (usuallyrandint(number,number)
is not. Any random number generator must be explicitly cryptographically secure.- If you want to know anything more about what "cryptographically secure" means, check here.
- Standard rules and loopholes apply.
This is code-golf, so the code with the fewest bytes will win.
May the best coder prosper...
6-1 for the cryptographically secure part. It doesn't add much to the challenge, other than making answers work around that restriction. It's not harder, just another step. – Rɪᴋᴇʀ – 2017-03-23T21:51:38.643
@Riker I felt like that adds to the challenge, personally, but I hear you. – ckjbgames – 2017-03-23T21:52:44.207
This is similar, but this isn't necessarily alphanumeric. – ckjbgames – 2017-03-23T21:54:04.550
"random string" String of bits, bytes, or printable ASCII chars? – ETHproductions – 2017-03-23T22:01:41.467
@ETHproductions If you aren't doing file I/O, these aren't needed. – ckjbgames – 2017-03-23T22:07:37.500
@ETHproductions Bytes – ckjbgames – 2017-03-23T22:07:42.510
Also, a thank you to whoever starred this question. – ckjbgames – 2017-03-23T22:10:39.070
@ETHproductions You're welcome :) – ckjbgames – 2017-03-23T22:12:39.097
Is XORing done bitwise for each byte? Can we assume any character-to-bytes encoding? – Luis Mendo – 2017-03-23T22:22:09.110
Can we take input and output as arrays of bytes, rather than strings? – ETHproductions – 2017-03-23T22:28:56.120
@LuisMendo It is done for each byte, and you can assume any encoding that actually exists. – ckjbgames – 2017-03-23T22:29:51.277
@ETHproductions Yes. I actually encourage that, in fact. – ckjbgames – 2017-03-23T22:30:11.650
Is I/O in hexadecimal acceptable? – Dennis – 2017-03-24T16:56:47.277