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

        let mut ptext = vec![0u8; ctext.len()];
        let ctext: Vec<u8> = ctext.bytes().collect();
        let mut k = 0usize;

        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 < ctext.len() {
                ptext[i] = *ctext.get(k).unwrap();
                k += 1;

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

                j += 1;
            }

            line += 1;
        }

        for i in (line..ctext.len()).step_by(2 * (self.key - 1)) {
            ptext[i] = *ctext.get(k).unwrap();
            k += 1;
        }

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

let rail_fence = RailFence::new(4).

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