From f72b2156cbd3ff9cc70c09e180bad7d95032c494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hatvani=20Tam=C3=A1s?= Date: Sun, 29 Mar 2026 17:07:54 +0200 Subject: [PATCH] working encryption with sample data --- main.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index faa1e72..5da717f 100644 --- a/main.c +++ b/main.c @@ -48,7 +48,7 @@ uint64_t quick_pow(uint64_t *d_binary, uint64_t a, uint64_t n, uint64_t length) } bool prime_test(uint64_t n, int a) { - printf("\n\nprime test: %ju\n", n); + // printf("\n\nprime test: %ju\n", n); // Miller Rabin prime test // choose a base: a, which should be a prime so that (n, a) = 1 // then do 2 rounds of tests provided the first one did not fail @@ -84,10 +84,10 @@ bool prime_test(uint64_t n, int a) { for (int i = 0; i <= r; i++) { if (first_qp_res == n - 1) { free(d_binary); - printf("true\n"); + // printf("true\n"); return true; } else if (first_qp_res < n - 2) { - printf("first_qp_res became smaller then n!!\n"); + // printf("first_qp_res became smaller then n!!\n"); break; } else { first_qp_res = (uint64_t)(((unsigned __int128)first_qp_res * first_qp_res) % n); @@ -108,9 +108,9 @@ void *prime_thread_worker(void *arg) { do { result_ptr->prime = rand64(); - printf("\nGenerating a new prime number (%p). Candidate: ", result_ptr); - printf("%ju", result_ptr->prime); - printf("\n"); + // printf("\nGenerating a new prime number (%p). Candidate: ", result_ptr); + // printf("%ju", result_ptr->prime); + // printf("\n"); } while (!prime_test(result_ptr->prime, result_ptr->base)); return NULL; @@ -157,6 +157,10 @@ euklidian_result_t euklidian_algorigthm_extended(unsigned __int128 a, unsigned _ } int main() { + uint64_t m = 0; + printf("give input for m: \n"); + scanf("%ju", &m); + srand(time(NULL)); uint64_t base = 2; @@ -172,6 +176,9 @@ int main() { printf("\n"); + p.prime = 11; + q.prime = 29; + unsigned __int128 n = p.prime * q.prime; print_uint128(n); printf("\n"); @@ -186,8 +193,17 @@ int main() { e = rand64(); } while (e <= 1 && e >= fi_n && prime_test(e, base)); - euklidian_result_t test = euklidian_algorigthm_extended(192, 11); - printf("test lnko: %ju\n", test.lnko); + e = 17; + + euklidian_result_t calc_d = euklidian_algorigthm_extended(fi_n, e); + __int128 d = calc_d.y; + + uint64_t length = 0; + uint64_t *nyenye = dec_to_bin(e, &length); + unsigned __int128 c = quick_pow(nyenye, m, n, length); + free(nyenye); + printf("\nc: "); + print_uint128(c); return 0; }