
Understanding the Enigma machine from “The Imitation Game” with 30 Lines of Ruby - albertstill
http://red-badger.com/blog/2015/02/23/understanding-the-enigma-machine-with-30-lines-of-ruby-star-of-the-2014-film-the-imitation-game/
======
Animats
The movie "Enigma" from 2001 is better.

Here's the NSA's official history of Enigma and the bombe:
[https://www.nsa.gov/about/_files/cryptologic_heritage/public...](https://www.nsa.gov/about/_files/cryptologic_heritage/publications/wwii/solving_enigma.pdf)

They credit the Polish cryptanalysts who first cracked the Enigma and built
the first bombe. Turing and Welchman at Bletchley Park came up with
improvements which made it much more effective. Building the new machines was
outsourced to the British Tabulating Machine Company.

Then the Germans switched from a three-rotor Enigma to a four-rotor, which the
British machines could not solve and increased the effort required by a factor
of 26. So the US Navy had National Cash Register build much faster machines.
Hundreds of them.

Four wheels was about the limit for a portable rotor machine where the key
presses advanced the wheels. The key pressure required for even a 3-wheel
Enigma was very high. (I've typed on one, when one was at Stanford. The key
travel is huge, almost an inch.) So that was as complex as the ciphers used by
German mobile units (ships, trucks) ever got.

For fixed installations, there was the German Lorenz machine, which had 12
wheels. That required a completely different approach to crack. Bombes were a
brute-force solution. The Colossus machine used electronics and a more
statistical approach. But that's another story.

~~~
BuildTheRobots
> They credit the Polish cryptanalysts who first cracked the Enigma and built
> the first bombe. Turing and Welchman at Bletchley Park came up with
> improvements which made it much more effective.

Not entirely. The Poles realised that the German keying procedure was flawed;
they were doubly-encrypting the start of messages which made key recovery
extremely easy.

They (the Germans,) stopped doing this relatively early on, so the key
recovery devised by Turing (and then expanded on by the Americans) was a
completely different attack. [1]

[1]
[http://www.cryptomuseum.com/crypto/bombe/](http://www.cryptomuseum.com/crypto/bombe/)

------
lsd5you
Also known as the enigma machine from that war! What a bizarre appropriation
to make.

(I mean I get it, the idea is to link the title to the recent film and make
the article somehow more current and clickable. Maybe it is a cultural thing
but to me it sounds jarring and crass)

~~~
kijin
Actually, the article only talks about the Enigma machine featured in the
movie, not all the different models (with different rotor counts, etc.) that
the Germans used throughout the war. The title might sound linkbaity, but it's
accurate.

------
jgrahamc
There's a minor problem with the implementation. The rotors and reflector
always turned a letter into a different letter because of the wiring. It's
possible for the shuffling of the alphabet to leave a letter in place.

This is a minor flaw for the explanation but the result was that a letter
could never be enciphered to itself on Enigma. And this fact was exploited
because it meant that crib positions could be eliminated.

~~~
charypar
That property is caused by the reflector, rotors themselves can shuffle
randomly. The way the reflector is built in the implementation is from pairs
of consecutive (unique) letters of the shuffled alphabet (getting a half of
the reflector) and then merging the inversion.

IMHO it's correct.

~~~
jgrahamc
Hmm. Rereading the code I believe you are correct. I'm not strong in Ruby and
had misunderstood what this was doing:

    
    
        Reflector = Hash[*('A'..'Z').to_a.shuffle]
        Reflector.merge!(Reflector.invert)

------
VikingCoder
> I recently watched the film “The Imitation Game” and it’s brilliant despite
> Keira Knightley’s failed attempt at a posh British accent.

Really?

Born: March 26, 1985 (age 29), Teddington, London, United Kingdom

Is the problem that her British accent wasn't posh enough?

~~~
jgrahamc
Correct.

~~~
peteretep
Why would you think Joan Clarke was any posher than Keira Knightly? She was
the daughter of a vicar...

~~~
jgrahamc
Listen to her speak:
[https://www.youtube.com/watch?v=MB2e9R7bXCk](https://www.youtube.com/watch?v=MB2e9R7bXCk)

~~~
AwesomeTogether
Is that posher or just more old fashioned? Serious question.

------
peteri
Did something similar during a Software Craftsmanship conference at Bletchley
Park a couple of years ago.

BP have a "paper" enigma machine that they use for school children and we pair
programmed an implementation in a couple of hours. (no plug board IIRC)

Nice programming exercise and a great place to visit, although if you go don't
forget to visit the computer museum (BP and the computer museum have fallen
out so access to the museum is a bit more awkward than it used to be).

------
prezjordan
Did the British troops _have_ an enigma machine during the war? If so couldn't
they just intercept the arrangement of rotors each day and decode messages as
they came in?

~~~
MertsA
The problem is intercepting the codebook. If they had the machine and could
somehow intercept the codes then yes.

~~~
kijin
According to Wikipedia [1], the codebooks were printed in red water-soluble
ink. If a German ship wasn't already full of water by the time the Allies
gained access to it, any German soldier could simply splash water (or blood)
on the codebook, rendering it useless.

[1]
[https://en.wikipedia.org/wiki/Enigma_machine#Details](https://en.wikipedia.org/wiki/Enigma_machine#Details)

------
tacos
Y'know, I program in Ruby. I paid my dues in CoffeeScript. And I also studied
computer science.

And sometimes Knuth-style pseudocode beats jerking off in Ruby. This is one of
those times.

~~~
AwesomeTogether
Hahahah

