commit 33de82aa1c7d67d54ca7224176618604d0eb2e98 Author: gbucchino Date: Mon Jun 15 10:31:58 2026 +0200 First commit diff --git a/common.h b/common.h new file mode 100644 index 0000000..5d28b90 --- /dev/null +++ b/common.h @@ -0,0 +1,21 @@ +#ifndef H_COMMON +#define H_COMMON + +struct prng{ + unsigned int p; + unsigned int q; + unsigned long long seed; + unsigned long long output; +} /*__attribute__((packed))*/; + +#define CSPRNG_VERS 0x1 + +/* Define all commandes */ +#define CSPRNG_CMD_GET_RNG 0x10 + +struct cmd{ + int version; + int cmd; +}; + +#endif diff --git a/exec.sh b/exec.sh new file mode 100755 index 0000000..fae34cc --- /dev/null +++ b/exec.sh @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +gcc -o main uart.c test_bbs.c main.c && ./main $1 diff --git a/main b/main new file mode 100755 index 0000000..73d8a7f Binary files /dev/null and b/main differ diff --git a/main.c b/main.c new file mode 100644 index 0000000..c97568d --- /dev/null +++ b/main.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#include +#include "common.h" +#include "uart.h" +#include "test_bbs.h" + + +static void bbs_module(){ + struct prng *s_prng = {0}; + int status = 0; + int fd; + int totalSuccess = 0; + int totalFailed = 0; + if ((fd = open("./reports", O_CREAT | O_RDWR, 00660)) < 0){ + printf("Failed to create the report\n"); + exit(-1); + } + + //printf("%d %d %llu %llu\n", s_prng->p, s_prng->q, s_prng->seed, s_prng->output); + for (int i = 0; i < 100; i++){ + char tmp[32]; + snprintf(tmp, 32, "*** Test: %d ***\n", i); + write(fd, "***************\n", 16); + write(fd, tmp, strlen(tmp)); + write(fd, "***************\n", 16); + status = send_uart(&s_prng); + + int result = test_bbs(fd, s_prng->p, s_prng->q, s_prng->seed, s_prng->output); + if (!result){ + printf("Test %d: success\n", i); + totalSuccess += 1; + } + else{ + printf("Test %d: failed\n", i); + totalFailed += 1; + } + memset(s_prng, 0, sizeof(struct prng)); + } + close(fd); + + printf("Summary: \n"); + printf("\tSuccess: %d\n", totalSuccess); + printf("\tFailed: %d\n", totalFailed); + +} +static void stats_module(){ + struct prng *s_prng = {0}; + int status = 0; + int fd; + + if ((fd = open("stats_stm32", O_CREAT | O_TRUNC | O_RDWR, 00760)) < 0){ + printf("Failed to open the file\n"); + perror("open()"); + exit(-1); + } + + for (size_t i = 0; i < 100; i++){ + status = send_uart(&s_prng); + //printf("%d %d %llu %llu\n", s_prng->p, s_prng->q, s_prng->seed, s_prng->output); + char str[32]; + memset(str, 0, 32); + snprintf(str, 32, "%llu", s_prng->output); + write(fd, str, strlen(str)); + write(fd, "\n", 1); + } + close(fd); + +} +int main(int argc, char *argv[]){ + if (argc < 2){ + printf("Please, specify the module to use: bbs or stats\n"); + return -1; + } + + if (strncmp(argv[1], "bbs", 5) == 0){ + bbs_module(); + } + else if (strncmp(argv[1], "stats", 5) == 0){ + stats_module(); + } + + return 0; +} diff --git a/monobit_test.py b/monobit_test.py new file mode 100644 index 0000000..af49d36 --- /dev/null +++ b/monobit_test.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +from math import erfc, sqrt + + +def monobit_test(bitseq: str): + """ + Frequency (Monobit) Test for a binary sequence. This tests count the number of '1' and '0' in a bit sequence and make a test statistics + + This test is based on the NIST SP 800-22 document, that describe how to perform tests for PRNG algorithms: + https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-22r1a.pdf + + Returns: + p_value (float): larger p-values suggest consistency with randomness. + """ + + n = len(bitseq) + if n == 0: + raise ValueError("bitseq must not be empty") + + if any(c not in "01" for c in bitseq): + raise ValueError("bitseq must contain only '0' and '1'") + + # Count ones and zeros via +/-1 sum + s = sum(1 if c == "1" else -1 for c in bitseq) + + # Compute the test statistic + sobs = abs(s) / sqrt(n) + + # Compute p-value, based on the Complementary Error Function (erfc) + p_value = erfc(sobs / sqrt(2)) + return p_value diff --git a/reports b/reports new file mode 100644 index 0000000..f79ce9a --- /dev/null +++ b/reports @@ -0,0 +1,2500 @@ +*************** +*** Test: 0 *** +*************** +Testing p (236412899) +p is a prime number. The test has succeeded. + +Testing q (1449535663) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 342688928293717037 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 18221263061575827332 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 1 *** +*************** +Testing p (509210311) +p is a prime number. The test has succeeded. + +Testing q (476028191) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 242398463183877401 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13957250907377810679 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 2 *** +*************** +Testing p (1475551283) +p is a prime number. The test has succeeded. + +Testing q (973725763) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1436782298884803929 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 6865706233718783231 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 3 *** +*************** +Testing p (2023325947) +p is a prime number. The test has succeeded. + +Testing q (314316287) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 635964299051798789 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 10078954275340087149 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 4 *** +*************** +Testing p (1943341627) +p is a prime number. The test has succeeded. + +Testing q (1858778459) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3612241554745612793 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13690091737832226816 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 5 *** +*************** +Testing p (883663439) +p is a prime number. The test has succeeded. + +Testing q (1669183259) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1474996218969167701 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 4897934848390581084 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 6 *** +*************** +Testing p (829659359) +p is a prime number. The test has succeeded. + +Testing q (737795039) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 612118559130120001 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 9708342100660668705 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 7 *** +*************** +Testing p (598116203) +p is a prime number. The test has succeeded. + +Testing q (480422083) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 287348232121310849 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8444825606750600696 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 8 *** +*************** +Testing p (389121727) +p is a prime number. The test has succeeded. + +Testing q (2061022343) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 801988573493746361 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 5543013947387472548 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 9 *** +*************** +Testing p (833714363) +p is a prime number. The test has succeeded. + +Testing q (1703304527) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1420069448722821301 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 9138049836158135531 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 10 *** +*************** +Testing p (496224247) +p is a prime number. The test has succeeded. + +Testing q (130793263) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 64902788444847961 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 18374214338710287740 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 11 *** +*************** +Testing p (1740405031) +p is a prime number. The test has succeeded. + +Testing q (738029147) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1284469640463438557 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 7810876928086368174 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 12 *** +*************** +Testing p (44917087) +p is a prime number. The test has succeeded. + +Testing q (697940339) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 31349446927672493 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 1895353598221782705 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 13 *** +*************** +Testing p (1604562983) +p is a prime number. The test has succeeded. + +Testing q (1090760423) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1750193798067221809 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8944367864858557632 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 14 *** +*************** +Testing p (505683883) +p is a prime number. The test has succeeded. + +Testing q (1343195731) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 679232432881103473 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 18205627915990556328 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 15 *** +*************** +Testing p (1940941207) +p is a prime number. The test has succeeded. + +Testing q (2143802371) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 4160994361538201797 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 16561374041047375085 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 16 *** +*************** +Testing p (73039579) +p is a prime number. The test has succeeded. + +Testing q (929390131) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 67882263894994849 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 12350787772269445851 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 17 *** +*************** +Testing p (2058806179) +p is a prime number. The test has succeeded. + +Testing q (1876829819) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3864028828288651601 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14180667775752636938 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 18 *** +*************** +Testing p (936363607) +p is a prime number. The test has succeeded. + +Testing q (917452691) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 859069310996616437 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3582984501271528915 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 19 *** +*************** +Testing p (361126399) +p is a prime number. The test has succeeded. + +Testing q (1792782263) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 647421002828260937 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 12332169021332278476 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 20 *** +*************** +Testing p (1079689183) +p is a prime number. The test has succeeded. + +Testing q (985668571) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1064215694131767493 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13560492014018831682 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 21 *** +*************** +Testing p (1035682027) +p is a prime number. The test has succeeded. + +Testing q (1930098931) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1998968773168613137 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3906848351319316606 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 22 *** +*************** +Testing p (824899903) +p is a prime number. The test has succeeded. + +Testing q (1681398239) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1386985244255470817 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14557306431021167913 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 23 *** +*************** +Testing p (1163289143) +p is a prime number. The test has succeeded. + +Testing q (1594586827) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1854965543419919261 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 2484405126603198764 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 24 *** +*************** +Testing p (1894794047) +p is a prime number. The test has succeeded. + +Testing q (24945611) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 47266795221577717 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 6059495291564529354 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 25 *** +*************** +Testing p (1467181271) +p is a prime number. The test has succeeded. + +Testing q (44866879) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 65827844557023209 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8654553304429526910 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 26 *** +*************** +Testing p (1338820367) +p is a prime number. The test has succeeded. + +Testing q (1282631579) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1717213281322569493 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 7147913949981697350 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 27 *** +*************** +Testing p (1746597271) +p is a prime number. The test has succeeded. + +Testing q (1585247107) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2768788270946844997 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 16181838028018357422 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 28 *** +*************** +Testing p (1300948127) +p is a prime number. The test has succeeded. + +Testing q (705927307) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 918374807839803989 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8484070686346314881 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 29 *** +*************** +Testing p (844058399) +p is a prime number. The test has succeeded. + +Testing q (1992087007) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1681437769797121793 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 7187971162089850913 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 30 *** +*************** +Testing p (1831414987) +p is a prime number. The test has succeeded. + +Testing q (980438999) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1795590676607878013 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 10454217091598886711 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 31 *** +*************** +Testing p (1359361943) +p is a prime number. The test has succeeded. + +Testing q (1250043499) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1699261559635158557 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14504299047120391621 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 32 *** +*************** +Testing p (1557534211) +p is a prime number. The test has succeeded. + +Testing q (1911110867) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2976620556366370937 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 18103630233951113806 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 33 *** +*************** +Testing p (2010006659) +p is a prime number. The test has succeeded. + +Testing q (633240719) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1272818061939947821 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 531468411713401329 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 34 *** +*************** +Testing p (509354411) +p is a prime number. The test has succeeded. + +Testing q (1388741891) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 707361807921331201 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 6875854204058067211 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 35 *** +*************** +Testing p (133816483) +p is a prime number. The test has succeeded. + +Testing q (255019) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 34125745678177 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8709779116396052894 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 36 *** +*************** +Testing p (1600299479) +p is a prime number. The test has succeeded. + +Testing q (1322456743) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2116326836822936897 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 17335844872505943714 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 37 *** +*************** +Testing p (1685845247) +p is a prime number. The test has succeeded. + +Testing q (1615330091) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2723196556248427477 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 17270511783420698942 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 38 *** +*************** +Testing p (1036469047) +p is a prime number. The test has succeeded. + +Testing q (251714839) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 260894639294088433 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13248841213242281227 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 39 *** +*************** +Testing p (1222819867) +p is a prime number. The test has succeeded. + +Testing q (376619983) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 460538397521602261 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 15655894579001667002 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 40 *** +*************** +Testing p (499075111) +p is a prime number. The test has succeeded. + +Testing q (1988107067) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 992214755142909437 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 9728526573701921550 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 41 *** +*************** +Testing p (1902851627) +p is a prime number. The test has succeeded. + +Testing q (1143104507) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2175158270975982889 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 4192700815998537260 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 42 *** +*************** +Testing p (137859191) +p is a prime number. The test has succeeded. + +Testing q (1562062283) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 215344642625993053 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14066580904650993101 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 43 *** +*************** +Testing p (434820299) +p is a prime number. The test has succeeded. + +Testing q (650992379) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 283064700883501321 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3664985608137763350 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 44 *** +*************** +Testing p (2075081947) +p is a prime number. The test has succeeded. + +Testing q (336699851) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 698679782367689897 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3886841404671927807 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 45 *** +*************** +Testing p (389034707) +p is a prime number. The test has succeeded. + +Testing q (1175087759) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 457149922021851613 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13858877241405196780 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 46 *** +*************** +Testing p (643553191) +p is a prime number. The test has succeeded. + +Testing q (2025171443) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1303305544464724613 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 15592578083494876955 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 47 *** +*************** +Testing p (1282664963) +p is a prime number. The test has succeeded. + +Testing q (735127559) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 942922363265015317 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3688753342384005117 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 48 *** +*************** +Testing p (560213939) +p is a prime number. The test has succeeded. + +Testing q (1895902559) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1062111040537569901 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 15174181351431781971 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 49 *** +*************** +Testing p (275933519) +p is a prime number. The test has succeeded. + +Testing q (1965771239) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 542422175526260041 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3194150269311944246 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 50 *** +*************** +Testing p (1748875067) +p is a prime number. The test has succeeded. + +Testing q (1485120583) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2597290359097204061 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 9077568236341217776 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 51 *** +*************** +Testing p (1931717387) +p is a prime number. The test has succeeded. + +Testing q (1567628903) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3028216008288836461 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13112189250376598279 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 52 *** +*************** +Testing p (1053979139) +p is a prime number. The test has succeeded. + +Testing q (1338468763) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1410718154405135057 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 220052402059302046 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 53 *** +*************** +Testing p (604086139) +p is a prime number. The test has succeeded. + +Testing q (1571995171) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 949620493376034769 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 15162797506037789927 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 54 *** +*************** +Testing p (134343959) +p is a prime number. The test has succeeded. + +Testing q (1738871723) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 233606911460971357 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 11315486520407574506 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 55 *** +*************** +Testing p (732975923) +p is a prime number. The test has succeeded. + +Testing q (689795251) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 505603310782741673 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14926393054527941861 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 56 *** +*************** +Testing p (1277549519) +p is a prime number. The test has succeeded. + +Testing q (1318089623) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1683924763862541337 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 346896177569636605 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 57 *** +*************** +Testing p (1250260511) +p is a prime number. The test has succeeded. + +Testing q (381851471) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 477413815258561681 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 4341140863472009864 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 58 *** +*************** +Testing p (1047915931) +p is a prime number. The test has succeeded. + +Testing q (236202751) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 247520625718926181 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 9869727488027642979 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 59 *** +*************** +Testing p (1904159683) +p is a prime number. The test has succeeded. + +Testing q (1519363231) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2893110208302815773 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 1409126215294505774 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 60 *** +*************** +Testing p (1189777679) +p is a prime number. The test has succeeded. + +Testing q (107165651) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 127503299515304029 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14102244630888894812 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 61 *** +*************** +Testing p (1732339043) +p is a prime number. The test has succeeded. + +Testing q (1700708491) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2946203719720914113 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 721517442545819259 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 62 *** +*************** +Testing p (214518527) +p is a prime number. The test has succeeded. + +Testing q (2117134823) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 454164643690365721 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 2333306839051001258 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 63 *** +*************** +Testing p (1759071163) +p is a prime number. The test has succeeded. + +Testing q (831323099) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1462356490586694137 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 846771185591157999 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 64 *** +*************** +Testing p (2145971123) +p is a prime number. The test has succeeded. + +Testing q (1422302347) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3052219764837125681 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 1193785140384230927 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 65 *** +*************** +Testing p (1070024779) +p is a prime number. The test has succeeded. + +Testing q (612958399) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 655880675426168821 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 4832707365888543349 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 66 *** +*************** +Testing p (2083545671) +p is a prime number. The test has succeeded. + +Testing q (98833519) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 205924150662146249 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 9595626696188051486 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 67 *** +*************** +Testing p (519049931) +p is a prime number. The test has succeeded. + +Testing q (1912804459) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 992841022460442329 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8219881918818937505 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 68 *** +*************** +Testing p (1873039439) +p is a prime number. The test has succeeded. + +Testing q (334215979) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 625999709810995781 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 7648211678046639943 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 69 *** +*************** +Testing p (89790131) +p is a prime number. The test has succeeded. + +Testing q (1166550719) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 104744741877154189 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 7507964773784511783 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 70 *** +*************** +Testing p (1910407127) +p is a prime number. The test has succeeded. + +Testing q (2103270119) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 4018102225343738113 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 12491172361638265631 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 71 *** +*************** +Testing p (1305943907) +p is a prime number. The test has succeeded. + +Testing q (86657107) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 113169320884897049 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14765805383615511492 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 72 *** +*************** +Testing p (2020486651) +p is a prime number. The test has succeeded. + +Testing q (1293783811) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2614072919405406961 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 12965449523947179495 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 73 *** +*************** +Testing p (1815178007) +p is a prime number. The test has succeeded. + +Testing q (2145702043) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3894831158028568301 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14584847574976847974 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 74 *** +*************** +Testing p (357108047) +p is a prime number. The test has succeeded. + +Testing q (1878915503) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 670975845754352641 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 10299579617128130803 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 75 *** +*************** +Testing p (33175543) +p is a prime number. The test has succeeded. + +Testing q (1270627903) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 42153770632976329 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 6737793881018070427 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 76 *** +*************** +Testing p (973561859) +p is a prime number. The test has succeeded. + +Testing q (1560063107) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1518817938608235913 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 4208352199125266249 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 77 *** +*************** +Testing p (1811610623) +p is a prime number. The test has succeeded. + +Testing q (1682361983) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3047784840134145409 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 17637965993085316975 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 78 *** +*************** +Testing p (1553287283) +p is a prime number. The test has succeeded. + +Testing q (514629539) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 799367518384852537 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 2924501982455716823 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 79 *** +*************** +Testing p (514956179) +p is a prime number. The test has succeeded. + +Testing q (1224255863) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 630438121328827477 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13174988278447465614 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 80 *** +*************** +Testing p (1151739227) +p is a prime number. The test has succeeded. + +Testing q (1461188039) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1682907582539505853 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 8913175046297800422 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 81 *** +*************** +Testing p (1189543711) +p is a prime number. The test has succeeded. + +Testing q (1527327667) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1816823020916152237 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3960980301570215022 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 82 *** +*************** +Testing p (1150081279) +p is a prime number. The test has succeeded. + +Testing q (694036243) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 798198090021794797 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14667569085532774799 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 83 *** +*************** +Testing p (556142567) +p is a prime number. The test has succeeded. + +Testing q (1776411883) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 987938264660923661 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 429925793044673998 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 84 *** +*************** +Testing p (2124047579) +p is a prime number. The test has succeeded. + +Testing q (1556588743) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3306268551067803197 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 11427729888976746492 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 85 *** +*************** +Testing p (378050831) +p is a prime number. The test has succeeded. + +Testing q (287727599) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 108775657903584769 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 5745548543371826615 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 86 *** +*************** +Testing p (2102144747) +p is a prime number. The test has succeeded. + +Testing q (1098970471) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2310195002720765837 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 1855028978865113892 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 87 *** +*************** +Testing p (1185362471) +p is a prime number. The test has succeeded. + +Testing q (1340659871) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1589167897459101241 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 4037621111696870432 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 88 *** +*************** +Testing p (2103408551) +p is a prime number. The test has succeeded. + +Testing q (1107077087) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 2328635411411970937 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 5151825807974328064 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 89 *** +*************** +Testing p (56436791) +p is a prime number. The test has succeeded. + +Testing q (816374831) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 46073575714807321 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 11783978799283575889 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 90 *** +*************** +Testing p (971882179) +p is a prime number. The test has succeeded. + +Testing q (2004013003) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1947664524099973537 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 13259462130999234807 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 91 *** +*************** +Testing p (478069847) +p is a prime number. The test has succeeded. + +Testing q (1562541803) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 747004120691314141 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14672021383316906053 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 92 *** +*************** +Testing p (1008141059) +p is a prime number. The test has succeeded. + +Testing q (381645479) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 384752477361622261 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 14882128711806518154 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 93 *** +*************** +Testing p (860030363) +p is a prime number. The test has succeeded. + +Testing q (796515527) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 685027537820946301 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 18389027253516702725 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 94 *** +*************** +Testing p (2049082183) +p is a prime number. The test has succeeded. + +Testing q (1830226159) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 3750283813267425097 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 7442009941150289404 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 95 *** +*************** +Testing p (1606198039) +p is a prime number. The test has succeeded. + +Testing q (138698411) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 222777115760616029 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 2924094235980787680 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 96 *** +*************** +Testing p (1708175407) +p is a prime number. The test has succeeded. + +Testing q (34620491) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 59137871304464837 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 10357424479518037642 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 97 *** +*************** +Testing p (875153399) +p is a prime number. The test has succeeded. + +Testing q (1223076671) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1070379705863254729 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 3415187296543127964 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 98 *** +*************** +Testing p (1743329587) +p is a prime number. The test has succeeded. + +Testing q (342527071) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 597137577222749677 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 5488241840447651504 +All tests has passed with success, the BBS algorithm works. + +*************** +*** Test: 99 *** +*************** +Testing p (2116664591) +p is a prime number. The test has succeeded. + +Testing q (631948951) +q is a prime number. The test has succeeded. + +Testing p congruent 3 modulo 4: +p is congruent 3 modulo 4. The test has succeeded. + +Testing q congruent 3 modulo 4: +q is congruent 3 modulo 4. The test has succeeded. + +n: 1337623967901294041 +Testing seed: +The seed test has passed. + +Testing gcd(seed, n) = 1: +gcd (seed, n) = 1. The has passed. + +Random number: 20861957979557168 +All tests has passed with success, the BBS algorithm works. + diff --git a/stats.py b/stats.py new file mode 100644 index 0000000..abdaecc --- /dev/null +++ b/stats.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser +from monobit_test import monobit_test +import matplotlib.pyplot as plt +from math import ceil + +parser = ArgumentParser(description="Stats") +parser.add_argument('-r', '--random', help='Random tests file') +args = parser.parse_args() + +if args.random is None: + print("You must specify the random test file") + exit(-1) + +data = None +with open(args.random, "r") as f: + data = f.readlines() + +x = list() +y = list() +i = 0 +totals = 0 +totalsAverage = dict() +for entry in data: + rand = int(entry.replace("\n", "")) + stats = monobit_test(bin(rand)[2:]) + totals += 1 + + # Je recupere juste le la value 0.x et je fais une moyenne + pvalue = str(stats)[0:3] + print(f"{rand}: {stats}: {pvalue}") + if pvalue not in totalsAverage: + totalsAverage[pvalue] = 0 + totalsAverage[pvalue] += 1 + + y.append(stats) # Get the maximum value + x.append(i) + i += 1 + +plt.figure(figsize=(10, 6)) +plt.bar(x, y, color='b') +plt.legend() +plt.show() + +x = list() +y = list() + +for entry in totalsAverage: + print(f"{entry}: {totalsAverage[entry]}") + x.append(entry) + y.append(totalsAverage[entry]) + +plt.figure(figsize=(10, 6)) +plt.bar(x, y, color='b') +plt.legend() +plt.show() diff --git a/stats_stm32 b/stats_stm32 new file mode 100755 index 0000000..dfa0c8c --- /dev/null +++ b/stats_stm32 @@ -0,0 +1,100 @@ +7143956609604881876 +6340670099509582644 +4333063528847840840 +5448018992326244964 +15481972836083048938 +3934379957052359253 +13152513937849694277 +2356684764018913277 +10058073522818051299 +15962996786604220673 +3942988100900722377 +10934163235194474014 +6599067683569711565 +7600599936755187680 +2405724269070210974 +11933146282488597358 +17258108528392989763 +12351616828616339343 +7704667635734705225 +16062004988962659328 +15732156458016953228 +14216936927168641841 +807742483240682402 +5475393661225397918 +2470077164568330899 +2964143963273089349 +14050280231004325874 +4794409721138831186 +5910878502533703035 +2891170948527933857 +16676943507448926252 +15462900432179282703 +15507435142494667442 +1677813438968503920 +9609228843553996341 +213089384859731146 +162552557704144544 +17597685084860323452 +9354024014538640154 +10077682396898715931 +1521103123871795714 +14552281874167193074 +7283173614658258684 +1919461955721824711 +8144830301161275821 +5855722041235443106 +5627126812385231187 +5265259268987312118 +13492757238726588169 +1815285119994321873 +2052410304797613645 +12319629048524816380 +10214415561913379519 +12055736959121855087 +4582950055558425767 +9620899185974271789 +14305339244738711898 +1332066268470078589 +16454992780571219535 +15994724435223301341 +17693254104230191035 +15179585275573828959 +17953669566852115206 +4850685134783252795 +5237775842428082632 +14605220744584287293 +17843194877515927408 +7145744655039698832 +6202054781425764022 +11162432947491746585 +17870660189937233770 +11846030029933436476 +17502604038329397571 +12900957045976627210 +2229699146690248944 +14464066371164287761 +15434304277948242038 +9948953088560674393 +18173717715545186381 +1961227897653913140 +12873961365795314954 +348868410274517725 +3542539594548864311 +6226010854009674672 +3970283356438754992 +8882086061509035049 +12550402613932570435 +6339289237626352931 +5101542075764696572 +1928582022423371495 +17470386898714041417 +2164929531054351313 +1781755032125269242 +9577013602259270449 +1097648098100462529 +1688066412708239185 +11765217448167006791 +2982376079644557045 +10305427686653677079 +786171841716133178 diff --git a/test_bbs.c b/test_bbs.c new file mode 100644 index 0000000..875849f --- /dev/null +++ b/test_bbs.c @@ -0,0 +1,162 @@ +#include +#include +#include +#include "test_bbs.h" + + +static int gcd(unsigned long a, unsigned long b){ + if (b == 0) + return a; + return gcd(b, a % b); +} + +static int isPrimeNumber(unsigned int x){ + for (int i = 0; i < SIEVES_LEN; i++){ + if (x % sieves[i] == 0) + return 0; + } + return 1; +} +/* + * This function check if the prime number x is congruent 3 modulo 4 + */ +static int isCongruent(unsigned int x){ + int res = x % 4; + if (res != 3) + return res; + + return -1; +} + + +/* + * This function convert a bit sequences store in the char * to unsigned long long + */ +static unsigned long long bitToUl(char *bits){ + unsigned long long o = 0; + for (int i = 0; i < strlen(bits); i++) + o = (o << 1) + bits[i] - '0'; + return o; +} +/* + * This function write to the report file + */ +static void writeToReport(int fd, const char *buf, ...){ + char str[BUF_FILE]; + va_list va; + va_start(va, buf); + //snprintf(str, BUF_FILE, buf, va); + vsnprintf(str, BUF_FILE, buf, va); + + write(fd, str, strlen(str)); + + va_end(va); +} +/* + * This function test the BBS algorithm received from the STM32 board + * Return 0 if succeed otherwise return -1 + */ +int test_bbs(int fd, unsigned int p, unsigned int q, unsigned long long seed, unsigned long long g){ + int res = 0; + /* + * Check if p and q are prime numbers + */ + writeToReport(fd, "Testing p (%d)\n", p); + + res = isPrimeNumber(p); + + if (!res){ + writeToReport(fd, "p is not a prime number. The has failed.\n"); + return -1; + } + writeToReport(fd, "p is a prime number. The test has succeeded.\n\n", q); + + writeToReport(fd, "Testing q (%d)\n", q); + res = isPrimeNumber(q); + + if (!res){ + writeToReport(fd, "q is not a prime number. The has failed.\n"); + return -1; + } + writeToReport(fd, "q is a prime number. The test has succeeded.\n\n", q); + + // Check if is congruent 3 modulo 4 + writeToReport(fd, "Testing p congruent 3 modulo 4:\n"); + res = isCongruent(p); + if (res >= 0){ + writeToReport( + fd, + "p is not congruent 3 modulo 4, but congruent %d. The test has failed.\n", + res + ); + return -1; + } + writeToReport( + fd, + "p is congruent 3 modulo 4. The test has succeeded.\n\n" + ); + + writeToReport(fd, "Testing q congruent 3 modulo 4:\n"); + res = isCongruent(q); + if (res >= 0){ + writeToReport(fd, + "q is not congruent 3 modulo 4, but congruent %d. The test has failed.\n", + res + ); + return -1; + } + writeToReport(fd, "q is congruent 3 modulo 4. The test has succeeded.\n\n"); + + // Check if n is correct + unsigned long long n = (unsigned long long)p * (unsigned long long)q; + writeToReport(fd, "n: %llu\n", n); + + // Check if seed is in the range 1 < seed < n - 1 + writeToReport(fd, "Testing seed:\n"); + if (seed < 1 || seed > n - 1){ + writeToReport( + fd, + "Seed (%llu) is not in the range 1 < seed < n - 1. " + "The test has failed\n", + seed + ); + return -1; + } + writeToReport(fd, "The seed test has passed.\n\n"); + + // Check if seed satisfy the equation: gcd(seed, n) = 1 + writeToReport(fd, "Testing gcd(seed, n) = 1:\n"); + int res_gcd = gcd(seed, n); + if (res_gcd != 1){ + writeToReport( + fd, + "the result of the gcd(seed, n) = %d. " + "The test has failed.\n", + res_gcd + ); + return -1; + } + writeToReport(fd, "gcd (seed, n) = %d. The has passed.\n\n", res_gcd); + + // Check least bit significant + unsigned long long tmp = (seed * seed) % n; + + char bits[ITER_BBS]; + memset(bits, 0, ITER_BBS); + int pos = 0; + for (size_t i = 1; i < ITER_BBS; i++){ + unsigned long long x = (tmp * tmp) % n; + bits[pos++] = (x & 1) + '0'; + tmp = x; + } + + /* We convert the bit sequence to unsigned long long */ + unsigned long long output = bitToUl(bits); + if (output != g){ + writeToReport(fd, "The random generated has failed.\n"); + return -1; + } + writeToReport(fd, "Random number: %llu\n", g); + writeToReport(fd, "All tests has passed with success, the BBS algorithm works.\n\n"); + return 0; +} diff --git a/test_bbs.h b/test_bbs.h new file mode 100644 index 0000000..0106d24 --- /dev/null +++ b/test_bbs.h @@ -0,0 +1,49 @@ +#ifndef H_TEST_BBS +#define H_TEST_BBS + + +#include +#include + +#define SIEVES_LEN 430 +#define ITER_BBS 100 +#define BUF_FILE 192 + +static int gcd(unsigned long, unsigned long); +static int isPrimeNumber(unsigned int); +static int isCongruent(unsigned int); +static int testGCD(unsigned long long, unsigned long long); +static unsigned long long bitToUl(char *); +static void writeToReport(int fd, const char *buf, ...); +int test_bbs(int, unsigned int, unsigned int, unsigned long long, unsigned long long); + +static int sieves[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, + 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, + 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, + 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, + 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, + 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, + 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, + 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, + 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, + 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, + 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, + 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, + 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, + 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, + 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, + 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, + 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, + 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, + 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, + 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, + 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, + 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, + 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, + 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, + 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, + 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, + 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999}; + + +#endif diff --git a/uart.c b/uart.c new file mode 100644 index 0000000..8eeac1c --- /dev/null +++ b/uart.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include "common.h" + +int set_serial_device(int fd){ + struct termios serial_cnf; + + if (tcgetattr(fd, &serial_cnf) < 0){ + printf("It's a TTY device\n"); + close(fd); + return -1; + } + + cfsetispeed(&serial_cnf, B115200); + cfsetospeed(&serial_cnf, B115200); + + serial_cnf.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + serial_cnf.c_iflag &= ~(IXON | IXOFF | IXANY); // Disable software flow control + serial_cnf.c_iflag &= ~(INLCR | ICRNL | IGNCR); + serial_cnf.c_cflag &= ~CRTSCTS; // Disable hardware control + + serial_cnf.c_cflag |= CREAD | CLOCAL; + + /* Set 8N1 (8 bits, no parity, 1 stop bit) */ + serial_cnf.c_cflag &= ~PARENB; // No parity + serial_cnf.c_cflag &= ~CSTOPB; // 1 stop bit + serial_cnf.c_cflag &= ~CSIZE; // clear data + serial_cnf.c_cflag |= CS8; // 8 data bits + serial_cnf.c_oflag &= ~OPOST; // Disable output processing + + serial_cnf.c_cc[VMIN] = 1; + serial_cnf.c_cc[VTIME] = 0; + + tcflush(fd, TCIFLUSH); + if (tcsetattr(fd, TCSANOW/*TCSAFLUSH*/, &serial_cnf) < 0) { + printf("Failed to serial_cnfure the serial port\n"); + close(fd); + return -1; + } + return 0; +} + + + +static unsigned short csum(unsigned short *buf, int nwords) { + unsigned long sum = 0; + while (nwords > 0) { + sum += *buf++; + nwords--; + } + sum = (sum >> 16) + (sum & 0xFFFF); + sum += (sum >> 16); + return (unsigned short)(~sum); +} + +int send_uart(struct prng **s_prng){ + int fd; + + if ((fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY)) < 0){ + printf("Failed to read the device\n"); + exit(-1); + } + + set_serial_device(fd); + + char buffer[sizeof(struct prng)]; + u_int8_t cmd = 1; + + //printf("Sending command...\n"); + size_t len = write(fd, &cmd, 1); + //printf("Data sent: %ld\n\n", len); + + // Read data + //printf("Receiving data...\n"); + int total_len = 0; + while (total_len < sizeof(struct prng)){ + len = read(fd, buffer + total_len, sizeof(struct prng)); + //printf("Len recv: %ld\n", len); + total_len += len; + } + *s_prng = (struct prng *)buffer; + close(fd); + return 0; +} diff --git a/uart.h b/uart.h new file mode 100644 index 0000000..8a59a25 --- /dev/null +++ b/uart.h @@ -0,0 +1,9 @@ +#ifndef H_UART +#define H_UART + +#include "common.h" + +int set_serial_device(int); +int send_uart(struct prng **); + +#endif