added some fixes
This commit is contained in:
parent
35ef48b721
commit
b436e25188
2 changed files with 20 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/target
|
||||
.idea
|
36
src/main.rs
36
src/main.rs
|
@ -1,5 +1,5 @@
|
|||
use colog;
|
||||
use log::{info, error};
|
||||
use log::{info, error, warn};
|
||||
use num::BigUint;
|
||||
use num_primes::Generator;
|
||||
use num_traits::cast::ToPrimitive;
|
||||
|
@ -19,13 +19,13 @@ impl RSA {
|
|||
let q = Generator::new_prime(key_size);
|
||||
|
||||
// Convert num-primes::BigUint to num-bigint::BigUint
|
||||
let p_bigint = num::BigUint::parse_bytes(p.to_string().as_bytes(), 10).unwrap();
|
||||
let q_bigint = num::BigUint::parse_bytes(q.to_string().as_bytes(), 10).unwrap();
|
||||
let p_bigint = BigUint::parse_bytes(p.to_string().as_bytes(), 10).unwrap();
|
||||
let q_bigint = BigUint::parse_bytes(q.to_string().as_bytes(), 10).unwrap();
|
||||
|
||||
let n = &p_bigint * &q_bigint;
|
||||
|
||||
let phi =
|
||||
(&p_bigint - num::BigUint::one()) * (&q_bigint - num::BigUint::one());
|
||||
(&p_bigint - BigUint::one()) * (&q_bigint - BigUint::one());
|
||||
|
||||
let e = num::BigUint::from(65537u32);
|
||||
|
||||
|
@ -67,11 +67,7 @@ impl RSA {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
colog::init();
|
||||
info!("RSA Encryption/Decryption");
|
||||
info!("Enter a message to encrypt:");
|
||||
|
||||
fn get_input() -> String {
|
||||
let mut message: String = "".to_string();
|
||||
match io::stdin().read_line(&mut message) {
|
||||
Ok(n) => match n {
|
||||
|
@ -81,18 +77,24 @@ fn main() {
|
|||
Err(error) => error!("error: {error}"),
|
||||
}
|
||||
|
||||
let mut rsa_size: String = "".to_string();
|
||||
message
|
||||
}
|
||||
|
||||
fn main() {
|
||||
colog::init();
|
||||
info!("RSA Encryption/Decryption");
|
||||
info!("Enter a message to encrypt:");
|
||||
let message: String = get_input();
|
||||
|
||||
info!("Enter the size of the RSA key pair (in bits):");
|
||||
match io::stdin().read_line(&mut rsa_size) {
|
||||
Ok(n) => match n {
|
||||
0 => info!("No input provided"),
|
||||
_ => info!("{} bytes read", n),
|
||||
},
|
||||
Err(error) => error!("error: {error}"),
|
||||
let mut rsa_size: usize = get_input().trim().parse::<usize>().unwrap();
|
||||
|
||||
if rsa_size < 1024 {
|
||||
warn!("Invalid RSA Size, Defaulting to 1024");
|
||||
rsa_size = 1024;
|
||||
}
|
||||
|
||||
let rsa = RSA::new(rsa_size.trim().parse().unwrap());
|
||||
let rsa = RSA::new(rsa_size);
|
||||
|
||||
info!("Original: {}", message.trim());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue