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

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

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