Post

Just One Time

Just One Time

JOT

I have always had an interest in Cryptography, ever since reading Simon Singh’s The Code Book. Truly, it is a fascinating area of study and very necessary for secure communications, should the need arise. Public Key encryption with GPG/PGP is already a great option. But I always come back to the One Time Pad. It’s the only uncrackable code, providing you use it correctly (once).

For ultimate security, no compromise one-time pads, you should generate the numbers manually by hand with dice in a dark room with no electronic devices around. Or you can use the following script. This will run on any Linux distribution from the terminal. Ideally, you would run this code on an offline, air-gapped computer that has never connected to the internet.

The Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#
key=$(printf "%05d" $RANDOM)
echo "-----------------------------"
echo "| ONE TIME PAD - KEY: $key |"
echo "-----------------------------"
#
for i in {1..10}; do
    # For the first line, reuse the stored number so it's identical
    if (( i == 1 )); then
        printf "%s %05d %05d %05d %05d\n" "$key" $RANDOM $RANDOM $RANDOM $RANDOM
    else
        printf "%05d %05d %05d %05d %05d\n" $RANDOM $RANDOM $RANDOM $RANDOM $RANDOM
    fi
done
# Without A Repeated Key
#for i in {1..10}; do
#    printf "%s %05d %05d %05d %05d\n" $key $((RANDOM % 100000)) $((RANDOM % 100000)) $((RANDOM % 100000)) $((RANDOM % 100000))
#done
echo
echo ".:EN- | DE+ | TEXT/KEY:."
echo
echo "=========================="
echo "|  CONVERSION TABLE #1   |"
echo "=========================="
echo "A-1   B-70   P-80   FIG-90"
echo "E-2   C-71   Q-81   (.)-91"
echo "I-3   D-72   R-82   (:)-92"
echo "N-4   F-73   S-83   (')-93"
echo "O-5   G-74   U-84   (,)-94"
echo "T-6   H-75   V-85   (+)-95"
echo "      J-76   W-86   (-)-96"
echo "      K-77   X-87   (=)-97"
echo "      L-78   Y-88   (?)-98"
echo "      M-79   Z-89   SPC-99"
echo "=========================="
echo
# Generate Several OTPs at once
#for i in {1..5}; do
#./OTP.sh >> OTPs.txt
# done

You can copy & paste this code into a file. Then save it as with a script extension, something like OTP.sh then just make it executable in the shell.

1
chmod + x OTP.sh

To run the script and generate the pad, you just run the script in the shell.

1
./OTP.sh

The Tutorial

Here is how to use the One-Time Pad to encrypt and decrypt a message.

1. Run the script to generate a One Time Pad

JOT

It spits out a 5 digit key and 5 Columns of 5 digit numbers with 10 rows.

JOT

It also generates the usage hint and a conversion table.

The hint tells you to ENcrypt you subtract (-). To DEcrypt, you add (+). And, your message text goes over (/) the key.

The conversion table allows you to transcode your plain text message into numbers.

2. Transcode Your Plain Text Message

  • Using the conversion table, convert your message into numbers.
  • Do not use the key as part of the encryption. Start with the numbers to the right of the key.
  • If you get a negative number in the encryption process, just add 10 to the top number

3. Example

Plain Text

“Meet me at the old place”

Transcoded

Meet me at the old place
7922699792991699675299578729980781712
3148213100097770931825027106410096910
  • The One Time Pad Numbers Starting After The Key
3148213100097770931825027106410096910

Encrypted Message (Subtracted)

4884486692904929744474551623570795802
  • Encrypted Message: 4884486692904929744474551623570795802

  • You can present the encrypted text in groups of 5 to make it easier to work with.

48844 86692 90492 97444 74551 62357 07958 02

Decrypt the Cipher Text

To Decrypt, you just do the process in reverse, adding the numbers from the One Time Pad.

48844 86692 90492 97444 74551 62357 07958 02

31482 13100 09777 09318 25027 10641 00969 10

79226 99792 99169 96752 99578 72998 07817 12

7922699792991699675299578729980781712
MEET ME AT THE OLD PLACE

“Meet me at the old place”

Generate a Few at a Time

Tucked at the bottom of the main script is some code to generate 5 of these at one time and append them to a text file. This is good for generating a few Pads at once that could be easily shared among Mutual Assistance Group and such.

1
2
3
4
#Generate Several OTPs at once
for i in {1..5}; do
./OTP.sh >> OTPs.txt
done

73 de VE5REV

This post is licensed under CC BY 4.0 by the author.