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/randomis fine, but the Mersenne Twister (usually
randint(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...