pub fn transposition(decrypt_mode: bool, msg: &str, key: &str) -> String {
    let key_uppercase: String = key.to_uppercase();
    let mut cipher_msg: String = msg.to_string();

    let keys: Vec<&str> = match decrypt_mode {
        false => key_uppercase.split_whitespace().collect(),
        true => key_uppercase.split_whitespace().rev().collect(),
    };

    for cipher_key in &keys {
        let mut key_order: Vec<usize> = Vec::new();
        let mut counter: u8 = 0;

        // Removes any non-alphabet characters from 'msg'
        cipher_msg = cipher_msg
            .to_uppercase()
            .chars()
            .filter(|&c| c.is_ascii_alphabetic())
            .collect();

        // Determines the sequence of the columns, as dictated by the
        // alphabetical order of the keyword's letters
        let mut key_ascii: Vec<(usize, u8)> =
            cipher_key.bytes().enumerate().collect::<Vec<(usize, u8)>>();

        key_ascii.sort_by_key(|&(_, key)| key);

        key_ascii.iter_mut().for_each(|(_, key)| {
            *key = counter;
            counter += 1;
        });

        key_ascii.sort_by_key(|&(index, _)| index);

        key_ascii
            .into_iter()
            .for_each(|(_, key)| key_order.push(key.into()));

        // Determines whether to encrypt or decrypt the message,
        // and returns the result
        cipher_msg = match decrypt_mode {
            false => encrypt(cipher_msg, key_order),
            true => decrypt(cipher_msg, key_order),
        };
    }

    println!("Original Message: {}", msg);
    match decrypt_mode {
        false => println!("Encrypted Message: {}\n", cipher_msg),
        true => println!("Decrypted Message: {}\n", cipher_msg),
    };

    cipher_msg
}
/// Encrypts or decrypts a message, using multiple keys. The
/// encryption is based on the columnar transposition method.
Encrypts or decrypts a message, using multiple keys. The
encryption is based on the columnar transposition method.
Encrypts or decrypts a message using multiple keys . The encryption is based on the columnar transposition method .
pub fn transposition(decrypt_mode: bool, msg: &str, key: &str) -> String {
    let key_uppercase: String = key.to_uppercase();
    let mut cipher_msg: String = msg.to_string();
    let keys: Vec<&str> = match decrypt_mode {
        false => key_uppercase.split_whitespace().collect(),
        true => key_uppercase.split_whitespace().rev().collect(),
    };
    for cipher_key in &keys {
        let mut key_order: Vec<usize> = Vec::new();
        let mut counter: u8 = 0;
        // Removes any non-alphabet characters from 'msg'
        cipher_msg = cipher_msg
            .to_uppercase()
            .chars()
            .filter(|&c| c.is_ascii_alphabetic())
            .collect();
        // Determines the sequence of the columns, as dictated by the
        // alphabetical order of the keyword's letters
        let mut key_ascii: Vec<(usize, u8)> =
            cipher_key.bytes().enumerate().collect::<Vec<(usize, u8)>>();
        key_ascii.sort_by_key(|&(_, key)| key);
        key_ascii.iter_mut().for_each(|(_, key)| {
            *key = counter;
            counter += 1;
        });
        key_ascii.sort_by_key(|&(index, _)| index);
        key_ascii
            .into_iter()
            .for_each(|(_, key)| key_order.push(key.into()));
        // Determines whether to encrypt or decrypt the message,
        // and returns the result
        cipher_msg = match decrypt_mode {
            false => encrypt(cipher_msg, key_order),
            true => decrypt(cipher_msg, key_order),
        };
    }
    println!("Original Message: {}", msg);
    match decrypt_mode {
        false => println!("Encrypted Message: {}\n", cipher_msg),
        true => println!("Decrypted Message: {}\n", cipher_msg),
    };
    cipher_msg
}
pub fn transposition ( decrypt_mode : bool , msg : & str , key : & str ) -> String { let key_uppercase : String = key . to_uppercase ( ) ; let mut cipher_msg : String = msg . to_string ( ) ; let keys : Vec < & str > = match decrypt_mode { false => key_uppercase . split_whitespace ( ) . collect ( ) , true => key_uppercase . split_whitespace ( ) . rev ( ) . collect ( ) , } ; for cipher_key in & keys { let mut key_order : Vec < usize > = Vec :: new ( ) ; let mut counter : u8 = 0 ; // Removes any non-alphabet characters from 'msg' cipher_msg = cipher_msg . to_uppercase ( ) . chars ( ) . filter ( | & c | c . is_ascii_alphabetic ( ) ) . collect ( ) ; // Determines the sequence of the columns, as dictated by the // alphabetical order of the keyword's letters let mut key_ascii : Vec < ( usize , u8 ) > = cipher_key . bytes ( ) . enumerate ( ) . collect :: < Vec < ( usize , u8 ) > > ( ) ; key_ascii . sort_by_key ( | & ( _ , key ) | key ) ; key_ascii . iter_mut ( ) . for_each ( | ( _ , key ) | { * key = counter ; counter += 1 ; } ) ; key_ascii . sort_by_key ( | & ( index , _ ) | index ) ; key_ascii . into_iter ( ) . for_each ( | ( _ , key ) | key_order . push ( key . into ( ) ) ) ; // Determines whether to encrypt or decrypt the message, // and returns the result cipher_msg = match decrypt_mode { false => encrypt ( cipher_msg , key_order ) , true => decrypt ( cipher_msg , key_order ) , } ; } println ! ( " " msg ) ; match decrypt_mode { false => println ! ( " \n " cipher_msg ) , true => println ! ( " \n " cipher_msg ) , } ; cipher_msg }
Encrypts or decrypts a message, using multiple keys.
Encrypts or decrypts a message using multiple keys .
decrypt_mode
bool
msg
&str
key
&str