From 23e1d52b04d01298b038b818a44cd9b7c3d7d8d0 Mon Sep 17 00:00:00 2001 From: K Shiva Kiran Date: Tue, 7 May 2024 14:50:52 +0530 Subject: [PATCH] readme: Added example inline --- README.md | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 07216c6..cab2ce0 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,42 @@ Run the following command in your project directory to add this library. ```sh cargo add false-bottom ``` -Or alternatively, check out the [crates.io](https://crates.io/crates/false-bottom) to add this library to your project using the `Cargo.toml` file. +Or alternatively, check out [crates.io](https://crates.io/crates/false-bottom) to add this library to your project using the `Cargo.toml` file. The documentation is available at [docs.rs](https://docs.rs/false-bottom). -## Run the examples -These are provided in the [examples](./examples) directory. +## Examples +These are provided in the [examples](https://codeberg.org/skran/false-bottom/src/branch/main/examples) directory. Run them using the following command: ```sh cargo run --example ``` +### Encryption +```rust +use false_bottom::{FalseBottom, Fb128}; +fn main() { + // Input messages + let msg1 = "Weather department warns of heavy rains within the upcoming two days"; + let msg2 = "I have gathered intel regarding the government's illegal spying"; + + // Cipher initialization + let mut fb = Fb128::init(12, 12); + + // Encryption (Adding messages is not limited to 2) + let key1 = fb.add(&msg1.as_bytes()); + let key2 = fb.add(&msg2.as_bytes()); + + // Decryption + let decr1 = fb.decrypt(&key1).unwrap(); + let decr2 = fb.decrypt(&key2).unwrap(); + + let result1 = String::from_utf8(decr1).unwrap(); + let result2 = String::from_utf8(decr2).unwrap(); + + assert_eq!(msg1, result1); + assert_eq!(msg2, result2); +} +``` ## Todo - [x] Add more block sizes. - [ ] Add capabilities to edit and delete added messages in the ciphertext.