预定/报价
Erlang代写 | COM3190/COM6116 Programming Assignment Erl-nigma
Erlang代写 | COM3190/COM6116 Programming Assignment Erl-nigma
yet2024-06-14 15:21:22
这个作业是用Erlang开发一个Enigma机器
COM3190/COM6116 Programming Assignment
Erl-nigma – A simulated Enigma machine
Ramsay Taylor
Department of Computer Science
The University of Sheffield
DEADLINE: 3.00pm, Wednesday, Week 12
Guidelines
This assignment contributes 30% towards your overall module mark, and requires you to submit
TWO files: (a) a single PDF document answering Part 1 below; (b) a single Erlang program file
containing your solutions to Part 2. You should submit your solutions via MOLE no later than
the deadline specified above. Standard penalties will apply for late submissions.
Background
The Enigma machine was invented in Germany in 1918, and uses various mechanical and electrical
components to encrypt and decrypt messages, one letter at a time. Originally developed for
commercial use, it was soon adapted for military and diplomatic purposes (Figure 1a) [5].
(a) Enigma (b) Plugboard
Figure 1: (a) A Military Enigma Machine [6]. (b) Plugboard [3]. The wires shown here swap A
with J, and S with O.
1
Figure 2: Rotors [2].
Components
Figure 3: An outline of the Enigma process
Figure 3 shows the basic components of an Enigma machine and their interconnections:
Keyboard
The machine has a keyboard, on which users type their plaintext messages.
Plugboard
The plugboard is used to set up a basic substitution cipher. In Figure 1b, for example, a wire
has been used to join the sockets labeled A and J. This means that every time the user
types the letter A, the keyboard actually produces the letter J (and vice versa). Similarly,
because there is a wire joining sockets S and O, typing the letter O actually produces the
letter S (and vice versa).
Rotor
The machine is equipped with several rotors, which again perform simple letter-for-letter
substitutions. Each rotor is connected to the next by electrical contacts, and the result of
sending a letter through all of the rotors, one after the other, depends on their positions
relative to one another (Figure 2). The power of the Enigma machine comes from the simple
tactic of changing the relative positions of the rotors after each letter has been encrypted.
Just because E generated the output Z last time (say), doesn’t mean it will generate the
output Z this time, because the rotors will have rotated relative to one another.
Reflector , Lampboard
Once the current letter has been transmitted through the plugboard and rotors, it is passed
through a reflector (this again connects letters together in pairs). Having passed through the
reflector, the letter undergoes further encryption by being passed back through the rotors
and plugboard. On reaching the keyboard, the built-in lampboard shows the user which
letter should be used to encrypt the letter they just typed.
2
Modelling the details of the encryption process in CCS would require modelling each of the
individual letter connections on each rotor as a separate channel, which would make for an unwieldy
model. Modelling the system in π-calculus would allow you to represent the changing rotor
connections more economically, but it would still require 26 channels per rotor, and an explicit
definition of the internal connections of each.
Instead, a more abstract model can be constructed that includes the components and their
connections, but represents the actual operations over the characters by declaring the functions
used to manipulate the data as it flows across the channels. One such model is shown in Figure 4.
Reflector = in(x ).outhfrefl (x )i.Reflector
Keyboard = keyhx i.inc.lamp(y).Keyboard
Plugboard = r (x ).lhfplug (x )i.Plugboard
+ l(x ).r hfplug (x )i.Plugboard
Rotor (26, p) = incr .incl
.Rotor (0, p − 26) + RotorFunction(p)
Rotor (c, p) = incr .Rotor (c + 1, p + 1) + RotorFunction(p)
RotorFunction(p) = l(x ).r hfrotor (p, x )i.RotorFunction(p)
+ r (x ).lhfrotor (p, x )i.RotorFunction(p)
Enigma = Reflector [ref /in, ref /out]
| Rotor (c3, p3)[ref /l, m1/r, i3/incr]
| Rotor (c2, p2)[m1/l, m2/r, i3/incl
, i2/incr]
| Rotor (c1, p1)[m2/l, m3/r, i2/incl
, i1/incr]
| Plugboard[m3/l, keys/r]
| Keyboard[keys/key, keys/lamp, i1/inc]
Figure 4: An abstractly parametrised CCS/π-calculus model of the Enigma system components.
The Reflector process simply takes an input on channel in and reflects it out on channel out
having modified it with the reflection function frefl . The Keyboard process outputs a keypress on
channel key (the choice of key is not specified), outputs an increment signal on channel inc to
advance the rotors, and the waits for a signal on channel lamp to represent the result from the
encryption process being received on the lamp board. The plugboard simply passes messages from
l to r or r to l via the plugboard function fplug . Since the real plugboard is implemented with
wires tying letters together, fplug is bijective — so, if a is translated to x then x is translated to
a — and so there doesn’t need to be an inverse function.1
The rotor encryption function is modelled in RotorFunction, which is parameterised with a
position, p. It will accept a character on the left channel, l, and output on channel r with the