Crates.io | playfair |
lib.rs | playfair |
version | 1.0.0 |
source | src |
created_at | 2022-11-26 21:23:07.330636 |
updated_at | 2023-01-08 22:58:13.243579 |
description | A Playfair Cipher implementation in Rust |
homepage | |
repository | https://github.com/taxborn/playfair-rs |
max_upload_size | |
id | 723465 |
size | 38,767 |
Originally was an assignment for my CS 303: Databases and Information Security class, I wanted to take some more time and implement it again. This is my solution to implementing the Playfair Cipher in Rust.
Some implementations omit the letter 'q' in encryption/decryption, some omit 'j', and some equate 'i' to 'j'. For my implementation, I went with 'i' = 'j', since that is what the Wikipedia article's example followed, and a random online playfair cipher website used by default. This allowed for easy verification of my implementation.
I also used a Makefile to enforce strict commenting of all my functions
to ensure I knew what was going on at that line and function. As well thanks to the awesome
Rust ecosystem, it enables generation of documentation
with just a single make
command. That documentation can be found in the ./target/doc/playfair_rs/
directory, following execution of the make
command.
I also used testing extensively, for each part from keyword generation, matrix computation, character location, to full integration testing. Combining this with assertions in the code, I have a pretty good idea that my code is correct.
You can see an example in main.rs, or here is a simple shown implementation:
Encryption steps:
use playfair::{Cipher, Playfair};
// Example from https://en.wikipedia.org/wiki/Playfair_cipher.
fn main() {
let pf = Playfair::new("playfair example");
let out = pf.encrypt("Hide the gold in the tree stump.");
// out = bmodzbxdnabekudmuixmmouvif
}
Decryption steps:
use playfair::{Cipher, Playfair};
// Example from https://en.wikipedia.org/wiki/Playfair_cipher.
fn main() {
let pf = Playfair::new("playfair example");
let out = pf.decrypt("bmodzbxdnabekudmuixmmouvif");
// out = hidethegoldinthetrexestump
// NOTE: the extra 'x' here ^ is expected since it was inserted during the encryption process.
// Read more about the Playfair cipher to understand why.
}