use ciphers::{Autokey, Cipher, CipherInputError};
#[test]
fn encipher_small() {
let autokey = Autokey::new("FORTIFICATION");
let ctext = autokey.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "ISWXVIBJEXIGGZEQPBIMOIGAKMHE");
}
#[test]
fn decipher_small() {
let autokey = Autokey::new("FORTIFICATION");
let ptext = autokey.decipher("ISWXVIBJEXIGGZEQPBIMOIGAKMHE");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
fn encipher_large() {
let autokey = Autokey::new("ZYXWVUTSRQPON");
let ctext = autokey.encipher("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
assert_eq!(
ctext.unwrap(),
"ZZZZZZZZZZZZZNPRTVXZBDFHJLNPRTVXZBDFHJLNPRTVXZBDFHJL"
);
}
#[test]
fn decipher_large() {
let autokey = Autokey::new("ZYXWVUTSRQPON");
let ptext = autokey.decipher("ZZZZZZZZZZZZZNPRTVXZBDFHJLNPRTVXZBDFHJLNPRTVXZBDFHJL");
assert_eq!(
ptext.unwrap(),
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
#[test]
fn encipher_lowercase() {
let autokey = Autokey::new("fortification");
let ctext = autokey.encipher("defendtheeastwallofthecastle");
assert_eq!(ctext.unwrap(), "ISWXVIBJEXIGGZEQPBIMOIGAKMHE");
}
#[test]
fn decipher_lowercase() {
let autokey = Autokey::new("fortification");
let ptext = autokey.decipher("iswxvibjexiggzeqpbimoigakmhe");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
#[should_panic]
fn key_non_alpha() {
Autokey::new("f0rtificati0n");
}
#[test]
fn ptext_non_alpha() {
let autokey = Autokey::new("fortification");
let ctext = autokey.encipher("d3f3ndtheeastwallofthecastle");
assert_eq!(ctext, Err(CipherInputError::NotAlphabetic));
}
#[test]
fn ctext_non_alpha() {
let autokey = Autokey::new("fortification");
let ptext = autokey.decipher("15wxvibjexiggzeqpbimoigakmh3");
assert_eq!(ptext, Err(CipherInputError::NotAlphabetic));
}