Struct cryptatools_core::cryptography::classical::encryption::polyalphabetic_ciphers::vigenere::VigenereNoTable
source · pub struct VigenereNoTable {
pub alphabet: Arc<Alphabet>,
pub sorted_alphabet: Vec<Vec<u8>>,
}
Fields§
§alphabet: Arc<Alphabet>
§sorted_alphabet: Vec<Vec<u8>>
Implementations§
source§impl VigenereNoTable
impl VigenereNoTable
pub fn new(alphabet: Arc<Alphabet>) -> Self
sourcepub fn encrypt(
&self,
plain_text: Vec<u8>,
passphrase_key: Vec<Vec<u8>>
) -> Vec<u8> ⓘ
pub fn encrypt( &self, plain_text: Vec<u8>, passphrase_key: Vec<Vec<u8>> ) -> Vec<u8> ⓘ
use cryptatools_core::utils::{alphabets, alphabets::Alphabet, convert::Encode};
use cryptatools_core::cryptography::classical::encryption::polyalphabetic_ciphers::vigenere::VigenereNoTable;
let ascii_alphabet = Alphabet::new_empty().ascii_encoding();
let v = VigenereNoTable::new(ascii_alphabet.clone().into());
let plaintext = Encode::from_ascii_to_u8(String::from("the quick brown roman fox jumped over the lazy ostrogoth dog"));
assert_eq!(plaintext, [116, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, 114, 111, 119, 110, 32, 114, 111, 109, 97, 110, 32, 102, 111, 120, 32, 106, 117, 109, 112, 101, 100, 32, 111, 118, 101, 114, 32, 116, 104, 101, 32, 108, 97, 122, 121, 32, 111, 115, 116, 114, 111, 103, 111, 116, 104, 32, 100, 111, 103]);
let key = alphabets::split_bytes_by_characters_representation(&ascii_alphabet.clone(), Encode::from_ascii_to_u8(String::from("caesar")));
assert_eq!(key, [[99], [97], [101], [115], [97], [114]]);
let result = v.encrypt(plaintext, key);
assert_eq!(result, [86, 72, 73, 18, 81, 102, 75, 67, 79, 18, 66, 99, 81, 87, 82, 18, 82, 96, 79, 65, 82, 18, 70, 96, 90, 0, 78, 103, 77, 97, 71, 68, 4, 97, 86, 86, 84, 0, 88, 90, 69, 17, 78, 65, 94, 107, 0, 96, 85, 84, 86, 97, 71, 96, 86, 72, 4, 86, 79, 88]);
use cryptatools_core::utils::convert::Decode;
let str_encrypted = Decode::from_u8_to_ascii(result);
assert_eq!(str_encrypted, "VHI\u{12}QfKCO\u{12}BcQWR\u{12}R`OAR\u{12}F`Z\0NgMaGD\u{4}aVVT\0XZE\u{11}NA^k\0`UTVaG`VH\u{4}VOX");
let uppurcase_ascii_alphabet_with_no_chars = Alphabet::new_empty().uppercase_no_space_ascii_alphabet_encoding();
let v = VigenereNoTable::new(uppurcase_ascii_alphabet_with_no_chars.clone().into());
let plaintext = Encode::from_ascii_to_u8(String::from("thequickbrownromanfoxjumpedoverthelazyostrogothdog").to_uppercase());
let key = alphabets::split_bytes_by_characters_representation(&uppurcase_ascii_alphabet_with_no_chars.clone().into(), Encode::from_ascii_to_u8(String::from("CAESAR")));
assert_eq!(plaintext, [84, 72, 69, 81, 85, 73, 67, 75, 66, 82, 79, 87, 78, 82, 79, 77, 65, 78, 70, 79, 88, 74, 85, 77, 80, 69, 68, 79, 86, 69, 82, 84, 72, 69, 76, 65, 90, 89, 79, 83, 84, 82, 79, 71, 79, 84, 72, 68, 79, 71]);
assert_eq!(key, [[67], [65], [69], [83], [65], [82]]);
let result = v.encrypt(plaintext, key);
assert_eq!(result, [86, 72, 73, 73, 85, 90, 69, 75, 70, 74, 79, 78, 80, 82, 83, 69, 65, 69, 72, 79, 66, 66, 85, 68, 82, 69, 72, 71, 86, 86, 84, 84, 76, 87, 76, 82, 66, 89, 83, 75, 84, 73, 81, 71, 83, 76, 72, 85, 81, 71]);
let str_encrypted = Decode::from_u8_to_ascii(result);
assert_eq!(str_encrypted, "VHIIUZEKFJONPRSEAEHOBBUDREHGVVTTLWLRBYSKTIQGSLHUQG");
Auto Trait Implementations§
impl RefUnwindSafe for VigenereNoTable
impl Send for VigenereNoTable
impl Sync for VigenereNoTable
impl Unpin for VigenereNoTable
impl UnwindSafe for VigenereNoTable
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more