cryptor/cryptor/algorithm/enigma/
reflector.rs1
2use super::{ SubstitutionTable, ALPHABETS };
10
11use utility::{ GetIndex, IndexResult };
13
14pub struct Reflector {
15 substitution_table: SubstitutionTable
16}
17
18impl Reflector {
19
20 pub fn new(substitution_table: SubstitutionTable) -> Self {
21 Reflector {
22 substitution_table
23 }
24 }
25
26 pub fn reflect(&self, character: &char) -> char {
27 let characters = ALPHABETS.to_vec();
28 match characters.get_index(character) {
29 IndexResult::Exist(index) => self.substitution_table.characters[index],
30 IndexResult::None => *character
31 }
32 }
33}