# One Time Pads, Generation and Exchange

"Anyone who considers arithmetical methods of producing random numbers is, of course, living in a state of sin."
-- John Von Neumann (1903-1957)

I recommend building David Eather's Transistor Junction Noise Random Number Generator, a simple, easy to construct hardware RNG that plugs into your sound card. Other methods of truly random number generation are possible, such as using radioactive decay, atmospheric noise, quantum effects, lava lamps, or commercial TRNGs. But the transistor-junction noise device is the easiest to build, by far. If you lack the inclination required to build circuits, but have the financial abilities, consider paying someone to build it for you. Or if you're willing to learn, give it a shot. TODO: Post pictures and tutorial on building this.

Audacity can be used to record the noise. From the dropdown on the main window, change it from "Microphone" to "Wave Out Mix" for a better volume. David's noise generator is dual-channel, but I only built a single-channel RNG because my laptop only has a microphone input (no line in), therefore its mono and only records one channel. Under Windows, mono microphone recording records the left channel (tip), but under Linux it records the right (ring), so you can either use a DPDT switch to select the channel, use a mono jack, or wire both channels together and be sure to only record in mono.

If yours supports stereo, in Audacity go to Preferences -> Recording -> Channels, and select 2 (Stereo).

After recording a sufficient amount of random noise, you need to distill it. The RNG does not produce 8 bits of entropy per byte, rather about 5 bits. distill.py is included to do this. You need Python:

```python distill.py input.wav otp-1 5
```

The optional last argument (default 5), is how many bits of entropy there are per byte. David Eather says this is 5, and this value seems to work well. If otp-1 isn't random enough, you can decrease the bits of entropy per byte (try 4.9, 4.5, etc.). Fractional values are allowed, even less than 1, but if the TRNG is working correctly such drastic measures shouldn't be necessary. (Values greater than 8 will decrease entropy, but increase the file size.)

TODO: program to read /dev/dsp or Windows equivalent and monitor randomness.

Finally, check your pad's entropy using John Walker's ent program. See his page for how to interpret the results. Here is the output of ent on a large, distilled capture from the TRNG:

```Entropy = 7.999999 bits per byte.

Optimum compression would reduce the size
of this 286734080 byte file by 0 percent.

Chi square distribution for 286734080 samples is 247.30, and randomly
would exceed this value 50.00 percent of the times.

Arithmetic mean value of data bytes is 127.4943 (127.5 = random).
Monte Carlo value for Pi is 3.141707237 (error 0.00 percent).
Serial correlation coefficient is -0.000100 (totally uncorrelated = 0.0).
```

Here is a comparison between 12288 bytes from Hotbits, and 12288 distilled bytes from the homemade TRNG:

```John Walker's Hotbits
12288 bytes transferred in 0.002398 secs (5124240 bytes/sec)
Entropy = 7.984197 bits per byte.

Optimum compression would reduce the size
of this 12288 byte file by 0 percent.

Chi square distribution for 12288 samples is 266.21, and randomly
would exceed this value 50.00 percent of the times.

Arithmetic mean value of data bytes is 128.1309 (127.5 = random).
Monte Carlo value for Pi is 3.105468750 (error 1.15 percent).
Serial correlation coefficient is 0.007923 (totally uncorrelated = 0.0).

David Eather's Transistor Junction Noise Gen, Distilled
Entropy = 7.986972 bits per byte.

Optimum compression would reduce the size
of this 12288 byte file by 0 percent.

Chi square distribution for 12288 samples is 220.33, and randomly
would exceed this value 90.00 percent of the times.

Arithmetic mean value of data bytes is 128.0278 (127.5 = random).
Monte Carlo value for Pi is 3.111328125 (error 0.96 percent).
Serial correlation coefficient is -0.000064 (totally uncorrelated = 0.0).
```

There are other random number generator testers, such as RaBiGeTe - Random Bit Generators Tester which may be worth using.

That was the hard part...its all downhill from here.