+
Plugboard
A
F
Z
M
R
B
P
R
J
G
Reflector
Converting Enigma to JS
A B C D E F G . . .
Real Rotor:
A B C D E F G . . .
Is the same as
Having one totally random alphabet
EKMFLGDQVZNTOWYHXUSPAIBRCJ
You need to keep track of current rotation (position)
Rotate rotor after each key press
rotor.letters.shift()
Change letter as it passes through the rotors
return output[input.indexOf(letter)]
Next rotor
Current rotor
Current letter
reflector.letters.split('').reverse().join('')
Reflect letter back at the reflector
Feel like using real enigma with buttons and stuff
Challenge: Allow user to select 3 rotors out of five in any order
Solution: Use React DnD
http://react-dnd.github.io/react-dnd/
Goal?
Main principle
DragSource and DropTarget
wrapped with
DragDropContext
DragSource(type, spec, collect)(MyComponent)
string
object
object
react component
DropTarget(types, spec, collect)(MyComponent)
string/array
object
object
react component