readme: Added example inline

This commit is contained in:
K Shiva Kiran 2024-05-07 14:50:52 +05:30
parent 2f7deacdb1
commit 23e1d52b04
1 changed files with 29 additions and 3 deletions

View File

@ -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 <filename>
```
### 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.