remove trailing spaces

This commit is contained in:
Francois Perrad 2017-10-17 20:51:19 +02:00
parent 4f6420bc02
commit 32e710ae07
4 changed files with 28 additions and 38 deletions

View File

@ -12,16 +12,16 @@ int main(void)
FILE *out; FILE *out;
clock_t t1; clock_t t1;
mp_digit z; mp_digit z;
mp_init_multi(&q, &p, NULL); mp_init_multi(&q, &p, NULL);
out = fopen("2kprime.1", "w"); out = fopen("2kprime.1", "w");
for (x = 0; x < (int)(sizeof(sizes) / sizeof(sizes[0])); x++) { for (x = 0; x < (int)(sizeof(sizes) / sizeof(sizes[0])); x++) {
top: top:
mp_2expt(&q, sizes[x]); mp_2expt(&q, sizes[x]);
mp_add_d(&q, 3, &q); mp_add_d(&q, 3, &q);
z = -3; z = -3;
t1 = clock(); t1 = clock();
for(;;) { for(;;) {
mp_sub_d(&q, 4, &q); mp_sub_d(&q, 4, &q);
@ -31,13 +31,13 @@ int main(void)
printf("No primes of size %d found\n", sizes[x]); printf("No primes of size %d found\n", sizes[x]);
break; break;
} }
if (clock() - t1 > CLOCKS_PER_SEC) { if (clock() - t1 > CLOCKS_PER_SEC) {
printf("."); fflush(stdout); printf("."); fflush(stdout);
// sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC); // sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC);
t1 = clock(); t1 = clock();
} }
/* quick test on q */ /* quick test on q */
mp_prime_is_prime(&q, 1, &y); mp_prime_is_prime(&q, 1, &y);
if (y == 0) { if (y == 0) {
@ -60,24 +60,19 @@ int main(void)
break; break;
} }
if (y == 0) { if (y == 0) {
++sizes[x]; ++sizes[x];
goto top; goto top;
} }
mp_toradix(&q, buf, 10); mp_toradix(&q, buf, 10);
printf("\n\n%d-bits (k = %lu) = %s\n", sizes[x], z, buf); printf("\n\n%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf); fflush(out); fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf); fflush(out);
} }
return 0; return 0;
} }
/* ref: $Format:%D$ */ /* ref: $Format:%D$ */
/* git commit: $Format:%H$ */ /* git commit: $Format:%H$ */

View File

@ -2,16 +2,17 @@
#include <tommath.h> #include <tommath.h>
int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT }; int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
int main(void) int main(void)
{ {
int res, x, y; int res, x, y;
char buf[4096]; char buf[4096];
FILE *out; FILE *out;
mp_int a, b; mp_int a, b;
mp_init(&a); mp_init(&a);
mp_init(&b); mp_init(&b);
out = fopen("drprimes.txt", "w"); out = fopen("drprimes.txt", "w");
for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) { for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
top: top:
@ -21,14 +22,14 @@ int main(void)
for (y = 1; y < sizes[x]; y++) { for (y = 1; y < sizes[x]; y++) {
a.dp[y] = MP_MASK; a.dp[y] = MP_MASK;
} }
/* make a DR modulus */ /* make a DR modulus */
a.dp[0] = -1; a.dp[0] = -1;
a.used = sizes[x]; a.used = sizes[x];
/* now loop */ /* now loop */
res = 0; res = 0;
for (;;) { for (;;) {
a.dp[0] += 4; a.dp[0] += 4;
if (a.dp[0] >= MP_MASK) break; if (a.dp[0] >= MP_MASK) break;
mp_prime_is_prime(&a, 1, &res); mp_prime_is_prime(&a, 1, &res);
@ -36,29 +37,28 @@ int main(void)
printf("."); fflush(stdout); printf("."); fflush(stdout);
mp_sub_d(&a, 1, &b); mp_sub_d(&a, 1, &b);
mp_div_2(&b, &b); mp_div_2(&b, &b);
mp_prime_is_prime(&b, 3, &res); mp_prime_is_prime(&b, 3, &res);
if (res == 0) continue; if (res == 0) continue;
mp_prime_is_prime(&a, 3, &res); mp_prime_is_prime(&a, 3, &res);
if (res == 1) break; if (res == 1) break;
} }
if (res != 1) { if (res != 1) {
printf("Error not DR modulus\n"); sizes[x] += 1; goto top; printf("Error not DR modulus\n"); sizes[x] += 1; goto top;
} else { } else {
mp_toradix(&a, buf, 10); mp_toradix(&a, buf, 10);
printf("\n\np == %s\n\n", buf); printf("\n\np == %s\n\n", buf);
fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf); fflush(out); fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf); fflush(out);
} }
} }
fclose(out); fclose(out);
mp_clear(&a); mp_clear(&a);
mp_clear(&b); mp_clear(&b);
return 0; return 0;
} }
/* ref: $Format:%D$ */ /* ref: $Format:%D$ */
/* git commit: $Format:%H$ */ /* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */ /* commit time: $Format:%ai$ */

View File

@ -1,4 +1,4 @@
/* Finds Mersenne primes using the Lucas-Lehmer test /* Finds Mersenne primes using the Lucas-Lehmer test
* *
* Tom St Denis, tomstdenis@gmail.com * Tom St Denis, tomstdenis@gmail.com
*/ */
@ -10,7 +10,7 @@ is_mersenne (long s, int *pp)
{ {
mp_int n, u; mp_int n, u;
int res, k; int res, k;
*pp = 0; *pp = 0;
if ((res = mp_init (&n)) != MP_OKAY) { if ((res = mp_init (&n)) != MP_OKAY) {

View File

@ -13,21 +13,21 @@ int main(void)
/* loop through various sizes */ /* loop through various sizes */
for (x = 4; x < 256; x++) { for (x = 4; x < 256; x++) {
printf("DIGITS == %3ld...", x); fflush(stdout); printf("DIGITS == %3ld...", x); fflush(stdout);
/* make up the odd modulus */ /* make up the odd modulus */
mp_rand(&modulus, x); mp_rand(&modulus, x);
modulus.dp[0] |= 1; modulus.dp[0] |= 1;
/* now find the R value */ /* now find the R value */
mp_montgomery_calc_normalization(&R, &modulus); mp_montgomery_calc_normalization(&R, &modulus);
mp_montgomery_setup(&modulus, &mp); mp_montgomery_setup(&modulus, &mp);
/* now run through a bunch tests */ /* now run through a bunch tests */
for (y = 0; y < 1000; y++) { for (y = 0; y < 1000; y++) {
mp_rand(&p, x/2); /* p = random */ mp_rand(&p, x/2); /* p = random */
mp_mul(&p, &R, &pp); /* pp = R * p */ mp_mul(&p, &R, &pp); /* pp = R * p */
mp_montgomery_reduce(&pp, &modulus, mp); mp_montgomery_reduce(&pp, &modulus, mp);
/* should be equal to p */ /* should be equal to p */
if (mp_cmp(&pp, &p) != MP_EQ) { if (mp_cmp(&pp, &p) != MP_EQ) {
printf("FAILURE!\n"); printf("FAILURE!\n");
@ -36,15 +36,10 @@ int main(void)
} }
printf("PASSED\n"); printf("PASSED\n");
} }
return 0; return 0;
} }
/* ref: $Format:%D$ */ /* ref: $Format:%D$ */
/* git commit: $Format:%H$ */ /* git commit: $Format:%H$ */
/* commit time: $Format:%ai$ */ /* commit time: $Format:%ai$ */