/// Deciphers the given ciphertext (a str reference) using the Running Key
/// cipher and returns the plaintext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, RunningKey};
///
/// let running_key = RunningKey::new("HOWDOESTHEDUCKKNOWTHATSAIDVICTOR");
///
/// let ptext = running_key.decipher("KSBHBHLALIDMVGKYZKYAHXUAAWGM");
/// assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
/// ```
Deciphers the given ciphertext (a str reference) using the Running Key
cipher and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Running Key cipher and returns the plaintext as a ` CipherResult ` .
fn decipher(&self, ctext: &str) -> CipherResult {
        if self.key.len() < ctext.len() {
            return Err(CipherInputError::BadInput(String::from(
                "`ctext` cannot be longer than the key",
            )));
        }
        input::is_alpha(ctext)?;
        let ctext = ctext.to_ascii_uppercase();
        let key = self.key.as_bytes();
        let ptext = ctext
            .bytes()
            .enumerate()
            .map(move |(i, c)| {
                let y = key[i] as usize - 65;
                TABULA_RECTA[y].iter().position(|&j| j == c).unwrap() as u8 + 65
            })
            .collect();
        Ok(String::from_utf8(ptext).unwrap())
    }
fn decipher ( & self , ctext : & str ) -> CipherResult { if self . key . len ( ) < ctext . len ( ) { return Err ( CipherInputError :: BadInput ( String :: from ( " " , ) ) ) ; } input :: is_alpha ( ctext ) ? ; let ctext = ctext . to_ascii_uppercase ( ) ; let key = self . key . as_bytes ( ) ; let ptext = ctext . bytes ( ) . enumerate ( ) . map ( move | ( i , c ) | { let y = key [ i ] as usize - 65 ; TABULA_RECTA [ y ] . iter ( ) . position ( | & j | j == c ) . unwrap ( ) as u8 + 65 } ) . collect ( ) ; Ok ( String :: from_utf8 ( ptext ) . unwrap ( ) ) }
Deciphers the given ciphertext (a str reference) using the Running Key
cipher and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Running Key cipher and returns the plaintext as a ` CipherResult ` .
&self
ctext
&str
example
```
use ciphers::{Cipher, RunningKey}.



let ptext = running_key.decipher("KSBHBHLALIDMVGKYZKYAHXUAAWGM");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
```
` ` ` use ciphers :: { Cipher RunningKey } . let ptext = running_key . decipher ( " KSBHBHLALIDMVGKYZKYAHXUAAWGM " ) ; assert_eq! ( ptext . unwrap () " DEFENDTHEEASTWALLOFTHECASTLE " ) ; ` ` `