Skip to content

Latest commit

 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaEnigma

An Java implementation of the Nazi cipher machine used during World War II.

Featuring:

  • Easy to use API
  • Configurable rotor, plugboard and reflectors
  • Unit tested
  • BSD Licenced

Usage

Basic usage

Instantiate a new machine using the EnigmaMachineBuilder, the builder will prompt the user for all the required configuration returning a functioning EnigmaMachine instance.

EnigmaMachine enigmaMachine = EnigmaMachineBuilder
                               .addRotor1(RotorType.I)
                               .addRotor2(RotorType.II,
                               .addRotor3(RotorType.III)
                               .addReflector(ReflectorType.B)
                               .build();

The EnigmaMachine instance can encrypt a single character or process a String of text. The EnigmaMachine instance stores rotor positions so any additional material encrypted will be enciphered using the rotor positions after the last call to .encrypt().

enigmaMachine.encrypt("SETECASTRONOMY");

The enigma machine can only encrypt uppercase alphabetic characters, with no spaces or punctuation. Therefore all data passed to the encryption device will be converted to uppercase and stripped of non-compatible characters.

public char encrypt(char pt)
public String encrypt(String pt)

The encryption function is overloaded to accept a String of characters or a single character at a time - internally the char function is used.

Advanced usage

The configuration below shows a Plugboard configured with a number of cables in addition to custom start positions for rotors 1-3.

Plugboard plugboard = new PlugboardImpl();
plugboard.addCable('A', 'H').addCable('Q', 'C').addCable('P', 'A');

EnigmaMachine enigmaMachine = EnigmaMachineBuilder
                               .addRotor1(RotorType.I, 'H')
                               .addRotor2(RotorType.II, 'A')
                               .addRotor3(RotorType.III, 'A')
                               .addReflector(ReflectorType.B)  
                               .addPlugBoard(plugboard)
                               .build();

TODO

  • Increase unit test coverage
  • Create a way to implement custom rotors and reflectors

Dependencies

Thanks

Thanks to Marcin Wrzeszcz and Hugh O'Brien for the inspiration to create the library.

References

About

No description, website, or topics provided.

Resources

Stars

11 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages