Sigaba, my simulator


Home Page
The Sigaba Home Page

Description

I created a simulator of the Siagaba cipher machine. It works in text mode (TUI interface). It is written in Python and only uses the standard library. Consequently, it works on any platform on which the Python 3.x interpreter is installed (Windows, Linux, Mac-OS-X, etc.).

Installation

My simulator is in the form of a TARBALL: a compressed TAR file. Just download it from my website and then untar it.

Example :

C:\> curl -O http://www.jfbouch.fr/crypto/sigaba/sigabajf.tar
C:\> tar xf sigabajf.tar
After decompression, we obtain a file tree which starts at the sigabajf directory.

Show the syntax

Just use the -h option to display the syntax. We start by moving to the root directory of the software.

C:\>cd sigabajf

C:\sigabajf>dir /w
 Le volume dans le lecteur D s’appelle DATA
 Le numéro de série du volume est 9A86-5488

 Répertoire de D:\TMP\sigabajf

[.]              [..]             [LOGS]           [MSGS]           README.md
RotorBiFace.py   RotorIndx.py     [ROTORS]         sigaba.py        sigaba_tui.py
Syslog.py
...

C:\sigabajf>python sigaba_tui.py -h
Usage:
Syntax: sigaba_tui.py [option...]
Example:
 echo AAAAAAAAAAAAAAAA | python sigaba_tui.py \
   -m CSP-889  \
   -s ECM \
   -I 00R:01:02:03:04R=05:06:07R:08:09=10:20:30:40:50 \
   -E ABCDE:FGHIJ:01234 \
   -c
 [Expected: JTSCA LXDRW OQKRX]
 -h             Help
 -D prefix      DEBUG, if prefix equal LOG, use STDOUT
 -m model       CSP-889 by default (it exists also the CSP-2900 model)
 -s set         The set of rotors (ECM by default)
 -I internal    Internal Key, by default:
                00:01:02:03:04=05:06:07:08:09=10:20:30:40:50
                If the rotor is in Reverse position, it is followed by 'R'
                Example:  00:01R:02:03R:....
                Separators: , <,>, =, -, :
 -E external    External Key, OOOOO:OOOOO:00000 by default
 -N external    External Key but using Navy Indicator method, ex: -N MERDE
 -c/-d          The mode: Cipher/Decipher, by default: Power off
 [Note: order (I,E options): cipher rotors, ctrl rotors, index rotors]

Note: If you activate the program without option, it reads standard input. We must interrupt it with Ctrl-C or terminate standard input (via Ctrl-D on Unix or Ctrl-Z on Windows).

A simple example

To encrypt text, use the “-c” option. Plain text is read from standard input. For example, we want to encrypt the text HELLOWORLD.

C:\sigabajf> echo HELLOWORLD | python sigaba_tui.py -c
FLQGF ONNOE O

C:\sigabajf> echo HELLOWORLD > MSGS\plain.txt
C:\sigabajf> more MSGS\plain.txt
HELLOWORLD

C:\sigabajf> python sigaba_tui.py -c   < MSGS\plain.txt
FLQGF ONNOE O
Note: The Microsoft Windows system adds a space, which here is coded by the letter O. There is no additional character under Unix.

To decrypt a text, we use the “-d” option.

C:\sigabajf> echo FLQGF ONNOE O |python sigaba_tui.py -d
HELLOWORLD
Here are the default values used in the previous examples:
Model: CSP-889
Rotors set: ECM
Mode: ENCRYPT
Reset Mode: OPERATE
Rotor 00,0,YCHLQSUGBDIXNZKERPVJTAWFOM
Rotor 01,0,INPXBWETGUYSAOCHVLDMQKZJFR
Rotor 02,0,WNDRIOZPTAXHFJYQBMSVEKUCGL
Rotor 03,0,TZGHOBKRVUXLQDMPNFWCJYEIAS
Rotor 04,0,YWTAHRQJVLCEXUNGBIPZMSDFOK
Rotor 05,0,QSLRBTEKOGAICFWYVMHJNXZUDP
Rotor 06,0,CHJDQIGNBSAKVTUOXFWLEPRMZY
Rotor 07,0,CDFAJXTIMNBEQHSUGRYLWZKVPO
Rotor 08,0,XHFESZDNRBCGKQIJLTVMUOYAPW
Rotor 09,0,EZJQXMOGYTCSFRIUPVNADLHWBK
Rotor 10,0,7591482630
Rotor 20,0,3810592764
Rotor 30,0,4086153297
Rotor 40,0,3980526174
Rotor 50,0,6497135280
Key: OOOOO OOOOO 00000

The example given when displaying the syntax

C:\sigabajf>  echo AAAAAAAAAAAAAAA | python sigaba_tui.py ^
	-m CSP-889 -s ECM ^
	-I 00R:01:02:03:04R=05:06:07R:08:09=10:20:30:40:50 ^
	-E ABCDE:FGHIJ:01234 -c
JTSCA LXDRW OQKRX
Note: Under the command interpreter it is possible to enter a command on several lines. With the Unix shell, just enter the "\" character before validating. The command prompt changes to ">". With the Windows CMD tool, simply enter the "^" character. The command prompt changes to "Plus ?".

Here is the corresponding configuration:

  • Model: CSP-889
  • Set: ECM
  • Rotors
    • The encryption rotors (left to right). The letter R following the name of a rotor indicates it is in reverse mode: 00R 01 02 03 04R
    • The control rotors (left to right): 05 06 07R 08 09
    • The Index rotors: 10 20 30 40 50
  • Key: Initial positions of the rotors:
    • For encryption rotors (from left to right): A B C D E
    • For control rotors (left to right): F G H I J
    • For index rotors: 0 1 2 3 4
    Note: With a graphical simulator, this corresponds to 10 21 32 43 54 initial positions.
  • Mode: encryption
Note: In fact, the set of rotors corresponds concretely to a directory (ROTORS\ECM) which contains files with the extension *.rot for encryption and control rotors or the *.ri extension for Index rotors.

Example :

C:\sigabajf> more ROTORS\ECM\00.rot
YCHLQSUGBDIXNZKERPVJTAWFOM

Alpha wheel 0
C:\sigabajf> more ROTORS\ECM\10.ri
7591482630

Rotor Index 10

Debugging

It is possible to obtain debugging information using the “-D” option followed by a word. If this word is "LOG", the Debugging information will be visible on the screen. If this is not the case, a log file is created in the LOGS directory and whose prefix corresponds to the word following option D.

WARNING! The log is very detailed. It can only be used if very few letters (1,2 or 3) are encrypted (or deciphered), otherwise the log becomes enormous.

Here is an example:

  • Model: CSP-2900
  • Set: ECM
  • Rotors:
    • Cipher ones: 08R 02 05R 09 01
    • Control ones: 07 00R 04 03 06R
    • Index ones: 30R 10 50R 40 20
  • Key:
    • Cipher Rotors: M E R D E
    • Control rotors: S H I T S
    • Index rotors: 0 1 7 8 9
  • Mode: Encryption
C:\sigabajf> echo THE ZEBRE | python sigaba_tui.py -m CSP-2900 -s ECM ^
	-I 08R:02:05R:09:01=07:00R:04:03:06R=30R:10:50R:40:20 ^
	-E MERDE:SHITS:01789 -c -D MRD
ZTABW AULD

C:\sigabajf> echo ZTABW AULD | python sigaba_tui.py -m CSP-2900 -s ECM ^
	-I 08R:02:05R:09:01=07:00R:04:03:06R=30R:10:50R:40:20 ^
	-E MERDE:SHITS:01789 -d -D MRD2
THE XEBRE
Here is the start of the log file (LOGS\MRD_log.txt):
DEBUG 7 9507  ---Starting Logging----
INFO 6 9507  kargs:{'debug': True, 'ident': 'MRD', 'rep': 'ECM', 'model': 'CSP-2900', 'mod
e': 3, 'intKey': ['08', '02', '05', '09', '01', '07', '00', '04', '03', '06', '30', '10',
'50', '40', '20'], 'verse': [1, 0, 1, 0, 0, 0, 1, 0, 0, 1], 'verseIdx': [1, 0, 1, 0, 0]}
NOTICE 5 9507  Mode: ENCRYPT
INFO 6 9507  Model: CSP-2900
INFO 6 9507  Rotors set: ECM
INFO 6 9507  Mode: ENCRYPT
INFO 6 9507  Reset Mode: OPERATE
INFO 6 9507  Rotor 08,1,XHFESZDNRBCGKQIJLTVMUOYAPW
INFO 6 9507  Rotor 02,0,WNDRIOZPTAXHFJYQBMSVEKUCGL
INFO 6 9507  Rotor 05,1,QSLRBTEKOGAICFWYVMHJNXZUDP
INFO 6 9507  Rotor 09,0,EZJQXMOGYTCSFRIUPVNADLHWBK
INFO 6 9507  Rotor 01,0,INPXBWETGUYSAOCHVLDMQKZJFR
INFO 6 9507  Rotor 07,0,CDFAJXTIMNBEQHSUGRYLWZKVPO
INFO 6 9507  Rotor 00,1,YCHLQSUGBDIXNZKERPVJTAWFOM
INFO 6 9507  Rotor 04,0,YWTAHRQJVLCEXUNGBIPZMSDFOK
INFO 6 9507  Rotor 03,0,TZGHOBKRVUXLQDMPNFWCJYEIAS
INFO 6 9507  Rotor 06,1,CHJDQIGNBSAKVTUOXFWLEPRMZY
INFO 6 9507  Rotor 30,1,4086153297
INFO 6 9507  Rotor 10,0,7591482630
INFO 6 9507  Rotor 50,1,6497135280
INFO 6 9507  Rotor 40,0,3980526174
INFO 6 9507  Rotor 20,0,3810592764
INFO 6 9507  IKey: 01789
NOTICE 5 9507  Key: MERDE SHITS 01789
NOTICE 5 9507  ---> 0000: code <T>
NOTICE 5 9507  Encrypt:T>V:H:K:O:Z:>Z
DEBUG 7 9507  Current Injection
DEBUG 7 9507  Rotors ctrl input: 345678 DEFGHI
DEBUG 7 9507  D>E:R:L:L:J:>J
DEBUG 7 9507  E>Y:O:T:X:G:>G
DEBUG 7 9507  F>Z:G:Q:S:E:>E
DEBUG 7 9507  G>X:T:I:V:R:>R
DEBUG 7 9507  H>I:M:F:A:W:>W
DEBUG 7 9507  I>S:S:V:U:Q:>Q
DEBUG 7 9507  Rotors ctrl output: 00001010010000001100001000
DEBUG 7 9507  Rotors index input : 0001110010
DEBUG 7 9507  3>18529
DEBUG 7 9507  4>72160
DEBUG 7 9507  5>51741
DEBUG 7 9507  8>33673
DEBUG 7 9507  Rotors index output: 1101000001
DEBUG 7 9507  Advance cipher rotors: [1, 0, 0, 1, 1]
DEBUG 7 9507  Advancement of control rotors
NOTICE 5 9507  Key: NERED SHHTS 01789
NOTICE 5 9507  ---> 0001: code <H>
NOTICE 5 9507  Encrypt:H>C:V:D:C:T:>T
Remarks :
  1. For each encrypted (or decrypted) letter, the log displays the encryption details:
    NOTICE 5 5607  ---> 0000: code <T>
    NOTICE 5 5685  Encrypt:T>V:H:K:O:Z:>Z
    
    The counter shows the 0000 value. The letter T is encrypted as Z. The output of the first rotor gives the letter V. The output of the second rotor gives H, etc...

  2. Then, we have the detail of the advancement of the encryption rotors mainly due to the control rotors.
    1. We have the injection of electric current into the control rotors and the resulting currents output from the control rotors:
      DEBUG 7 7912  Rotors ctrl input: 345678 DEFGHI
      DEBUG 7 5843  D>E:R:L:L:J:>J
      DEBUG 7 5904  E>Y:O:T:X:G:>G
      DEBUG 7 5963  F>Z:G:Q:S:E:>E
      DEBUG 7 6021  G>X:T:I:V:R:>R
      DEBUG 7 6078  H>I:M:F:A:W:>W
      DEBUG 7 6137  I>S:S:V:U:Q:>Q
      DEBUG 7 6196  Rotors ctrl output: 00001010010000001100001000
      
      Thus, the current generated at the input at the letter D comes out at the letter J, etc...

      In the end, we have 6 cables which are electrified: 00001010010000001100001000
      If we translate this table into letters:....E.G..J......QR....W...

    2. At the input of the control rotors, we only have 10 entries, only four cables are electrified: 0001110010.
      DEBUG 7 6251  Rotors index input : 0001110010
      

    3. At the output of the index rotors, we have: 1101000001
      DEBUG 7 6308  3>18529
      DEBUG 7 6359  4>72160
      DEBUG 7 6408  5>51741
      DEBUG 7 6479  8>33673
      DEBUG 7 6520  Rotors index output: 1101000001
      

    4. We deduce the encryption rotors which will move:[1, 0, 0, 1, 1]

      That is to say, the first and the last two. The key (for cipher rotors) changes from MERDE to NERED. The first rotor goes from M to N, the second and third do not move (they remain at ER), the fourth goes from D to E and the last rotor goes from E to D. Due to the fact that the machine used is a CSP -2900, the second and fourth rotors move forward instead of backward. But when a rotor is reversed, we have the impression it moves forward.

      DEBUG 7 6579  Advance cipher rotors: [1, 0, 0, 1, 1]
      DEBUG 7 6606  Advancement of control rotors
      INFO 6 6677  Key: NERED SHHTS 01789
      

    5. The control rotors step regularly: We go from SHIFTS to SHHTS. Index rotors do not move.
If you have the AWK or GREP commands, for example on Unix, you can extract part of the logs.
$ echo HELLO | python3 sigaba_tui.py -c -D LOG |awk '$2 < 6'
NOTICE 5 4305  Mode: ENCRYPT
NOTICE 5 5309  Key: OOOOO OOOOO 00000
NOTICE 5 5357  ---> 0000: code 
NOTICE 5 5430  Encrypt:H>M:U:F:O:F:>F
NOTICE 5 6243  Key: NONON ONNNO 00000
FNOTICE 5 6294  ---> 0001: code 
NOTICE 5 6361  Encrypt:E>C:H:R:N:L:>L
NOTICE 5 7124  Key: MOMOM ONMNO 00000
LNOTICE 5 7170  ---> 0002: code 
NOTICE 5 7237  Encrypt:L>T:F:A:Y:Q:>Q
NOTICE 5 7996  Key: MOLNL ONLNO 00000
QNOTICE 5 8042  ---> 0003: code 
NOTICE 5 8108  Encrypt:L>T:F:Q:U:G:>G
NOTICE 5 8868  Key: LOLMK ONKNO 00000
GNOTICE 5 8915  ---> 0004: code 
NOTICE 5 8981  Encrypt:O>B:T:X:I:F:>F
NOTICE 5 9755  Key: KOKMJ ONJNO 00000
F
NOTICE 5 6308  Master Switch: POWER_OFF
NOTICE 5 6385  ---- Stop Logging -----

$ echo HELLO | python3 sigaba_tui.py -c -D LOG | grep 'Advance cipher'
DEBUG 7 8566  Advance cipher rotors: [1, 0, 1, 0, 1]
DEBUG 7 9439  Advance cipher rotors: [1, 0, 1, 0, 1]
DEBUG 7 0310  Advance cipher rotors: [0, 0, 1, 1, 1]
DEBUG 7 1183  Advance cipher rotors: [1, 0, 0, 1, 1]
DEBUG 7 2066  Advance cipher rotors: [1, 0, 1, 0, 1]

Advanced modes

My simulator supports advanced capabilities of Sigaba: the Navy's indicator method for specifying the starting key of 26-contact rotors and also tandem mode operation.

C:\sigabajf>echo HELLOWORLD |python sigaba_tui.py -c -N MERDE
CJUOD AARIV J

C:\sigabajf>echo HELLOWORLD |python sigaba_tui.py -c | python sigaba_tui.py -d
HELLOWORLD

Web Links

  • My simulator, download link.