cleaned up logs, added 128bit logger started working on second phase of rsa: keygen

This commit is contained in:
2026-03-20 14:43:45 +01:00
parent e0006f049c
commit cef7d5b5f9
2 changed files with 47 additions and 10 deletions

32
main.c
View File

@@ -4,6 +4,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "helper.c"
uint64_t *dec_to_bin(uint64_t d, uint64_t *length) {
uint64_t *binary_form = calloc(100, sizeof(uint64_t));
int index = 0;
@@ -15,11 +17,6 @@ uint64_t *dec_to_bin(uint64_t d, uint64_t *length) {
*length = index;
for (int i = index; i >= 0; i--) {
printf("%ju", binary_form[i]);
}
printf(" index: %d\n", index);
return binary_form;
}
@@ -66,10 +63,7 @@ bool prime_test(uint64_t n, int a) {
while (d % 2 == 0) {
d = d / 2;
S++;
printf("%ju ", d);
}
printf("S: %ju", S);
printf("\n");
uint64_t r = S - 1; // this stores the number of elements from 0 to S-1
@@ -81,7 +75,6 @@ bool prime_test(uint64_t n, int a) {
if ((first_qp_res = quick_pow(d_binary, a, n, length)) == 1) {
free(d_binary);
printf("true\n");
return true;
}
@@ -98,7 +91,6 @@ bool prime_test(uint64_t n, int a) {
}
}
printf("\nfalse\n\n");
free(d_binary);
return false;
}
@@ -111,5 +103,25 @@ int main() {
prime_test(661, 2);
prime_test(18446744073709551557UL, 2);
prime_test(18446744073709551533UL, 3);
uint64_t p = 11;
uint64_t q = 29;
// probably i should generate instead of asking the user to input
if (!prime_test(p, 2) || !prime_test(q, 2)) {
printf("given numbers were not primes");
return 1;
}
printf("\n");
unsigned __int128 n = p * q;
print_uint128(n);
printf("\n");
unsigned __int128 fi_n = (p - 1) * (q - 1);
print_uint128(fi_n);
printf("\n");
return 0;
}