print all keys in hex
This commit is contained in:
parent
37e3bbb70d
commit
c9e5bef814
1 changed files with 12 additions and 6 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::env;
|
||||
use std::{env, fmt::Display};
|
||||
|
||||
use rand::thread_rng;
|
||||
use num_bigint::{BigInt, BigUint, RandBigInt, ToBigInt};
|
||||
|
@ -11,6 +11,12 @@ struct Key {
|
|||
key: BigUint,
|
||||
}
|
||||
|
||||
impl Display for Key {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "Key {{ n: 0x{:X}, key: 0x{:X} }}", self.n, self.key)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct KeyPair {
|
||||
private: Key,
|
||||
|
@ -157,13 +163,13 @@ fn main() {
|
|||
let pair_b = generate_key_pair(&p1, &p2)
|
||||
.expect("failed to generate key pair b");
|
||||
|
||||
println!("private key A: {:?}", pair_a.private);
|
||||
println!("public key A: {:?}", pair_a.public);
|
||||
println!("private key B: {:?}", pair_b.private);
|
||||
println!("public key B: {:?}", pair_b.public);
|
||||
println!("private key A: {}", pair_a.private);
|
||||
println!("public key A: {}", pair_a.public);
|
||||
println!("private key B: {}", pair_b.private);
|
||||
println!("public key B: {}", pair_b.public);
|
||||
|
||||
let found_secret = find_private_key(&pair_a.public.n, &pair_a.public.key, &pair_a.private.key);
|
||||
println!("found_b: {:?}", found_secret);
|
||||
println!("found_b: (0x{:X}, 0x{:X})", found_secret.0, found_secret.1);
|
||||
if (&found_secret.0 == &p1 && &found_secret.1 == &p2)
|
||||
|| (&found_secret.0 == &p2 && &found_secret.1 == &p1) {
|
||||
println!("cracked B)");
|
||||
|
|
Loading…
Reference in a new issue