You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a personal tool I use to bruteforce the decryption of Enigma ciphers, emphasizing speed. It's functional, but not yet in a polished library form. Expect frequent breakage until published as a library. The code has reached fair performance, so I decided to release it in alpha form as I continue to improve it.
4
+
A tool for bruteforcing enigma ciphers. Currently breaks ciphers where the plugboard is already known.
5
+
6
+
7
+
# Installation
8
+
9
+
Clone or download the project. Open up `crack_enigma.cpp` and in the `main` function place your code (see Basic Usage below). Compile by running `make` or `make crack_enigma` and run with `./crack_enigma`.
10
+
11
+
To import into an existing project, you need the the contents of the `source/` and `include/` folders. `include/bruteforce-enigma.h` adds a nicer interface and multithreading, but doesn't contain any core functionality. Compile and link with the .cpp files from `source/`, but you can only compile against one quadgram language file (`qgr.cpp` or `de_qgr.cpp`) at a time. Requires compiling with C++20 and pthreads.
Currently cracks ciphers where the plugboard is already known.
34
+
**Cracking unknown ring and rotor positions**
6
35
36
+
The smart decipher should be sufficient for almost all ciphers. It uses a similar algorithm that [Practical Cryptography](http://www.practicalcryptography.com/cryptanalysis/breaking-machine-ciphers/cryptanalysis-enigma-part-2/) does, by first finding the best rotor combination and position, and then from the top results finding the best ring positions.
Open up **crack_enigma.cpp** and in the main function place your code. Using one of the two provided algorithms, pass in an enigma model, a plugboard setting, and your ciphertext. Compile by running `make` or `make crack_enigma` and run with `./crack_enigma`.
42
+
EnigmaBase base = {ETW_ABCDEF, m3_IV, m3_V, m3_II, UKWB};
To import into an existing project, drop the repo into your source tree, include include/bruteforce-enigma.h in a file, and compile and link with the .cpp files in src/. You can only compile against one quadgram language file (qgr.cpp or de_qgr.cpp) at a time.
13
48
14
-
Enigma models can be found in *models.cpp*. The current list includes:
15
-
* m3
16
-
* m3 extended (with rotors VI, VII, and VIII added)
17
-
* m4 (with only three rotors at the moment)
18
-
* railway
19
-
* CrypTool m3 (adds reflector UKWA)
20
-
* CrypTool railway (different notches)
21
-
* enigma I
22
-
* norenigma
23
-
* sondermaschine
24
-
* commercial enigma
49
+
**Bruteforcing unknown ring and rotor positions**
25
50
26
-
Two algorithms are provided to bruteforce an enigma cipher. The first, called `smart_decipher`, should be sufficient for almost all ciphers. It uses a similar algorithm to [Practical Cryptography](http://www.practicalcryptography.com/cryptanalysis/breaking-machine-ciphers/cryptanalysis-enigma-part-2/), by first finding the best rotor combination and position, and then from the top results finding the best ring positions.
51
+
The bruteforce decipher goes through every combination of rotor, rotor position, and ring position (except the third ring, which has no effect on finding a solution) of a given enigma model. Since this requires 11.9 million decryptions per rotor configuration, it takes a bit of time to finish. See below for the performance characteristics on my machine.
27
52
28
-
The second, called `bf_decipher`, goes through every combination of rotor, rotor position, and ring position (except the third ring, which has no effect on finding a solution) of a given enigma model. Since this requires 11.9 million decryptions per rotor configuration, it takes a bit of time to finish. See below for the performance characteristics on my machine.
Two different scoring functions are provided, `score_by_Qgram` for quadgram scoring, and `score_by_IOC_order` for IOC scoring (maintains ordering, but does not return the actual IOC).
Two different scoring functions are provided, `score_by_Qgram` for quadgram scoring (the default), and `score_by_IOC_order` for IOC scoring (maintains ordering, but does not return the actual IOC). You can also provide a custom scoring function, which must take a range of integers as its only parameter.
If you suspect a solution is missed because it is not in the top 10 results (rare), you can increase the number of high scores with a template argument. The smart decipher runtime will be increased by (26 + N)/36 %. The effect on the bruteforce runtime is negligible.
Enigma model definitions can be found in `models.cpp`. The list includes:
118
+
* M3
119
+
* Kriegsmarine (M3 with rotors VI, VII, and VIII added)
120
+
* M4
121
+
* Enigma I
122
+
* Norenigma
123
+
* Sondermaschine
124
+
* Railway
125
+
* CrypTool Railway (different notches and stator)
126
+
* CrypTool M3 (adds reflector UKWA to Kriegsmarine)
127
+
* Commercial Enigma
128
+
* Tirpitz
129
+
130
+
The following rotor definitions are included, but the unique machine behaviors have not been implemented.
131
+
* Swiss K
132
+
* Enigma KD
133
+
* Zahlwerk
134
+
* Enigma G-111
135
+
* Enigma G-312
136
+
* Enigma G-260
137
+
138
+
139
+
# Advance Usage
140
+
141
+
Quadgram scoring for German can be found in `de_qgr.h` and `de_qgr.cpp`. There is currently no mechanism to specify the language at runtime, but you can change the import in `score.h` from `qgr.h` to `de_qgr.h`, recompile, and it will just work.
| Number of decryptions / second | - | 3.70 x 10^6 |
162
+
| Characters / second | - | 207.16 x 10^6 |
54
163
55
164
56
-
Scoring with IOC is faster than quadgram, but also is less accurate. IOC scoring fails to solve the above cipher, as due to the plaintext's short length, its IOC is 0.080519, while the IOC scorer looks for the average English score of 0.066.
165
+
Scoring with IOC is faster than quadgram, but is also less accurate. It fails to solve the cipher above because its IOC is 0.080519, while the average English IOC is 0.066.
57
166
58
-
A longer cipher test was done on a text with IOC of 0.062931, which is much closer to the average English score. Even so, the smart_decipher function fails to solve the longer text, likely because IOC does not score well on the partial solutions found during the first part of the decryption process.
167
+
The text below has an IOC of 0.062931, which is much closer to English. Even so, the smart_decipher function fails to solve the longer text, possibily because IOC does not score well on the partial solutions found during the first part of the decryption process.
Copyright (c) 2020 Mike Castillo under the [MIT License](https://choosealicense.com/licenses/mit/). See LICENSE for the full terms.
84
192
85
-
Developed with reference to [CrypTool 2](https://www.cryptool.org/en/cryptool2) and [Practical Cryptography](http://www.practicalcryptography.com/cryptanalysis/breaking-machine-ciphers/cryptanalysis-enigma-part-2/).
193
+
Developed with reference to [CrypTool 2](https://www.cryptool.org/en/cryptool2), [Practical Cryptography](http://www.practicalcryptography.com/cryptanalysis/breaking-machine-ciphers/cryptanalysis-enigma-part-2/), and [Crypto Museum](https://www.cryptomuseum.com/).
0 commit comments