Maximum PC

Encrypt Messages With Your Pi

-

SENDING secret messages has been with us for a long time. Various methods have been devised, most with a weakness. Take the very ancient idea of tattooing your message on the head of a slave or serf, as seen in antiquity. First there’s the problem that slavery is morally repugnant, then you’ve got to shave the head, do the tattooing, and wait for the hair to grow before sending them to your co-conspirato­r. Then they need to be reshaved before the message can be read.

Far better to use something like, paper. There are invisible inks, of course, or there are ciphers, which change the letters used to make up the message so that only someone who knows the precise transforma­tion can reverse it.

In 1500 BC, the Mesopotami­ans encrypted recipes for pottery glaze, and ciphers proliferat­e through ancient Egypt, Greece, and Rome. The first people to systematic­ally document their methods, however, were the Arabs, with Al-Farahidi (710-786 or 791AD) writing the Bookof Cryptograp­hicMessage­s, considered the first book on cryptograp­hy written by a linguist.

We’re bringing things a bit more up to date, with a look at how you can use—and break—the notorious Enigma cipher machine on just about any computer you’ve got handy. –IAN EVENDEN

1

THE MACHINE

When not being simulated on your computer, an Enigma machine is a mixture of mechanical and electronic systems. This is 1915 technology, so there’s a keyboard from a typewriter, a series of wheels through which an electrical signal can be passed, and a board of lamps that light up depending on which letter they are showing. Each rotor is different, but each has 26 electrical contacts on its edges [ Image A], and wiring inside that connects the contacts together, swapping letters over. Stepping components ensure that at least one rotor turns with every press of a key, changing the electrical pathway for the next press.

>> The trick is that every machine shipped with a set of identical rotors. Usually, three from a choice of five were loaded into the machine, and set to their starting positions. The choice of positions was vital, as the encryption was reversible if you typed the ciphertext produced by one machine into a second machine set to the same starting positions. In World War II, the positions for each day tended to be provided to radio operators in a book, often printed on blotting paper to make its destructio­n easier.

>> There is more to Enigma than the rotors, though. From the depressed key (perhaps an A), the current flows through a plugboard that can be configured to swap letters over. If A is connected to D, the D signal goes into the three rotors, where it becomes perhaps a J, then a W, then a P, and is reflected back through the rotors again by a reflector, but takes a different path, becoming M, then Z, and finally F. Then it returns to the plugboard, and if F isn’t connected to anything, the F lights up on the lamp board. The only rule is that nothing can ever be enciphered as itself. On the next key-press, at least one of the rotors has turned, so A still becomes D, thanks to the plugboard, but D might now become L when it reaches the first rotor, so its path through the machine is different and you don’t get F at the end.

>> Cracking these starting positions, either by stealing codebooks or through remarkable feats of mental agility combined with electro-mechanical aids, was carried out by the remarkable brainiacs at Britain’s Bletchley Park during the war. See pg. 46 for more on them.

2

THE SIMULATOR

These days, we have computers. The best Enigma simulator we’ve found is from Félix Defrance, who goes by the name omnitrogen on GitHub. It comes

in the form of a Python script, so is relatively platform-agnostic. We’ve installed it on a Raspberry Pi, partly because you don’t need enormous processing power, and partly because the Pi OS comes with the Thonny Python integrated developmen­t environmen­t installed, as long as you choose the “Full” version of the OS; in Raspberry Pi Imager, look under “Raspberry Pi OS (Other).” For other platforms, you can get it from https://thonny. org. Note that, in Windows, this may trigger a warning from Windows Defender—click “More Info” followed by “Run Anyway.”

3

THONNY PYTHON

Pop up the Raspberry Pi equivalent of the “Start” menu, and you’ll find Thonny Python under “Programmin­g.” Don’t click it yet. If it’s not there, open Terminal and type

sudo apt-get install python3-thonny . Next, go to https:// github.com/omnitrogen/enigma and download the Zip file via the green “Code” button [ Image B]. Unzip it, and delve into the “GUI” folder. Locate the file “enigma-gui.py,” right-click it, and choose “Thonny Python IDE” to open it with. You should get something that looks like the image below [ Image C]. Press “Run.”

4

ENCRYPT AND DECRYPT

The Enigma machine doesn’t simulate the plugboard, but gives you a selection of three rotors, and you can place them in any order in the slots, including duplicatin­g them, using the arrows at the right of the horizontal slots. Below those is the reflector, which doesn’t change. Then there are three vertical slots that represent the starting positions of the rotors. Set these how you please by dragging them with the mouse. With the rotors set 1, 2, 3, and A, A, A, the popular phrase “Maximum PC Minimum BS” becomes QSWOITCZUY­YOLLEEVJ [ Image D]. Move rotor 1 to position B, and it becomes KVVEJSTNGI­PXMKMHZB. Note that there are no spaces, numbers, or punctuatio­n used,

and it throws an error if you add them. Stick to letters, perhaps using an X as a spacing character.

>> To decrypt, reset the machine to its starting settings, and feed in the cyphertext you generated. If the settings are right, you’ll get readable plaintext in the output box.

5

CRACK THE CODE

To use this to communicat­e, you need to transmit your rotor order and starting positions to your recipient without the enemy becoming aware of them. Alternatel­y, if, like us, you’re intercepti­ng your neighbor’s Morse transmissi­ons, you could try a brute-force attack, but it can take a long time. Breaking into Enigma is still difficult today without some sort of clue about what the message says—in 2017, an AI was used to mount a statistica­l attack on an Enigma message (see boxout), and took 12 minutes to solve. There is a way to do it in Python, with scripts by British intelligen­ce agency GCHQ and a historical­ly accurate Python library by Brian Neal, but it’s very long and beyond the scope of this tutorial— find out how deep the rabbit hole goes (it calls for eight Pi machines at one point) at https://projects.raspberryp­i. org/en/projects/octapi-brute-force-enigma.

 ??  ?? A
A
 ??  ?? C
C
 ??  ?? D
D
 ??  ?? B
B

Newspapers in English

Newspapers from United States