fn encipher(&self, ptext: &str) -> CipherResult {
        input::in_alphabet(ptext, &self.alphabet)?;

        let mut ptext: Vec<u8> = ptext.bytes().collect();
        if ptext.len() % 2 != 0 {
            ptext.push(self.pad);
        }

        let key1 = self.key1.as_bytes();
        let key2 = self.key2.as_bytes();

        let mut ctext = Vec::with_capacity(ptext.len());
        for i in (0..ptext.len()).step_by(2) {
            let yx1 = match self.alphabet.bytes().position(|c| c == ptext[i]) {
                Some(val) => val,
                None => return Err(CipherInputError::NotInAlphabet),
            };
            let yx2 = match self.alphabet.bytes().position(|c| c == ptext[i + 1]) {
                Some(val) => val,
                None => return Err(CipherInputError::NotInAlphabet),
            };

            let (y1, x1) = (yx1 / 5, yx1 % 5);
            let (y2, x2) = (yx2 / 5, yx2 % 5);

            ctext.push(key1[y1 * 5 + x2]);
            ctext.push(key2[y2 * 5 + x1]);
        }

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

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

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