[Cryptography] 100-year-old secret revealed

Henry Baker hbaker1 at pipeline.com
Fri Dec 4 10:35:20 EST 2015

Dear Mr. Comey, Mr. Vance, Ms. May, at al:

The one-time pad is approximately 100 years old,
and provides perfect secrecy (so long as you don't
reuse the key material).

Here's the program in C (forgive the code author's
accent; his native language is Lisp):

int main(int argc, char *argv[])
{long long i; /* Count # bytes processed. */
 int ch1,ch2; /* The bytes from file1, file2 */
 FILE *fp;    /* file1=stdin, file2=fp */
 if (argc != 2)
           "xor: wrong # of args: %d\n",
   return 1;}
         "xor: opening file %s\n",
 if ((fp=fopen(argv[1],"rb"))==NULL)
           "xor: bad file arg: %s\n",
   return 1;}
 /* XOR stdin with fp; shortest file wins. */
 for (ch1=fgetc(stdin),ch2=fgetc(fp),i=0;
      (!feof(stdin)) && (!feof(fp));
 fclose(fp); fclose(stdin); fclose(stdout);
         "xor: bytes processed: %d\n",
         (int) i);
 return 0;}

Compile with: gcc -Wall -o xor xor.c

Get some key material:

head -c1024 /dev/random > key1024.bin

Make a secret message file:

echo "This is a secret message." > message.txt

Encode the message:

tail -c +123 key1024.bin | xor message.txt > message.enc

Decode the message:

tail -c +123 key1024.bin | xor message.enc > message.out

1.  You probably want a *much* longer key file: gigabytes long. 
Make 2 copies on USB drives; give one USB drive to your friend.

2.  Replace "+123" in the encode & decode by +n; the number n
is the index number of the first *unused* key bytes.


Gilbert Sandford Vernam

P.S.  There is no "back door". 
No tickee, no washee. 
Now let me rest in peace.

More information about the cryptography mailing list