From 66b499bc06f1a17821edb8e398fb990c29305745 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 3 May 2025 17:54:53 +0200 Subject: [PATCH 1/3] Formatting option for short if statements on a single line --- .clang-format | 1 + 1 file changed, 1 insertion(+) diff --git a/.clang-format b/.clang-format index 41e7b1a..ec06966 100644 --- a/.clang-format +++ b/.clang-format @@ -6,3 +6,4 @@ ColumnLimit: 80 # Wrap lines after 80 characters AllowShortLoopsOnASingleLine: true AlwaysBreakTemplateDeclarations: true BreakConstructorInitializers: BeforeComma +AllowShortIfStatementsOnASingleLine: true From 117adf9da135fbef893a4a62d0c411b74cc106a2 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 3 May 2025 17:54:58 +0200 Subject: [PATCH 2/3] Formatting --- rsa.c | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/rsa.c b/rsa.c index 89a3069..5a588eb 100644 --- a/rsa.c +++ b/rsa.c @@ -7,20 +7,16 @@ u64 gcd(u64 a, u64 b) { return extended_euclid(a, b, NULL, NULL); } u64 extended_euclid(u64 a, u64 b, u64 *x, u64 *y) { if (b == 0) { - if (x) - *x = 1; - if (y) - *y = 0; + if (x) *x = 1; + if (y) *y = 0; return a; } u64 x1, y1; u64 gcd = extended_euclid(b, a % b, &x1, &y1); - if (x) - *x = y1; - if (y) - *y = x1 - (a / b) * y1; + if (x) *x = y1; + if (y) *y = x1 - (a / b) * y1; return gcd; } @@ -56,8 +52,8 @@ u64 mulmod(u64 a, u64 b, u64 m) { if (b & 1) { result = (result + a) % m; } - a = (a * 2) % m; // Double a, keep it within the modulus - b >>= 1; // Right shift b (divide by 2) + a = (a * 2) % m; // Double a, keep it within the modulus + b >>= 1; // Right shift b (divide by 2) } return result; @@ -86,20 +82,17 @@ u64 gen_prime(u64 min, u64 max) { } bool is_prime(u64 n) { - if (n < 2) - return false; + if (n < 2) return false; for (int i = 2; i < n / 2 + 1; i++) { - if (n % i == 0) - return false; + if (n % i == 0) return false; } return true; } bool miller_rabin(u64 n, u64 k) { - if (n < 2) - return false; + if (n < 2) return false; u64 d = n - 1; u64 s = 0; @@ -113,17 +106,14 @@ bool miller_rabin(u64 n, u64 k) { u64 a = prand_range(2, n - 2); u64 x = modexp(a, d, n); - if (x == 1 || x == n - 1) - continue; + if (x == 1 || x == n - 1) continue; for (u64 r = 1; r < s; r++) { x = modexp(x, 2, n); - if (x == n - 1) - break; + if (x == n - 1) break; } - if (x != n - 1) - return false; // Not prime + if (x != n - 1) return false; // Not prime } return true; // Likely prime @@ -134,8 +124,7 @@ u64 mod_inverse(u64 a, u64 m) { u64 y = 0, x = 1; // Modular inverse does not exist when m is 1 - if (m == 1) - return 0; + if (m == 1) return 0; while (a > 1) { // q is quotient @@ -153,8 +142,7 @@ u64 mod_inverse(u64 a, u64 m) { } // Make x positive - if (x < 0) - x += m0; + if (x < 0) x += m0; return x; } From 88def95e47ace9fbb4215e91b420e74c7bdfd871 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 3 May 2025 17:55:02 +0200 Subject: [PATCH 3/3] Macro formatting --- assert.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assert.h b/assert.h index e56b318..e2fc017 100644 --- a/assert.h +++ b/assert.h @@ -3,7 +3,7 @@ #include #include -#define ASSERT(expr) \ +#define ASSERT(expr) \ do { \ if (!(expr)) { \ printf("ASSERTION FAILED: %s at %s:%d\n", #expr, __FILE__, \