Enigma Machine Simulator for Common Lisp.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ali Reza Hayati a83ee50b8c Files added 1 month ago
LICENSE Files added 1 month ago
README.md Files added 1 month ago
cl-enigma.asd Files added 1 month ago
enigma.lisp Files added 1 month ago

README.md

Installation

  1. SHELL$ git clone https://github.com/tkych/cl-enigma.git
  2. CL-REPL> (push #p"/path-to-cl-enigma/cl-enigma/" asdf:*central-registry*)
  3. 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".