OTP
From Koset
What is it?
The One Time Pad is a method for encrypting information. Theoretically, it could be the most secure method.
How it works
This is so elegantly simple that it requires one simple operation: Each input byte (A) XOR'd with a successive byte of the pad (B) produces a byte of encrypted output (C).
A XOR B = C
One line of C code!
This is all the programming required.
otp.c
main(i,c)int*c;{for(c=fopen(c[1],"r");~(i=getchar());putchar(getc(c)^i));}
Compile with
% cc -o otp otp.c
Invoke with
% otp pad < msg > cipher
Try it out
First make a pad with random bytes. For example,
% dd if=/dev/random count=1000000 of=mypad
In this case, the file msg.txt contains our text.
Hello, world!
Let's encrypt the text.
otp mypad < msg.txt > msg.encrypted
The new file msg.encrypted is the encrypted version of our file msg.txt, so let's see if we can get it back.
otp mypad < msg.encrypted Hello, world!
Indeed it works. The key to all this is two things,
- Our ability to generate extremely random data for our pad. If it is at all predictable, then the process falls apart.
- Our ability to keep the pad file secure and out of the wrong hands.
See AES as an alternative.
