pub struct ColumnarTransposition { /* private fields */ }
Expand description

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

Trait Implementations§

Initialize a Columnar Transposition cipher.

Where…

  • Elements of keystream are used as the column identifiers.
  • The optional null_char is used to pad messages of uneven length.
  • The derived_key is used to initialise the column structures in the cipher.
Panics
  • The keystream length is 0.
  • The keystream contains non-alphanumeric symbols.
  • The keystream contains duplicate characters.
  • The null_char is a character within the keystream

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));;

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

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));;
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));;

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

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.