Skip to content

An enigma machine emulation and brute-force breaker, written in Rust.

Notifications You must be signed in to change notification settings

MaddyGuthridge/Enigma-Breaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Enigma Breaker

An enigma machine emulation and brute-force breaker, written in Rust.

Installation

  1. Install a modern version of the Rust toolchain.

  2. git clone this repository

  3. Run cargo install --path .

Usage

Enciphering

The program behaves similarly to cat.

enigma encipher <reflector ID> -r [rotor IDs] -p [plug maps]

  • Reflector ID is specified as a char (eg A)

  • Rotors are given as roman numerals (eg IV). To specify a starting position, a colon is used, followed by the letter at which it should start. (eg II:T would use rotor II starting at position T). If not provided, the starting letter is assumed to be A.

  • Plug maps are given as a set of letters to swap (eg AC would swap letters A and C).

For example, to use reflector B, with rotors III, IV and I, you can run

enigma encipher B -r III IV I

For more details, use enigma help encipher

Encoding example

$ enigma encipher B -r V:X I:C II:B
Hello, world! This is my super cool Enigma machine, programmed in Rust!
Jtdvt, zndgl! Jrvr cq ik ydkqk qmws Nxxxtx sylgzjn, kmfwdmfwcv gc Iqcx!
$ enigma encipher B -r V:X I:C II:B
Jtdvt, zndgl! Jrvr cq ik ydkqk qmws Nxxxtx sylgzjn, kmfwdmfwcv gc Iqcx!
Hello, world! This is my super cool Enigma machine, programmed in Rust!

Brute force deciphering

enigma force <reflector ID> -r [rotor IDs] -p [plug maps] --msg-[constraints]

The program behaves similarly to when enciphering. Any unknown values are indicated using an _ (underscore) character.

  • For an unknown reflector or rotor, you can simply use _.

  • For an known rotor with an unknown starting position, you can just specify the rotor. For example, to specify rotor V with an unknown position, you can use V or V:_.

  • For an unknown rotor with a known starting position (say C), you can use _:C.

For the plug board, you should specify a number of plugs that was used. For example, to specify 10 plugs, you could use 10. Ranges are also supported, such as 4..7 for 4, 5 or 6 plugs, or 3..=5 for 3, 4 or 5 plugs.

Please note that as the number of plugs increases, the number of potential combinations increases to absurd degrees. Using 10 plugs, and three unknown rotors would result in 67 bits of work, which would take the software about 30000 years to solve from my calculations.

Message constraints

The program has no knowledge of what messages do/don't make sense, and so in order to discard combinations, it requires constraints on the output message.

Currently, the available ways of narrowing this are by specifying any combination of a known "message start", "message end", or "message contains".

  • --msg-start: the message must start with the given string to be considered a match.

  • --msg-end: the message must finish with the given string to be considered a match.

  • --msg-contains: the message must contain the given string at any location to be considered a match.

Brute force example

Demonstrates enciphering, then brute-forcing a message. The only given knowledge of the message is that it starts with the word "Hello".

$ enigma encipher B -r V:X I:C II:B
Hello, world! This is my super cool Enigma machine, programmed in Rust!
Jtdvt, zndgl! Jrvr cq ik ydkqk qmws Nxxxtx sylgzjn, kmfwdmfwcv gc Iqcx!
$ enigma force _ -r _ _ _ --msg-start Hello
Jtdvt, zndgl! Jrvr cq ik ydkqk qmws Nxxxtx sylgzjn, kmfwdmfwcv gc Iqcx!
Done! Found 2 matches
1 :: A --rotor-ids III:I V:R III:D
Hello, tipwh! Tned lc wv noegz tfyo Apdlih djpmfgf, hylfkogiqw wn Mcbj!

2 :: B --rotor-ids V:X I:C II:B
Hello, world! This is my super cool Enigma machine, programmed in Rust!

Observe that given our constraints (message starts with Hello), it was able to find two matches. Since the program has no concept of words, it is unaware that the first result is nonsensical.

Navigating the repo

  • src - source code for the enigma CLI
  • lib_enigma - source code for the library I created for emulating and brute-forcing the enigma machine.
  • Report.pdf - the report I made for COMP6841

Todo

  • Implement an enigma machine
  • Support controlling the machine to try combinations
  • Write code for handling known/unknown properties when brute-forcing
  • Write algorithm for brute-forcing the output
  • Implement optimisation where letters cannot encode to themselves
  • Add benchmarks to track program performance
  • Use threading to speed up brute-forcing
  • Display progress while running brute-force algorithms
  • Implement an estimated time remaining
  • Support brute-forcing from a list of possible configurations
  • Support looking for dictionary words in the output
  • Make it faster by preventing unnecessary copying of data

References

About

An enigma machine emulation and brute-force breaker, written in Rust.

Topics

Resources

Stars

Watchers

Forks

Languages