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

        let ptext = ptext.to_ascii_uppercase();
        let key = self.key.as_bytes();

        let ctext = ptext
            .bytes()
            .enumerate()
            .map(move |(i, c)| {
                let y = (key[i % key.len()] as usize - 65) / 2;
                match c {
                    78...90 => PORTA_TABLEU[y].iter().position(|&j| j == c).unwrap() as u8 + 65,
                    _ => PORTA_TABLEU[y][c as usize - 65],
                }
            })
            .collect();

        Ok(String::from_utf8(ctext).unwrap())
    }
/// Enciphers the given plaintext (a str reference) using the Porta cipher
/// and returns the ciphertext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, Porta};
///
/// let porta = Porta::new("FORTIFICATION");
///
/// let ctext = porta.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
/// assert_eq!(ctext.unwrap(), "SYNNJSCVRNRLAHUTUKUCVRYRLANY");
/// ```
Enciphers the given plaintext (a str reference) using the Porta cipher
and returns the ciphertext as a `CipherResult`.
Enciphers the given plaintext ( a str reference ) using the Porta 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 ctext = ptext
            .bytes()
            .enumerate()
            .map(move |(i, c)| {
                let y = (key[i % key.len()] as usize - 65) / 2;
                match c {
                    78...90 => PORTA_TABLEU[y].iter().position(|&j| j == c).unwrap() as u8 + 65,
                    _ => PORTA_TABLEU[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 ctext = ptext . bytes ( ) . enumerate ( ) . map ( move | ( i , c ) | { let y = ( key [ i % key . len ( ) ] as usize - 65 ) / 2 ; match c { 78 ... 90 => PORTA_TABLEU [ y ] . iter ( ) . position ( | & j | j == c ) . unwrap ( ) as u8 + 65 , _ => PORTA_TABLEU [ y ] [ c as usize - 65 ] , } } ) . collect ( ) ; Ok ( String :: from_utf8 ( ctext ) . unwrap ( ) ) }
Enciphers the given plaintext (a str reference) using the Porta cipher
and returns the ciphertext as a `CipherResult`.
Enciphers the given plaintext ( a str reference ) using the Porta cipher and returns the ciphertext as a ` CipherResult ` .
&self
ptext
&str
&self
ptext
&str
example
```
use ciphers::{Cipher, Porta}.

let porta = Porta::new("FORTIFICATION").

let ctext = porta.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "SYNNJSCVRNRLAHUTUKUCVRYRLANY");
```
` ` ` use ciphers :: { Cipher Porta } . let porta = Porta :: new ( " FORTIFICATION " ) . let ctext = porta . encipher ( " DEFENDTHEEASTWALLOFTHECASTLE " ) ; assert_eq! ( ctext . unwrap () " SYNNJSCVRNRLAHUTUKUCVRYRLANY " ) ; ` ` `