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

        let chars = self.chars.as_bytes();
        let mut ctext: Vec<u8> = Vec::with_capacity(ptext.len());

        for c in ptext.bytes() {
            let i = match self.key.find(move |j| j == c as char) {
                Some(val) => val,
                None => return Err(CipherInputError::NotInAlphabet),
            };

            ctext.push(chars[i / chars.len()]);
            ctext.push(chars[i % chars.len()]);
        }

        Ok(String::from_utf8(ctext).unwrap())
    }
/// Enciphers the given plaintext (a str reference) using the Polybius Square
/// cipher and returns the ciphertext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, PolybiusSquare};
///
/// let ps = PolybiusSquare::new("PHQGIUMEAYLNOFDXKRCVSTZWB", "ABCDE");
///
/// let ctext = ps.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
/// assert_eq!(ctext.unwrap(), "CEBCCDBCCBCEEBABBCBCBDEAEBEDBDCACACCCDEBABBCDDBDEAEBCABC");
/// ```
Enciphers the given plaintext (a str reference) using the Polybius Square
cipher and returns the ciphertext as a `CipherResult`.
Enciphers the given plaintext ( a str reference ) using the Polybius Square cipher and returns the ciphertext as a ` CipherResult ` .
fn encipher(&self, ptext: &str) -> CipherResult {
        input::in_alphabet(ptext, &self.key)?;
        let chars = self.chars.as_bytes();
        let mut ctext: Vec<u8> = Vec::with_capacity(ptext.len());
        for c in ptext.bytes() {
            let i = match self.key.find(move |j| j == c as char) {
                Some(val) => val,
                None => return Err(CipherInputError::NotInAlphabet),
            };
            ctext.push(chars[i / chars.len()]);
            ctext.push(chars[i % chars.len()]);
        }
        Ok(String::from_utf8(ctext).unwrap())
    }
fn encipher ( & self , ptext : & str ) -> CipherResult { input :: in_alphabet ( ptext , & self . key ) ? ; let chars = self . chars . as_bytes ( ) ; let mut ctext : Vec < u8 > = Vec :: with_capacity ( ptext . len ( ) ) ; for c in ptext . bytes ( ) { let i = match self . key . find ( move | j | j == c as char ) { Some ( val ) => val , None => return Err ( CipherInputError :: NotInAlphabet ) , } ; ctext . push ( chars [ i / chars . len ( ) ] ) ; ctext . push ( chars [ i % chars . len ( ) ] ) ; } Ok ( String :: from_utf8 ( ctext ) . unwrap ( ) ) }
Enciphers the given plaintext (a str reference) using the Polybius Square
cipher and returns the ciphertext as a `CipherResult`.
Enciphers the given plaintext ( a str reference ) using the Polybius Square cipher and returns the ciphertext as a ` CipherResult ` .
&self
ptext
&str
&self
ptext
&str
example
```
use ciphers::{Cipher, PolybiusSquare}.

let ps = PolybiusSquare::new("PHQGIUMEAYLNOFDXKRCVSTZWB", "ABCDE").


` ` ` use ciphers :: { Cipher PolybiusSquare } . let ps = PolybiusSquare :: new ( " PHQGIUMEAYLNOFDXKRCVSTZWB " " ABCDE " ) .