-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
55 lines (50 loc) · 2.13 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "avl.c" // the trees.
#include "cint.c" // the integers.
#include "headers.h" // factor headers.
#include "utils.c" // utilities and front-end.
#include "quadratic.c" // quadratic sieve source.
#include "lanczos.c" // quadratic sieve Lanczos.
#include "testing.c" // quadratic sieve tests.
// Why this project use "cint" instead of GMP ?
// - Author search to understand the problematics of 64+ bit integers.
// - Original software goal was to factor 200-bit RSA in 30 seconds.
// - "cint" allow us to see what is sufficient to reach the goal.
static inline void fac_display_verbose(fac_cint **ans);
static inline void fac_display_help(char *name);
int main(int argc, char *argv[]){
cint N ;
fac_params config = {0};
char * n ; // the string to factor in base 10.
n = fac_fill_params(&config, argc, argv);
if (config.testing) fac_mini_tests(&config);
else if (config.help) fac_display_help(argv[0]);
else if (n) {
const int bits = 64 + 4 * (int) strlen(n);
cint_init_by_string(&N, bits, n, 10); // init the number as a cint.
fac_cint ** answer = c_factor(&N, &config); // execute the routine.
fac_display_verbose(answer); // print answer.
free(answer); // release answer memory.
free(N.mem); // release number memory.
} else
fputs("usage : primesieve [-h] [-s] [number]", stderr);
return 0 ;
}
static inline void fac_display_verbose(fac_cint ** ans) {
for(int i = 0; i < 100; ++i)
putchar(' ');
putchar('\r');
char * str = fac_answer_to_string(ans);
puts(str);
free(str);
}
static inline void fac_display_help(char *name) {
char * str = 1 + strrchr(name, '/');
if (str < name) str = 1 + strrchr(name, '\\');
if (str < name) str = name;
puts("=== [ Welcome to the factor function help ] === \n");
printf(" - use ./%s 123 to see the factors of 123\n", str);
printf(" - use ./%s -test=150 to see a one-minute 150-bit factorization test\n", str);
printf(" - use ./%s -limit=250 to define a limit of bit for the quadratic sieve, default to 220-bit\n", str);
printf(" - use ./%s -s [number] to not see the progress of quadratic sieve\n", str);
putchar('\n');
}