Better comments in rsa
This commit is contained in:
parent
70dcda61e8
commit
e1ece2358f
1 changed files with 4 additions and 2 deletions
6
rsa.c
6
rsa.c
|
@ -51,12 +51,13 @@ u64 mulmod(u64 a, u64 b, u64 m) {
|
|||
u64 result = 0;
|
||||
a %= m;
|
||||
|
||||
// Perform the multiplication bit by bit (binary multiplication)
|
||||
while (b > 0) {
|
||||
if (b & 1) {
|
||||
result = (result + a) % m;
|
||||
}
|
||||
a = (a * 2) % m; // Double a, keep within mod
|
||||
b >>= 1;
|
||||
a = (a * 2) % m; // Double a, keep it within the modulus
|
||||
b >>= 1; // Right shift b (divide by 2)
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -132,6 +133,7 @@ u64 mod_inverse(u64 a, u64 m) {
|
|||
u64 m0 = m;
|
||||
u64 y = 0, x = 1;
|
||||
|
||||
// Modular inverse does not exist when m is 1
|
||||
if (m == 1)
|
||||
return 0;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue