Struct cipher_crypt::columnar_transposition::ColumnarTransposition [] [src]

pub struct ColumnarTransposition { /* fields omitted */ }

A Columnar Transposition cipher. This struct is created by the new() method. See its documentation for more.

Trait Implementations

impl Cipher for ColumnarTransposition
[src]

[src]

Initialize a Columnar Transposition cipher.

Where...

  • Elements of key are used as the column identifiers.
  • The optional null_char is used to pad messages of uneven length.

Will return Err if one of the following conditions is detected:

  • The key length is 0.
  • The key contains non-alphanumeric symbols.
  • The key contains duplicate characters.
  • The null_char is a character within the key

[src]

Encrypt a message with a Columnar Transposition cipher.

All characters (including utf8) can be encrypted during the transposition process. However, it is important to note that if padding characters are being used (null_char), the user must ensure that the message does not contain these padding characters, otherwise problems will occur during decryption. For this reason, the function will Err if it detects padding characters in the message to be encrypted.

Examples

Basic usage:

use cipher_crypt::{Cipher, ColumnarTransposition};

let key_word = String::from("zebras");
let null_char = None;

let ct = ColumnarTransposition::new((key_word, null_char)).unwrap();

assert_eq!("respce!uemeers-taSs g", ct.encrypt("Super-secret message!").unwrap());

[src]

Decrypt a ciphertext with a Columnar Transposition cipher.

Examples

Basic usage:

use cipher_crypt::{Cipher, ColumnarTransposition};

let key_word = String::from("zebras");
let null_char = None;

let ct = ColumnarTransposition::new((key_word, null_char)).unwrap();
assert_eq!("Super-secret message!", ct.decrypt("respce!uemeers-taSs g").unwrap());

Using whitespace as null (special case): This will strip only trailing whitespace in message during decryption

use cipher_crypt::{Cipher, ColumnarTransposition};

let key_word = String::from("zebras");
let null_char = None;
let message = "we are discovered  "; // Only trailing spaces will be stripped

let ct = ColumnarTransposition::new((key_word, null_char)).unwrap();

assert_eq!(ct.decrypt(&ct.encrypt(message).unwrap()).unwrap(),"we are discovered");

Auto Trait Implementations