|
Home Page Kryha Home Page
|
IntroductionThis web page presents my simulation program for the Kryha cipher machine. This program is written in Python and works in text mode. The Python interpreter must be installed. Here is the download link: (link). Suggestion to install the software
Open a terminal (a Shell ISO Session).
$ curl -O http://www.jfbouch.fr/crypto/kryha/KRYHA_TOOLS.tar
$ ls KRYHA_TOOLS.tar
KRYHA_TOOLS.tar
Install the archive :
$ tar -xf KRYHA_TOOLS.tarPosition yourself in the created directory:
$ cd KRYHA_TOOLS
Read the README (in fact, a copy of this documentation) :
$ more README.txtPrint the syntax:
$ python kryha_tui.py -h
usage:
Syntax: kryha_tui.py [option...]
Example:
echo AAAA|python kryha_tui.py -c
Options:
-h Help
-v/-D Verbose (Debug)
-o Old model (V1), by default V2
-i alpha Internal alphabet (ABC... by default)
-e alpha External alphabet (ABC... by default)
-s stops V1: Shifts, for example: 6,10,7,10,3,10
V2: Stops (Holes), 1,2,3,...52 by default
-f stop Initial stop (the first stop by default)
-a letter Initial shift for internal alphabet
-c/-d Cipher/Decipher (Cipher by default)
if Mode is Cipher we read the plain
letters in the External alphabet
-m Move the Internal disk before ciphering
By default, don't move the disk before ciphering
-w wheel The wheel (only for old model), DEFAULT by default
The wheel.whl file must be in 'keys' directory
Usage, the ABCsEncrypting a string of characters $ echo Hello World | python kryha_tui.py -c HAEAAFUTKY The option -c (ciphering) is used by default. $ echo Hello World | python kryha_tui.py HAEAAFUTKY Decipher a string of characters. $ echo HAEAA FUTKY | python kryha_tui.py -d HELLOWORLD
Encrypt a file, $ cat MSGS/tobe.txt To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And, by opposing, end them. To die, to sleep, No more, and by a sleep to say we end $ python kryha_tui.py -c < MSGS/tobe.txt | \ python groupe.py > MSGS/tobe.cry $ more MSGS/tobe.cry TKUTA ATQSO FPPBM BQCJG RLTUB LJVXS XFZKV PZXJP HFOTJ THJLW QULMZ LDEDK HCLKV PAPIK AINXJ DRNHM EWJPS NIORL SUPZE CBZPD JJIZZ CJZSG YAFHX CEGEH VEXHV GAUXA HXHLU HCVIG DYZLN DXBOB MGKOG RRJVM NDTPX ROJII SKTGB UTIXN KRSKK OIDIE KX Decrypt a file. $ python kryha_tui.py -d < MSGS/tobe.cry TOBEORNOTTOBETHATISTHEQUESTIONWHETHERTISNOBLERINTHEMINDTOSU FFERTHESLINGSANDARROWSOFOUTRAGEOUSFORTUNEORTOTAKEARMSAGAINS TASEAOFTROUBLESANDBYOPPOSINGENDTHEMTODIETOSLEEPNOMOREANDBYA SLEEPTOSAYWEEND Simulating the Original Version (V1)introductionThe first version of the Kryha uses a removable wheel made of about twenty sectors. Each sector contains several notches. The internal alphabet advances with each numbered letter by as many steps as there are notches in the current sector. In addition, a systematic advance of four steps is performed (see working). The standard wheel is composed of 17 sectors. Here is a description of the wheel and the number of notches for each sector: 3, 2, 3, 1, 2, 3, 2, 4, 2, 6, 1, 2, 1, 3, 2, 1, 5Since the machine adds 4 steps to each cipher, we obtain the following shifts: 7, 6, 7, 5, 6, 7, 6, 8, 6, 10, 5, 6, 5, 7, 6, 5, 9 The use of the original version (v1) is triggered by the use of the "-o" (old) option. Using DEBUG ModeThis option is essential as it allows you to fully understand how the Kryha machine works. Both the internal and external alphabets are displayed. Thus you can perform the encryption or decryption of any letter yourself. Also displayed the shift applied at each step, and of course, the plaintext (or ciphertext) letter to be transformed (encrypted or decrypted) and the result (encryption or decryption). The external alphabet is fixed and often consists of a standard alphabet (ABC...Z). The internal alphabet is mobile and is usually random. In addition, DEBUG mode displays the key used: the wheel used, the internal and external alphabets, the initial sector, the initial shift of the internal alphabet, the mode (ciphering or deciphering) and whether the wheel is advanced before or after encryption. Example: Encrypting the word HELLO:
$ echo Hello | python kryha_tui.py -o -D
Wheel: [3, 2, 3, 1, 2, 3, 2, 4, 2, 6, 1, 2, 1, 3, 2, 1, 5]
Sectors: [The offsets are specified directly.]>>17
First stop: 1
Cipher Mode: cipher
Initial shift for internal alphabet: 0
Advance before cipher: False
Systematik shift: 0
Internal alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
External alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 00, [00] , H -> H
TUVWXYZABCDEFGHIJKLMNOPQRS
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 07, [07] , E -> X
NOPQRSTUVWXYZABCDEFGHIJKLM
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0003 : 13, [06] , L -> Y
GHIJKLMNOPQRSTUVWXYZABCDEF
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0004 : 20, [07] , L -> R
BCDEFGHIJKLMNOPQRSTUVWXYZA
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0005 : 25, [05] , O -> P
HXYRP
$
The key is specifiedNote: To fully understand the effect of an option, we always use DEBUG mode. Specify the internal alphabet (for example, DBULYFZOVJWMKPSTNGQAEHXRIC).
$ python cree_alpha.py
DBULYFZOVJWMKPSTNGQAEHXRIC
$ echo OK | python kryha_tui.py -o \
-i DBULYFZOVJWMKPSTNGQAEHXRIC -D
...
DBULYFZOVJWMKPSTNGQAEHXRIC
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 00, [00] , O -> S
AEHXRICDBULYFZOVJWMKPSTNGQ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 07, [07] , K -> L
SL
$
Specify both alphabets (internal, option -i; external, option -e):
$ python cree_alpha.py
REGJNMZKYQDOBIHCAULFSPWVXT
$ echo OK | python kryha_tui.py -o \
-i DBULYFZOVJWMKPSTNGQAEHXRIC \
-e REGJNMZKYQDOBIHCAULFSPWVXT -D
...
DBULYFZOVJWMKPSTNGQAEHXRIC
REGJNMZKYQDOBIHCAULFSPWVXT
0001 : 00, [00] , O -> M
AEHXRICDBULYFZOVJWMKPSTNGQ
REGJNMZKYQDOBIHCAULFSPWVXT
0002 : 07, [07] , K -> D
MD
We advance the internal wheel before calculating the value (option -m).
$ echo OK | python kryha_tui.py -o -m -D
...
TUVWXYZABCDEFGHIJKLMNOPQRS
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 07, [07] , O -> H
NOPQRSTUVWXYZABCDEFGHIJKLM
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 13, [06] , K -> X
HX
We specify the starting sector, for example the 4th (option -f).
$ echo OK | python kryha_tui.py -o -f 4 -D
...
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 00, [00] , O -> O
VWXYZABCDEFGHIJKLMNOPQRSTU
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 05, [05] , K -> F
OF
The internal wheel is advanced (for example by 4 positions) before the start of the encryption (option -a).
$ echo OK | python kryha_tui.py -o -a 4 -D
...
Internal alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
External alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
WXYZABCDEFGHIJKLMNOPQRSTUV
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 04, [00] , O -> K
PQRSTUVWXYZABCDEFGHIJKLMNO
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 11, [07] , K -> Z
KZ
We use decryption mode (option -d).
$ echo HXYRP | python kryha_tui.py -o -d -D
...
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 00, [00] , H -> H
TUVWXYZABCDEFGHIJKLMNOPQRS
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 07, [07] , X -> E
NOPQRSTUVWXYZABCDEFGHIJKLM
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0003 : 13, [06] , Y -> L
GHIJKLMNOPQRSTUVWXYZABCDEF
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0004 : 20, [07] , R -> L
BCDEFGHIJKLMNOPQRSTUVWXYZA
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0005 : 25, [05] , P -> O
HELLO
Specifying the WheelBy default, the standard wheel is used (this wheel is described above). There are two ways to describe a non-standard wheel.
The wheel to be used is specified (option -w). This is stored in a file. The file must be in the keys directory and have the .whl extension.
$ cat keys/default.whl
3, 2, 3, 1, 2, 3, 2, 4, 2, 6, 1, 2, 1, 3, 2, 1, 5
$ echo HELLO | python kryha_tui.py -o -w default
HXYRP
$ echo HELLO | python kryha_tui.py -o
HXYRP
$ cat keys/parker1930.whl
2, 5, 4, 6, 2, 5, 3, 4, 6, 3, 5, 4, 6, 2, 3, 5, 6, 1, 3, 2, 1, 3, 6
$ echo HELLO | python kryha_tui.py -o -w parker1930
HYWOH
$ echo HELLO | python kryha_tui.py -o -w parker1930 -D
Wheel: [2, 5, 4, 6, 2, 5, 3, 4, 6, 3, 5, 4, 6, 2, 3, 5, 6, 1, 3, 2, 1, 3, 6]
Sectors: [6, 9, 8, 10, 6, 9, 7, 8, 10, 7, 9, 8, 10, 6, 7, 9, 10, 5, 7, 6, 5, 7, 10]>>23
...
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0001 : 00, [00] , H -> H
UVWXYZABCDEFGHIJKLMNOPQRST
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0002 : 06, [06] , E -> Y
LMNOPQRSTUVWXYZABCDEFGHIJK
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0003 : 15, [09] , L -> W
DEFGHIJKLMNOPQRSTUVWXYZABC
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0004 : 23, [08] , L -> O
TUVWXYZABCDEFGHIJKLMNOPQRS
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0005 : 07, [10] , O -> H
HYWOH
The offsets performed are specified in the command line (option -s). The systematic offset must be included (and therefore 4 must be added to each sector). $ cat keys/default.whl 3, 2, 3, 1, 2, 3, 2, 4, 2, 6, 1, 2, 1, 3, 2, 1, 5 $ echo HELLO | python kryha_tui.py -o \ -s 3,2,3,1,2,3,2,4,2,6,1,2,1,3,2,1,5 HBGDF $ echo HELLO | python kryha_tui.py -o HXYRP $ echo HELLO | python kryha_tui.py -o \ -s 7,6,7,5,6,7,6,8,6,10,5,6,5,7,6,5,9 # we add 4 HXYRP Simulate Version 2Version 2 of the Kryha has a universal encoding disk. It has holes around its periphery. Each hole contains a screw. If the screw is unscrewed, the hole no longer exists (it is filled by the screw). If the operator screws in a screw, the hole is real. Between each hole, there are a specific number of teeth. As you can see, the universal disk resembles one of the removable disks in version 1. However, depending on whether a screw is screwed in or not, a different number of sectors and therefore offsets are obtained. (see working). If the -o option is absent, Kryha version 2 is used by default. In version 2, the -s option specifies the hole locations. The -f option indicates (as before) the starting sector.
$ echo OK | python kryha_tui.py \
-s 1,3,5,7,11,13,16,18,21,22,25,27,30,32,33,35,37,38,40,41,43,45,47,49,52 \
-f 3 -D
Internal Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
External Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Stops: [1, 3, 5, 7, 11, 13, 16, 18, 21, 22, 25, 27, 30, 32, 33, 35, 37, 38,
40, 41, 43, 45, 47, 49, 52]
First stop: 3
Cipher Mode: True
Initial shift for internal alphabet: 0
Advance before cipher: False
Internal alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
External alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
0 - O => O ,Shift: 7, Cumuled shift: 7, Disk Position: 5
Internal alphabet: TUVWXYZABCDEFGHIJKLMNOPQRS
External alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
1 - K => D ,Shift: 6, Cumuled shift: 13, Disk Position: 7
OD
$
|