Struct cipher_crypt::columnar_transposition::ColumnarTransposition
[−]
[src]
pub struct ColumnarTransposition { /* fields omitted */ }A ColumnarTransposition cipher.
This struct is created by the new() method. See its documentation for more.
Trait Implementations
impl Cipher for ColumnarTransposition[src]
type Key = String
type Algorithm = ColumnarTransposition
fn new(key: String) -> Result<ColumnarTransposition, &'static str>[src]
Initialize a Columnar Transposition cipher given a specific key.
Will return Err if one of the following conditions is detected:
- The
keylength is 0. - The
keycontains non-alphanumeric symbols. - The
keycontains duplicate characters.
fn encrypt(&self, message: &str) -> Result<String, &'static str>[src]
Encrypt a message with a Columnar Transposition cipher.
Whilst all characters (including utf8) can be encrypted during the transposition process, it is important to note that the space character is also treated as padding. As such, whitespace characters at the end of a message are not preserved during the decryption process.
Examples
Basic usage:
use cipher_crypt::{Cipher, ColumnarTransposition}; let ct = ColumnarTransposition::new(String::from("zebras")).unwrap(); assert_eq!("res pce!uemeers -ta Ss g", ct.encrypt("Super-secret message!").unwrap());
fn decrypt(&self, ciphertext: &str) -> Result<String, &'static str>[src]
Decrypt a ciphertext with a Columnar Transposition cipher.
Examples
Basic usage:
use cipher_crypt::{Cipher, ColumnarTransposition}; let ct = ColumnarTransposition::new(String::from("zebras")).unwrap(); assert_eq!("Super-secret message!", ct.decrypt("res pce!uemeers -ta Ss g").unwrap());