

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: RSA
incomplete
2: RSA vs. ECC
incomplete
3: RSA Key Generation
incomplete
4: Totient and E
incomplete
5: Modular Arithmetic
incomplete
6: Modular Arithmetic
incomplete
7: Encryption
incomplete
8: Multiplicative Inverse
incomplete
9: Private Key
incomplete
10: Decryption
incomplete
11: Encryption and Decryption Explained
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Aside from the message itself, all we need to perform encryption are the numbers e and n. Together, these are the public key.
The security of RSA relies on the fact that given n, it's really hard to guess what p and q (the private keys) were. Finding prime factors of very large numbers is computationally expensive. Trying to brute-force p and q would take more than trillions of years on modern hardware.
Remember, n = p * q.
The math for encrypting a message with RSA follows this formula:
ciphertext ≡ me (mod n)
We'll talk more about this math later, but for now, let's just implement it.
Complete the encrypt function.
func encrypt(m, e, n *big.Int) *big.Int
Return the result of me mod n. Use the .Exp method.