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

        let mut ctext = Vec::with_capacity(ptext.len());
        let ptext: Vec<u8> = ptext.bytes().collect();

        let mut line = 0usize;
        while line < self.key - 1 {
            let skip = 2 * (self.key - line - 1);
            let mut j = 0usize;

            let mut i = line;
            while i < ptext.len() {
                ctext.push(*ptext.get(i).unwrap());

                if line == 0 || j % 2 == 0 {
                    i += skip;
                } else {
                    i += 2 * (self.key - 1) - skip;
                }

                j += 1;
            }

            line += 1;
        }

        for i in (line..ptext.len()).step_by(2 * (self.key - 1)) {
            ctext.push(*ptext.get(i).unwrap());
        }

        Ok(String::from_utf8(ctext).unwrap())
    }
/// Enciphers the given plaintext (a str reference) using the Rail-fence
/// cipher and returns the ciphertext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, RailFence};
///
/// let rail_fence = RailFence::new(4);
///
/// let ctext = rail_fence.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
/// assert_eq!(ctext.unwrap(), "DTTFSEDHSWOTATFNEAALHCLEELEE");
/// ```
Enciphers the given plaintext (a str reference) using the Rail-fence
cipher and returns the ciphertext as a `CipherResult`.
Enciphers the given plaintext ( a str reference ) using the Rail - fence cipher and returns the ciphertext as a ` CipherResult ` .
fn encipher(&self, ptext: &str) -> CipherResult {
        input::is_ascii(ptext)?;
        let mut ctext = Vec::with_capacity(ptext.len());
        let ptext: Vec<u8> = ptext.bytes().collect();
        let mut line = 0usize;
        while line < self.key - 1 {
            let skip = 2 * (self.key - line - 1);
            let mut j = 0usize;
            let mut i = line;
            while i < ptext.len() {
                ctext.push(*ptext.get(i).unwrap());
                if line == 0 || j % 2 == 0 {
                    i += skip;
                } else {
                    i += 2 * (self.key - 1) - skip;
                }
                j += 1;
            }
            line += 1;
        }
        for i in (line..ptext.len()).step_by(2 * (self.key - 1)) {
            ctext.push(*ptext.get(i).unwrap());
        }
        Ok(String::from_utf8(ctext).unwrap())
    }
fn encipher ( & self , ptext : & str ) -> CipherResult { input :: is_ascii ( ptext ) ? ; let mut ctext = Vec :: with_capacity ( ptext . len ( ) ) ; let ptext : Vec < u8 > = ptext . bytes ( ) . collect ( ) ; let mut line = 0usize ; while line < self . key - 1 { let skip = 2 * ( self . key - line - 1 ) ; let mut j = 0usize ; let mut i = line ; while i < ptext . len ( ) { ctext . push ( * ptext . get ( i ) . unwrap ( ) ) ; if line == 0 || j % 2 == 0 { i += skip ; } else { i += 2 * ( self . key - 1 ) - skip ; } j += 1 ; } line += 1 ; } for i in ( line .. ptext . len ( ) ) . step_by ( 2 * ( self . key - 1 ) ) { ctext . push ( * ptext . get ( i ) . unwrap ( ) ) ; } Ok ( String :: from_utf8 ( ctext ) . unwrap ( ) ) }
Enciphers the given plaintext (a str reference) using the Rail-fence
cipher and returns the ciphertext as a `CipherResult`.
Enciphers the given plaintext ( a str reference ) using the Rail - fence cipher and returns the ciphertext as a ` CipherResult ` .
&self
ptext
&str
&self
ptext
&str
example
```
use ciphers::{Cipher, RailFence}.

let rail_fence = RailFence::new(4).

let ctext = rail_fence.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "DTTFSEDHSWOTATFNEAALHCLEELEE");
```
` ` ` use ciphers :: { Cipher RailFence } . let rail_fence = RailFence :: new ( 4 ) . let ctext = rail_fence . encipher ( " DEFENDTHEEASTWALLOFTHECASTLE " ) ; assert_eq! ( ctext . unwrap () " DTTFSEDHSWOTATFNEAALHCLEELEE " ) ; ` ` `