/// Deciphers the given ciphertext (a str reference) using the Four-Square
/// cipher and returns the plaintext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, FourSquare};
///
/// let four_square = FourSquare::new(
///     "ZGPTFOIHMUWDRCNYKEQAXVSBL",
///     "MFNBDCRHSAXYOGVITUEWLQZKP",
///     "ABCDEFGHIKLMNOPQRSTUVWXYZ",
///     'X',
/// );
///
/// let ptext = four_square.decipher("TIYBFHTIZBSY");
/// assert_eq!(ptext.unwrap(), "ATTACKATDAWN");
/// ```
Deciphers the given ciphertext (a str reference) using the Four-Square
cipher and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Four - Square cipher and returns the plaintext as a ` CipherResult ` .
fn decipher(&self, ctext: &str) -> CipherResult {
        input::in_alphabet(ctext, &self.alphabet)?;
        if ctext.len() % 2 != 0 {
            return Err(CipherInputError::BadInput(String::from(
                "`ctext` must contain an even number of chars",
            )));
        }
        let ctext = ctext.as_bytes();
        let mut ptext = Vec::with_capacity(ctext.len());
        for i in (0..ctext.len()).step_by(2) {
            let yx1 = match self.key1.find(|c| c == ctext[i] as char) {
                Some(val) => val,
                None => return Err(CipherInputError::NotInAlphabet),
            };
            let yx2 = match self.key2.find(|c| c == ctext[i + 1] as char) {
                Some(val) => val,
                None => return Err(CipherInputError::NotInAlphabet),
            };
            let (y1, x2) = (yx1 / 5, yx1 % 5);
            let (y2, x1) = (yx2 / 5, yx2 % 5);
            ptext.push(self.alphabet.as_bytes()[y1 * 5 + x1]);
            ptext.push(self.alphabet.as_bytes()[y2 * 5 + x2]);
        }
        Ok(String::from_utf8(ptext).unwrap())
    }
fn decipher ( & self , ctext : & str ) -> CipherResult { input :: in_alphabet ( ctext , & self . alphabet ) ? ; if ctext . len ( ) % 2 != 0 { return Err ( CipherInputError :: BadInput ( String :: from ( " " , ) ) ) ; } let ctext = ctext . as_bytes ( ) ; let mut ptext = Vec :: with_capacity ( ctext . len ( ) ) ; for i in ( 0 .. ctext . len ( ) ) . step_by ( 2 ) { let yx1 = match self . key1 . find ( | c | c == ctext [ i ] as char ) { Some ( val ) => val , None => return Err ( CipherInputError :: NotInAlphabet ) , } ; let yx2 = match self . key2 . find ( | c | c == ctext [ i + 1 ] as char ) { Some ( val ) => val , None => return Err ( CipherInputError :: NotInAlphabet ) , } ; let ( y1 , x2 ) = ( yx1 / 5 , yx1 % 5 ) ; let ( y2 , x1 ) = ( yx2 / 5 , yx2 % 5 ) ; ptext . push ( self . alphabet . as_bytes ( ) [ y1 * 5 + x1 ] ) ; ptext . push ( self . alphabet . as_bytes ( ) [ y2 * 5 + x2 ] ) ; } Ok ( String :: from_utf8 ( ptext ) . unwrap ( ) ) }
Deciphers the given ciphertext (a str reference) using the Four-Square
cipher and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Four - Square cipher and returns the plaintext as a ` CipherResult ` .
&self
ctext
&str
example
```
use ciphers::{Cipher, FourSquare}.

let four_square = FourSquare::new(
"ZGPTFOIHMUWDRCNYKEQAXVSBL",
"MFNBDCRHSAXYOGVITUEWLQZKP",
"ABCDEFGHIKLMNOPQRSTUVWXYZ",
'X',
).

let ptext = four_square.decipher("TIYBFHTIZBSY");
assert_eq!(ptext.unwrap(), "ATTACKATDAWN");
```
` ` ` use ciphers :: { Cipher FourSquare } . let four_square = FourSquare :: new ( " ZGPTFOIHMUWDRCNYKEQAXVSBL " " MFNBDCRHSAXYOGVITUEWLQZKP " " ABCDEFGHIKLMNOPQRSTUVWXYZ " ' X ' ) . let ptext = four_square . decipher ( " TIYBFHTIZBSY " ) ; assert_eq! ( ptext . unwrap () " ATTACKATDAWN " ) ; ` ` `