RSA key generation (with hardcoded small primes for simplicity)
()
| 48 | |
| 49 | // RSA key generation (with hardcoded small primes for simplicity) |
| 50 | fn generate_keys() -> (PublicKey, PrivateKey) { |
| 51 | let p = 61; |
| 52 | let q = 53; |
| 53 | let n = p * q; |
| 54 | let phi = (p - 1) * (q - 1); |
| 55 | let e = 17; |
| 56 | let d = mod_inv(e as i64, phi as i64) as u64; |
| 57 | |
| 58 | ( |
| 59 | PublicKey { e, n }, |
| 60 | PrivateKey { d, n }, |
| 61 | ) |
| 62 | } |
| 63 | |
| 64 | // RSA encryption: c = m^e mod n |
| 65 | fn encrypt(pub_key: &PublicKey, message: u64) -> u64 { |