#encryption-decryption #enigma #machine #highly #flexible #simulation #absurdly

enigma-cipher

An absurdly fast and highly flexible Enigma machine simulation, encryption, and decryption library

2 releases

0.1.1 Oct 5, 2024
0.1.0 Oct 5, 2024

#938 in Cryptography

28 downloads per month

GPL-3.0 license

24KB
438 lines

enigma-rs

An absurdly fast and highly flexible Enigma machine simulation, encryption, and decryption library for Rust.

Usage

cargo add enigma-cipher

Example Usage:

use enigma_cipher::{EnigmaMachine, EnigmaResult, EnigmaBuilder as _};

pub fn main() -> EnigmaResult<()> {
	let machine = EnigmaMachine::new()
		.reflector("B")
		.plugboard("BY EW FZ GI QM RV UX")
		.rotors(1, 2, 3)
		.ring_settings(10, 12, 14)
		.ring_positions(5, 22, 3)?;
	let plaintext = machine.decode("KDZVKMNTYQJPHFXI");
	println!("{plaintext}");
}
cargo run --release

Performance

This crate uses a number of optimization techniques for max performance, including:

  • Memoization of certain functions that are called whenever an Enigma machine is created
  • Maximum runtime release profile applied by cargo-wizard
  • String storage as &[u8] for rapid indexing

lib.rs:

An absurdly fast and highly flexible Enigma machine simulation, encryption, and decryption library.

Dependencies

~0.4–0.9MB
~19K SLoC