tkych / cl-enigma

Enigma Machine Simulator for Common Lisp.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Depends-on

  • Independent

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".

TODO

  • ADD: local-alphabet extension.

Author, License, Copyright

About

Enigma Machine Simulator for Common Lisp.

License:MIT License


Languages

Language:Common Lisp 100.0%