1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! Cryptanalysis of the Engima in Rust.

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate itertools;
extern crate ordered_float;
extern crate rand;
extern crate rayon;

mod decrypt;
mod constants;
mod enigma;
mod fitness;
mod plugboard;
mod reflector;
mod rotor;

pub use decrypt::decrypt;
pub use enigma::Enigma;


trait CharIndex {
    fn index(&self) -> usize;
}

impl CharIndex for char {
    fn index(&self) -> usize {
        *self as usize - 65
    }
}


trait ToChar {
    fn to_char(&self) -> char;
}

impl ToChar for usize {
    fn to_char(&self) -> char {
        ((*self % 26) as u8 + 65) as char
    }
}