From e1ece2358f72e2a1c7caa72d2f19b1c9a3498959 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 14 Feb 2025 06:09:54 +0100 Subject: [PATCH] Better comments in rsa --- rsa.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rsa.c b/rsa.c index ab9ec95..89a3069 100644 --- a/rsa.c +++ b/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;