In summer 1940, Germany demanded access to Swedish telephone cables to send encoded messages from occupied Norway back to the homeland. Sweden acceded but tapped the lines and discovered that a new cryptographic system was being used. The T52 Geheimschreiber (or G-schreiber in short), with more than 800 quadrillion settings, was conveying top-secret information but seemed immune to a successful codebreaking attack.
The Swedish intelligence service assigned mathematician Arne Beurling to the task, giving him only a pile of coded messages and no knowledge of the mechanism that had been used to encode them. But after two weeks alone with a pencil and paper he announced that he had decoded the messages. He also described how a complementary machine could be built to decode the messages automatically.
Thanks to his work, Swedish officials learned in advance of the impending invasion of the Soviet Union. Unfortunately, Stalin's staff disregarded their warnings. In his book The Codebreakers1 Bengt Beckman accounts of the exploit. In his foreword to the book, Peter Jones writes:
To this day no one knows exactly how Beurling reasoned during the two weeks he spent on the G-Schreiber. In 1976 he was interviewed about his work by a group from the Swedish military, and became extremely irritated when pressed for an explanation. He finally responded, "A magician does not reveal his tricks." It seems the only clue Beurling ever offered was the remark, cryptic itself, that threes and fives were important.
In the end, the procedure used by the T52 Geheimschreiber did not
turn out to be all too complicated. It uses an alphabet of
In addition, two integers
When the Germans noticed that messages sent using the T52 could be easily
decoded, they tried to make the encryption procedure more complex. This
was done by not encoding a message once but twice. First a message was
encoded by a T52 that used keys
Define a class T52 to represent machines that can be used
to encode and decode messages according to the Geheimschreiber
cipher. Three argument must be passed when creating a new machine (T52):
two integers
Use the function math.gcd2 to compute the greatest common divisor of two integers.
A machine
A method encode_symbol that takes a single character (str).
If the given character occurs in the alphabet of machine
A method decode_symbol that takes a single character (str).
If the given character occurs in the alphabet of machine
A method encode that takes a plaintext
A method decode that takes a ciphertext
Make sure the sum (+) of two machines
>>> machine1 = T52(3, 5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>> machine1.encode_symbol('G')
'X'
>>> machine1.encode_symbol('S')
'H'
>>> machine1.encode_symbol('-')
'-'
>>> machine1.decode_symbol('X')
'G'
>>> machine1.decode_symbol('H')
'S'
>>> machine1.decode_symbol('-')
'-'
>>> machine1.encode('G-SCHREIBER')
'X-HLAERDIRE'
>>> machine1.decode('X-HLAERDIRE')
'G-SCHREIBER'
>>> machine2 = T52(17, 11, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>> machine2.encode('X-HLAERDIRE')
'M-AQLBOKROB'
>>> machine12 = machine1 + machine2
>>> machine12.encode('G-SCHREIBER')
'M-AQLBOKROB'
>>> T52(4, 5, 'ABCDEFGHIJKLMMLKJIHGFEDCBA')
Traceback (most recent call last):
AssertionError: alphabet has repeated symbols
>>> T52(4, 5, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
Traceback (most recent call last):
AssertionError: 4 and 26 are not coprime
>>> machine1 + T52(17, 11, 'abcdefghijklmnopqrstuvwxyz')
Traceback (most recent call last):
AssertionError: alphabets are different