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

        let key: Vec<u8> = self.key.bytes().collect();
        let ctext = ctext.as_bytes();
        let mut matrix: HashMap<u8, Vec<u8>> = HashMap::with_capacity(key.len());

        let mut sorted_key = key.clone();
        sorted_key.sort();

        for k in sorted_key.iter() {
            matrix.insert(*k, vec![]);
        }

        // populate matrix
        let mut i = 0usize;
        let mut k = 0usize;
        while i < ctext.len() {
            // calculate length of current entry
            let col = key.iter().position(|&c| c == sorted_key[k]).unwrap();
            let len = if col < ctext.len() % key.len() {
                ctext.len() / key.len() + 1
            } else {
                ctext.len() / key.len()
            };

            for _ in 0..len {
                matrix.entry(sorted_key[k]).or_insert(vec![]);
                matrix.get_mut(&sorted_key[k]).unwrap().push(ctext[i]);
                i += 1;
            }

            k += 1;
        }

        let mut ptext = vec![];
        for i in 0..ctext.len() {
            ptext.push(matrix.get_mut(&key[i % key.len()]).unwrap().remove(0));
        }

        Ok(String::from_utf8(ptext).unwrap())
    }
/// Deciphers the given ciphertext (a str reference) using the Columnar
/// Transposition cipher and returns the plaintext as a `CipherResult`.
///
/// # Example
/// ```
/// use ciphers::{Cipher, ColumnarTransposition};
///
/// let ct = ColumnarTransposition::new("GERMAN");
///
/// let ptext = ct.decipher("NALCEHWTTDTTFSEELEEDSOAFEAHL");
/// assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
/// ```
Deciphers the given ciphertext (a str reference) using the Columnar
Transposition cipher and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Columnar Transposition cipher and returns the plaintext as a ` CipherResult ` .
fn decipher(&self, ctext: &str) -> CipherResult {
        input::is_ascii(ctext)?;
        let key: Vec<u8> = self.key.bytes().collect();
        let ctext = ctext.as_bytes();
        let mut matrix: HashMap<u8, Vec<u8>> = HashMap::with_capacity(key.len());
        let mut sorted_key = key.clone();
        sorted_key.sort();
        for k in sorted_key.iter() {
            matrix.insert(*k, vec![]);
        }
        // populate matrix
        let mut i = 0usize;
        let mut k = 0usize;
        while i < ctext.len() {
            // calculate length of current entry
            let col = key.iter().position(|&c| c == sorted_key[k]).unwrap();
            let len = if col < ctext.len() % key.len() {
                ctext.len() / key.len() + 1
            } else {
                ctext.len() / key.len()
            };
            for _ in 0..len {
                matrix.entry(sorted_key[k]).or_insert(vec![]);
                matrix.get_mut(&sorted_key[k]).unwrap().push(ctext[i]);
                i += 1;
            }
            k += 1;
        }
        let mut ptext = vec![];
        for i in 0..ctext.len() {
            ptext.push(matrix.get_mut(&key[i % key.len()]).unwrap().remove(0));
        }
        Ok(String::from_utf8(ptext).unwrap())
    }
fn decipher ( & self , ctext : & str ) -> CipherResult { input :: is_ascii ( ctext ) ? ; let key : Vec < u8 > = self . key . bytes ( ) . collect ( ) ; let ctext = ctext . as_bytes ( ) ; let mut matrix : HashMap < u8 , Vec < u8 > > = HashMap :: with_capacity ( key . len ( ) ) ; let mut sorted_key = key . clone ( ) ; sorted_key . sort ( ) ; for k in sorted_key . iter ( ) { matrix . insert ( * k , vec ! [ ] ) ; } // populate matrix let mut i = 0usize ; let mut k = 0usize ; while i < ctext . len ( ) { // calculate length of current entry let col = key . iter ( ) . position ( | & c | c == sorted_key [ k ] ) . unwrap ( ) ; let len = if col < ctext . len ( ) % key . len ( ) { ctext . len ( ) / key . len ( ) + 1 } else { ctext . len ( ) / key . len ( ) } ; for _ in 0 .. len { matrix . entry ( sorted_key [ k ] ) . or_insert ( vec ! [ ] ) ; matrix . get_mut ( & sorted_key [ k ] ) . unwrap ( ) . push ( ctext [ i ] ) ; i += 1 ; } k += 1 ; } let mut ptext = vec ! [ ] ; for i in 0 .. ctext . len ( ) { ptext . push ( matrix . get_mut ( & key [ i % key . len ( ) ] ) . unwrap ( ) . remove ( 0 ) ) ; } Ok ( String :: from_utf8 ( ptext ) . unwrap ( ) ) }
Deciphers the given ciphertext (a str reference) using the Columnar
Transposition cipher and returns the plaintext as a `CipherResult`.
Deciphers the given ciphertext ( a str reference ) using the Columnar Transposition cipher and returns the plaintext as a ` CipherResult ` .
&self
ctext
&str
&self
ctext
&str
example
```
use ciphers::{Cipher, ColumnarTransposition}.

let ct = ColumnarTransposition::new("GERMAN").

let ptext = ct.decipher("NALCEHWTTDTTFSEELEEDSOAFEAHL");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
```
` ` ` use ciphers :: { Cipher ColumnarTransposition } . let ct = ColumnarTransposition :: new ( " GERMAN " ) . let ptext = ct . decipher ( " NALCEHWTTDTTFSEELEEDSOAFEAHL " ) ; assert_eq! ( ptext . unwrap () " DEFENDTHEEASTWALLOFTHECASTLE " ) ; ` ` `