The Red machine: My simulator


Home Page
The Red Home Page

Introduction

To study the RED cipher machine, I had to write a simulator for this machine. Here is the download link for my simulator : my simulator.

Suggestion to install the software

  • Open a terminal.
  • Download the software with the curl command:
            C:\> curl -O http://www.jfbouch.fr/crypto/red/red_simu.tar
         
  • Unzip:
            C:\> tar xf red_simu.tar
         
  • Position yourself in the created directory:
            C:\> cd red_simu
         
  • Print the manual (this page):
            C:\red_simu> more README
         

Quick start

Print syntax

       C:\red_simu> python red_tui.py -h
       usage:
       Syntax : red_tui.py [options...]
       Example: echo HELLO | python red_tui.py
                HAJHY
       Options:
       -I internal The rotors wiring, by defaut vigenere
           Note: the Internal Key file need to end by .rot
           and it must be in the ROTORS directory
       -W startpos The starting positions of wheels
           [breakwheel, voyel half-rotor, consonant half-rotor, 1,1,1 by default
       -G plug     The plugboard, by default:  AEIOUYBCDFGHJKLMNPQRSTVWXZ
                   The first six letters correspond to the sixes and the following
                   ones to the twenties.
       -P pins     The Pins, by default 11111111111 [5,6,11,12,17,20,30,31,34,39,40]
                   if length of pins is 47, we give the absolute value of pins
       -d | -c     Decipher or Cipher Mode (cipher mode by default)
       -V | -R     Verse or Reverse Mode (V [or Direct mode] by default)
       -S          Only decipher the Sixes
       -D          Debug Mode

Make the example work

  C:\red_simu> echo HELLO | python red_tui.py
  HAJHY

Encrypt or decrypt a file

  • We create the file
      C:\red_simu>echo to be or not to be > MSGS\tobe.txt
      
  • We encrypt the file
      C:\red_simu>python red_tui.py < MSGS\tobe.txt
      TIXUYLGIKJYME
      
  • Idem, but we print the result by group of 5 letters :
      C:\red_simu>python red_tui.py < MSGS\tobe.txt |python groupe.py
      TIXUY LGIKJ YME
      
  • We keep the encryption in a file (the -c option is the default)
      C:\>\red_simu>python red_tui.py -c < MSGS\tobe.txt  > MSGS\tobe.cry
      
  • We decrypt a file
      C:\red_simu>python red_tui.py -d < MSGS\tobe.cry
      TOBEORNOTTOBE
      

Encrypt messages realistically

Choosing the wiring for the half rotors

By default, the two half-rotors are wired directly, resulting in a progressive Vigenere-type encryption. The wiring of the two half-rotors is stored in a file with the ".rot" extension, which is stored in the ROTORS directory.

Here is the default wiring (vigenere.rot file):

C:\red_simu>more ROTORS\vigenere.rot
AEIOUY
AEIOUY
BCDFGHJKLMNPQRSTVWXZ
BCDFGHJKLMNPQRSTVWXZ
Here is the wiring corresponding to the examples provided by Mr Konheim
C:\red_simu>more ROTORS\konheim.rot
AEIOUY
UIOAYE
BCDFGHJKLMNPQRSTVWXZ
QTGVNWJFCKZHXBDRPSLM
Let's try to reproduce Mr. Konkeim's first ciphertext (cipherEx7.3):
C:\red_simu> more MSGS\konheim.txt
The issue of performance evaluation and prediction has concerned users
throughout the history of computer evolution In fact as in any other
technological development the issue is most acute when the technology is
young the persistent pursuit of products with improved cost performance
characteristics then constantly leads to untried uncertain features from
the initial conception of a system architectural design to its daily
operation after installation in the early planning phase of a new computer
system product the manufacturer

C:\red_simu> python red_tui.py -I konheim < MSGS\konheim.txt | python groupe.py
RVAAX WYEUK TOLFU HPYCV AYMYW UIJYE MOKPP HIKEV RUAVR EVLAN
HYLJI MOHUC DQTWI AGNUI FDHEF AJVAC YOSQA DZIHO NEZOK AWIUB
YXSOP LATON ILOEZ DAFTO TVWOW EGIKE PRIXA JILME ZQPSI IVTEO
OPTOL XUXOS URTET LPOHE HJKEK YSUYF EYOVJ LPEWY NPOMZ YFVKU
BCEUM YNXQE SUFBL ZOVZA KGXYK YXLAR FSUKD YGNAB TERSA TULHY
NUNBE BJVZE ZSIVX LIQHQ ENAEN KWYOB RZOEB IRLIP FEYJD EIVEC
ICSWI DKNAA MUCII JZECV AGPUA SUMAR EPCYR YGXZA RORNO TASVE
QAXJZ YEVGH UIZUI BIRIG YEKOD XUFOB DQAXW OKAIN OLCGU OUFFU
HBUVT ARFWL IPUED OFYVV AJFIM OSTYR FOTQJ OLAWS RVUGU SOMAJ
FULYJ

Remove pins from the breakwheel

If we remove pins from the breakwheel, the half-rotors will no longer advance regularly but in spurts. Consequently, the half-rotors controlled by the breakwheel will also advance erratically. Remember that if we remove a pin, the wheels' advancement is doubled: we don't advance by a single step, but by two. The breakwheel contains 47 pins. The following pins can be removed: 5, 6, 11, 12, 17, 20, 30, 31, 34, 39, and 40.

In my simulator, the -P option controls pin removal. By default, no pins are removed. If we want to reproduce Mr. Konheim's second example, we use the following argument: 00110111011, which corresponds to the removal of pins 5, 6, 17, and 34. The period will therefore be 47-4=43.

Let's try to reproduce Mr. Konkeim's second ciphertext (cipherEx7.4):

C:\red_simu> python red_tui.py -I konheim -P 00110111011 -W 2,1,1 < MSGS\konheim.txt | python groupe.py
RVAAV TOYIH REJCE DLIXR OIJIS EYFIU HYFKK CUFOQ MAIQM OQDAG
ZYDBI FOXOS THLNE YWFOE VTXYT UXLUR OEJGU SPAWE BOMYW IKUAN
AKFUB WEGUZ OWUIL PAPFO FGHOH EQITE ZCIGU QASTY HXWZY YCBUA
AVBAR FEFAX AWZOZ QTYMO MNPOP EVUYH EYOXL NQAXU PQINB UGWLO
CDYIM ONXQY SIFBL ZEVZI HDVEH EVJIN BPYGZ ACKEW QINPE PUGCY
JUJVE VDQTE TNANQ DAJZJ YGOUF BNIAR JQAUR YJCUF TOEXS OULOR
URJMU QWBAA ZUPII TLANH YRBOY FOXYD AZMOC OQJKU CECXE FUDDO
XIGQH EODMN YOGYO HOXOM AIQUJ DUKOG JVADC OPAIS ONFJI EIHHI
KCEWV OSGXM YQEUF AGEVV IJFUM YSTER FYTQG OJATQ PSUDO PIJYF
BOHUF
Note: The -W option specifies the initial position of the wheels. By default, it is 1,1,1. Due to a peculiarity of the algorithm followed by Konheim, I am forced to take a different starting position: 2,1,1.

Using main options

Here's an example using the main options:

  • We're using Mr. Konheim's half-rotor wiring (-I)
  • We're removing pins 5, 6, 17, and 34 (-P)
  • We're using the plugboard configuration as follows (-G):
    • Sixes: KAQWDE
    • Twenties: BOUHVMJYXFTGPLISZNRC
  • We're working in cipher mode (-c)
  • We're in direct mode (-V)
  • The starting position of the wheels is (-W):
    • Breakwheel: 10 (from 1 to 47)
    • Half-rotor vowel: 3 (from 1 to 6)
    • Half-rotor consonant: 10 (from 1 to 20)
C:\red_simu> python red_tui.py -I konheim -P 00110111011 -W 10,3,10 -c -V
-G KAQWDEBOUHVMJYXFTGPLISZNRC < MSGS\konheim.txt | python groupe.py

TJWTB CFDNX REJVG HGKJB QARKM XQOHS LWGDL UWKLC XXBRC EIFIP
JWUYK WIUQS CVBGN MMIPB ILFDY PUYUI XCTGI SSBID OQOMX GMYCN
VSYQY ZEXZY KVPHJ UEPUQ TZLLN GBIBW FDEZW VRCNW PZSGD SMVIE
TBHCZ ODFHN EWGQY GYDXQ IBNNO SVOCF NXZMS XVEVW PZVIC WGSLR
OMSPX HIVLC WJTNT WNLFI XXNUZ EQPNI CNDMH TUTEV RKZUD PQGBD
YBTSN HVFMD OSBRZ OWLNN CSQQD VFVPO MLMQE VLYWV IASJR QQYGP
ASXXI SZPES JLFGE YSBRP DCCOL TTOQM IHXQV ALLCV BKJSC UKPAQ
UTGCH RVBLA WCZRF GQCKY FOCAT OWXOP TSDIL EXTUB YRURA EEMZR
PLEMV GUPVO WSESJ WGKDH XFFIX DSCJS BQZZM GAROT FMQVA CXTWT
CHJWH
In the following example, reverse mode (-R) is used:
C:\red_simu> echo HELLO | python3 red_tui.py -R
HINPE

Explore other options

Use the 47 pins

If you're looking for the position of the pins by trial and error, I found it easier to express all 47 pins. My simulator allows this.

C:\red_simu> echo TO BE OR NOT TO BE | python red_tui.py
TIXUYLGIKJYME

C:\red_simu> echo TO BE OR NOT TO BE | python red_tui.py -P 01111111111
TIXUYKFEJHULA

We have the same result by removing the 5th Pin.
C:\red_simu> echo TO BE OR NOT TO BE | python red_tui.py -P 11110111111111111111111111111111111111111111111
TIXUYKFEJHULA

Show that the decipherment of the Sixes

Usually, we first search for the starting position of the vowel half-rotor and the vowel plugboard. Showing only the action of the Sixes on encryption/decryption is very helpful. The -S option allows this.

C:\red_simu>python red_tui.py -S -d < MSGS\tobe.cry
-O-EO--O--O-E

C:\red_simu>more MSGS\tobe.txt
to be or not to be

The Debug option

The Debug option (-D) allows you to know in detail the action of the half-rotors as well as the details of an encryption or decryption operation.

C:\red_simu>echo HELLO | python red_tui.py -I konheim -c -D
Vowel Half-rotor:
      1  2  3  4  5  6
      A  E  I  O  U  Y
 1 :  5  3  4  1  6  2
 2 :  4  2  3  6  5  1
 3 :  3  1  2  5  4  6
 4 :  2  6  1  4  3  5
 5 :  1  5  6  3  2  4
 6 :  6  4  5  2  1  3

Consonant Half-rotor:
      1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
      B  C  D  F  G  H  J  K  L  M  N  P  Q  R  S  T  V  W  X  Z
 1 : 13 16  5 17 11 18  7  4  2  8 20  6 19  1  3 14 12 15  9 10
 2 : 12 15  4 16 10 17  6  3  1  7 19  5 18 20  2 13 11 14  8  9
 3 : 11 14  3 15  9 16  5  2 20  6 18  4 17 19  1 12 10 13  7  8
 4 : 10 13  2 14  8 15  4  1 19  5 17  3 16 18 20 11  9 12  6  7
 5 :  9 12  1 13  7 14  3 20 18  4 16  2 15 17 19 10  8 11  5  6
 6 :  8 11 20 12  6 13  2 19 17  3 15  1 14 16 18  9  7 10  4  5
 7 :  7 10 19 11  5 12  1 18 16  2 14 20 13 15 17  8  6  9  3  4
 8 :  6  9 18 10  4 11 20 17 15  1 13 19 12 14 16  7  5  8  2  3
 9 :  5  8 17  9  3 10 19 16 14 20 12 18 11 13 15  6  4  7  1  2
10 :  4  7 16  8  2  9 18 15 13 19 11 17 10 12 14  5  3  6 20  1
11 :  3  6 15  7  1  8 17 14 12 18 10 16  9 11 13  4  2  5 19 20
12 :  2  5 14  6 20  7 16 13 11 17  9 15  8 10 12  3  1  4 18 19
13 :  1  4 13  5 19  6 15 12 10 16  8 14  7  9 11  2 20  3 17 18
14 : 20  3 12  4 18  5 14 11  9 15  7 13  6  8 10  1 19  2 16 17
15 : 19  2 11  3 17  4 13 10  8 14  6 12  5  7  9 20 18  1 15 16
16 : 18  1 10  2 16  3 12  9  7 13  5 11  4  6  8 19 17 20 14 15
17 : 17 20  9  1 15  2 11  8  6 12  4 10  3  5  7 18 16 19 13 14
18 : 16 19  8 20 14  1 10  7  5 11  3  9  2  4  6 17 15 18 12 13
19 : 15 18  7 19 13 20  9  6  4 10  2  8  1  3  5 16 14 17 11 12
20 : 14 17  6 18 12 19  8  5  3  9  1  7 20  2  4 15 13 16 10 11

PINS Wheel:
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
0->(1),1->(1),2->(1),3->(1),4->(1),5->(1),6->(1),7->(1),8->(1),9->(1),10->(1),11->(1),12->
(1),13->(1),14->(1),15->(1),16->(1),17->(1),18->(1),19->(1),20->(1),21->(1),22->(1),23->(1
),24->(1),25->(1),26->(1),27->(1),28->(1),29->(1),30->(1),31->(1),32->(1),33->(1),34->(1),
35->(1),36->(1),37->(1),38->(1),39->(1),40->(1),41->(1),42->(1),43->(1),44->(1),45->(1),46
->(1),
  1: ( 1, 1, 1) Plain: H( 7)-> Plug:  6  Twent H => After HRCON: W (18)  Crypto: W (22)
  2: ( 2, 2, 2) Plain: E( 4)-> Plug:  2  Sixes E => After HRVOY: E ( 2)  Crypto: E ( 4)
  3: ( 3, 3, 3) Plain: L(11)-> Plug:  9  Twent L => After HRCON: Z (20)  Crypto: Z (25)
  4: ( 4, 4, 4) Plain: L(11)-> Plug:  9  Twent L => After HRCON: X (19)  Crypto: X (23)
  5: ( 5, 5, 5) Plain: O(14)-> Plug:  4  Sixes O => After HRVOY: I ( 3)  Crypto: I ( 8)
WEZXI
Before encryption (or decryption), the simulator displays the following information:
  • The vowel half-rotor cipher table.
  • The consonant half-rotor cipher table.
  • The absolute pin positions (the first pin is numbered 0).
For each encryption operation, the simulator displays the following information:
  • The character number (1, 2, etc.)
  • The wheel positions (Breakwheel, vowel half-rotor, consonant half-rotor)
  • The input character (Plain if in encryption mode).
  • The plugboard action
  • Whether the letter is part of the Sixes or Twenties.
  • The half-rotor action (HRCON = consonant half-rotor, HRVOY = vowel half-rotor)
  • The resulting letter (Crypto if in encryption mode)
Finally, the resulting text.

Reference

  • Computer security and cryptography, by Alan G. Konheim, Wiley, 2007.