Last modified : 2013-08-04 10:58:41 tkych
Version: 0.1.00 (beta)
CL-Enigma
cl-enigma is a simulator of the enigma machine for Common Lisp. The enigma machine is a secret German cipher machine during WW2 period. It was broken at Bletchley Park, England.
This is a toy project. I enjoyed coding the enigma machine. I feel happy as long as you're having a good time (:-D)
Reference
- www.enigmaco.de enigma
- The Enigma cipher machine
- Eiichi, Wada Enigmaへの挑戦, Program Promenade, IPSJ Magazine, vol.45, No.10, Oct. 2004.
- Numberphile
- Dirk Rijmenants' Cipher Machines and Cryptology, Enigma Page
- Paper Enigma Machine by Mike Koss
Depends-on
- Independent
Installation
- SHELL$
git clone https://github.com/tkych/cl-enigma.git
- CL-REPL>
(push #p"/path-to-cl-enigma/cl-enigma/" asdf:*central-registry*)
- CL-REPL>
(ql:quickload :cl-enigma)
or(asdf:load-system :cl-enigma)
Examples
ENIGMA> (machine B
(set-rotor Beta #\G)
(set-rotor Gamma #\B)
(set-rotor VIII #\D)
'((a y) (l x))
"SUPERCALIFRAGILISTICEXPIALIDOCIOUS")
=> "NPFJDLEGBRBUVNZVFXSJHTXUMUGQSZGUWG"
ENIGMA> (machine B
(set-rotor Beta #\G)
(set-rotor Gamma #\B)
(set-rotor VIII #\D)
'((a y) (l x))
*)
=> "SUPERCALIFRAGILISTICEXPIALIDOCIOUS"
Referece Manual
[Function] MACHINE reflector left-rotor middle-rotor right-rotor plugs input-string => encoded/decoded-string
Encode/Decode input-string.
Argumants:
- reflector is a one of reflectors (built-in reflector A,B,C, or user defined reflector).
- left-rotor, middle-rotor, right-rotor are a one of rotors (built-in rotor I,II,III,IV,V,VI,VII,VIII,Beta,Gamma or user defined rotor).
- plugs is a list of a two characters/symbols which interchanges each other.
e.g. plugs,
((#\a #\b) (c d))
makes plugboard a <-> b and c <-> d. - input-string is a string to be encode/decode by machine.
[Function] SET-ROTOR rotor init-position => rotor
Set bar-position of the rotor to init-position. init-position must be a character (a...z) or an integer (1...26).
[Function] MAKE-ROTOR to-alphabet &rest notch-characters => rotor
Make a rotor.
to-alphabet is a permutation of *ALPHABET*. notch-characters are a characters which replesents the position of turnover.
e.g.
(make-rotor "BACDEFGHIJKLMNOPQRSTUVWXYZ" #\N #\W)
makes rotor which interchanges A <-> B
and has notchs for #\N
and #\W
.
[Special Variables] I, II, III, IV, V, VII, VIII, Beta, Gamma
Built-in rotors.
Definitions:
- I :=
(make-rotor "EKMFLGDQVZNTOWYHXUSPAIBRCJ" #\Q)
- II :=
(make-rotor "AJDKSIRUXBLHWTMCQGZNPYFVOE" #\E)
- III :=
(make-rotor "BDFHJLCPRTXVZNYEIWGAKMUSQO" #\V)
- IV :=
(make-rotor "ESOVPZJAYQUIRHXLNFTGKDCMWB" #\J)
- V :=
(make-rotor "VZBRGITYUPSDNHLXAWMJQOFECK" #\Z)
- VI :=
(make-rotor "JPGVOUMFYQBENHZRDKASXLICTW" #\Z #\M)
- VII :=
(make-rotor "NZJHGRCXMYSWBOUFAIVLPEKQDT" #\Z #\M)
- VIII :=
(make-rotor "FKQHTLXOCBJSPDZRAMEWNIUYGV" #\Z #\M)
- Beta :=
(make-rotor "LEYJVCNIXWPBQMDRTAKZGFUHOS")
- Gamma :=
(make-rotor "FSOKANUERHMBTIYCWLQPZXVGJD")
[Function] MAKE-REFLECTOR to-alphabet => reflector
Make a reflector.
to-alphabet is permutation of *ALPHABET*.
[Special Variables] A, B, C
Built-in reflectors.
Definitions:
- A :=
(make-reflector "EJMZALYXVBWFCRQUONTSPIKHGD")
- B :=
(make-reflector "YRUHQSLDPXNGOKMIEBFZCWVJAT")
- C :=
(make-reflector "FVPJIAOYEDRZXWGCTKUQSBNMHL")
[Special Variable] *ALPHABET*
The alphabet string used in a plaintext and a cyphertext.
Default is "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
.
TODO
- ADD: local-alphabet extension.
Author, License, Copyright
-
Takaya OCHIAI <#.(reverse "moc.liamg@lper.hcykt")>
-
MIT License
-
Copyright (C) 2013 Takaya OCHIAI