OTP

From Koset Surakomol

Jump to: navigation, search

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). pre A XOR B = C /pre

One line of C code!

This is all the programming required.

otp.c pre main(i,c)int*c;{for(c=fopen(c[1],r);~(i=getchar());putchar(getc(c)^i));} /pre Source

Compile with pre % cc -o otp otp.c /pre

Invoke with pre % otp pad msg cipher /pre

Try it out

First make a pad with random bytes. For example, pre % dd if=/dev/random count=1000000 of=mypad /pre

In this case, the file msg.txt contains our text. pre Hello, world! /pre

Let's encrypt the text. pre otp mypad msg.txt msg.encrypted /pre

The new file msg.encrypted is the encrypted version of our file msg.txt, so let's see if we can get it back. pre otp mypad msg.encrypted Hello, world! /pre

Indeed it works. The key to all this is two things,

  1. Our ability to generate extremely random data for our pad. If it is at all predictable, then the process falls apart.
  2. Our ability to keep the pad file secure and out of the wrong hands.

See AES as an alternative.

Personal tools