-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
309 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,27 @@ | ||
# Encryption | ||
I created an encryption algorithm that can encrypt an arbitrary amount of data with a 64 bit key. | ||
# Feistel Cipher | ||
|
||
## How it works. | ||
It uses a feinstel cipher where a PRNG is used as the round function. However, the feinstel cipher can only encrypt 64 bit blocks of data. | ||
I use the counter mode of operation to encrypt arbitrary amount of data while encrypting identical blocks differently. | ||
## Usage | ||
|
||
```cli | ||
Usage: feistel [COMMAND] | ||
Commands: | ||
encrypt Encrypt data using Feistel cipher | ||
decrypt Decrypt data using Feistel cipher | ||
help Print this message or the help of the given subcommand(s) | ||
Options: | ||
-h, --help Print help | ||
-V, --version Print version | ||
``` | ||
|
||
## Example | ||
|
||
```cli | ||
cat sensitive.png | feistel encrypt --key 123 > encrypted.dat | ||
cat encrypted.dat | feistel decrypt --key 123 > sensitive_decrypted.png | ||
``` | ||
|
||
## About | ||
|
||
This Feistel cipher uses a PRNG as the round function. However, the feistel cipher can only encrypt 64 bit blocks of data. I use the counter mode of operation to encrypt arbitrary amount of data while encrypting identical blocks differently. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crypto::countermode::encrypt_stream; | ||
use crypto::countermode::decrypt_stream; | ||
|
||
use clap::{Arg, Command}; | ||
use std::io::{self, Read, Write}; | ||
|
||
fn main() { | ||
// Define the CLI structure | ||
let matches = Command::new("feistel") | ||
.version("1.0") | ||
.author("Adam Zawierucha") | ||
.about("Feistel Cipher CLI using stdin and stdout") | ||
.subcommand( | ||
Command::new("encrypt") | ||
.about("Encrypt data using Feistel cipher") | ||
.arg(Arg::new("key") | ||
.short('k') | ||
.long("key") | ||
.value_name("NUMBER") | ||
.help("Encryption key (optional, default is 12345)") | ||
.default_value("1234567890") | ||
.value_parser(clap::value_parser!(u64)) | ||
) | ||
) | ||
.subcommand( | ||
Command::new("decrypt") | ||
.about("Decrypt data using Feistel cipher") | ||
.arg(Arg::new("key") | ||
.short('k') | ||
.long("key") | ||
.value_name("NUMBER") | ||
.help("Decryption key (optional, default is 12345)") | ||
.default_value("1234567890") | ||
.value_parser(clap::value_parser!(u64)) | ||
) | ||
) | ||
.get_matches(); | ||
|
||
let mut stdin: Box<dyn Read> = Box::new(io::stdin()); | ||
let mut stdout: Box<dyn Write> = Box::new(io::stdout()); | ||
|
||
if let Some(sub_matches) = matches.subcommand_matches("encrypt") { | ||
let key = sub_matches.get_one::<u64>("key").unwrap(); // Since default_value guarantees presence | ||
|
||
let _ = encrypt_stream(&mut stdin, &mut stdout, *key); | ||
} else if let Some(sub_matches) = matches.subcommand_matches("decrypt") { | ||
let key = sub_matches.get_one::<u64>("key").unwrap(); // Since default_value guarantees presence | ||
|
||
let _ = decrypt_stream(&mut stdin, &mut stdout, *key); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.