/// Deciphers the given ciphertext (a str reference) using the Autokey cipher
/// and returns the plaintext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, Autokey};
///
/// let autokey = Autokey::new("FORTIFICATION");
///
/// let ptext = autokey.decipher("ISWXVIBJEXIGGZEQPBIMOIGAKMHE");
/// assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
/// ```
Deciphers the given ciphertext (a str reference) using the Autokey cipher
and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Autokey cipher and returns the plaintext as a ` CipherResult ` .
fn decipher(&self, ctext: &str) -> CipherResult {
        input::is_alpha(ctext)?;
        let ctext = ctext.to_ascii_uppercase();
        let key = self.key.as_bytes();
        let ctext: Vec<u8> = ctext.bytes().collect();
        let mut ptext: Vec<u8> = Vec::with_capacity(ctext.len());
        for (i, c) in ctext.iter().enumerate() {
            let y = match i {
                i if i < key.len() => key[i] as usize - 65,
                _ => ptext[i - key.len()] as usize - 65,
            };
            ptext.push(TABULA_RECTA[y].iter().position(|&j| j == *c).unwrap() as u8 + 65);
        }
        Ok(String::from_utf8(ptext).unwrap())
    }
fn decipher ( & self , ctext : & str ) -> CipherResult { input :: is_alpha ( ctext ) ? ; let ctext = ctext . to_ascii_uppercase ( ) ; let key = self . key . as_bytes ( ) ; let ctext : Vec < u8 > = ctext . bytes ( ) . collect ( ) ; let mut ptext : Vec < u8 > = Vec :: with_capacity ( ctext . len ( ) ) ; for ( i , c ) in ctext . iter ( ) . enumerate ( ) { let y = match i { i if i < key . len ( ) => key [ i ] as usize - 65 , _ => ptext [ i - key . len ( ) ] as usize - 65 , } ; ptext . push ( TABULA_RECTA [ y ] . iter ( ) . position ( | & j | j == * c ) . unwrap ( ) as u8 + 65 ) ; } Ok ( String :: from_utf8 ( ptext ) . unwrap ( ) ) }
Deciphers the given ciphertext (a str reference) using the Autokey cipher
and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Autokey cipher and returns the plaintext as a ` CipherResult ` .
&self
ctext
&str
example
```
use ciphers::{Cipher, Autokey}.

let autokey = Autokey::new("FORTIFICATION").

let ptext = autokey.decipher("ISWXVIBJEXIGGZEQPBIMOIGAKMHE");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
```
` ` ` use ciphers :: { Cipher Autokey } . let autokey = Autokey :: new ( " FORTIFICATION " ) . let ptext = autokey . decipher ( " ISWXVIBJEXIGGZEQPBIMOIGAKMHE " ) ; assert_eq! ( ptext . unwrap () " DEFENDTHEEASTWALLOFTHECASTLE " ) ; ` ` `