-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsacrack.old9.c
51 lines (41 loc) · 994 Bytes
/
rsacrack.old9.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
#define TRUE (1)
#define FALSE (0)
#include <stdio.h>
#include <gmp.h>
int main(int argc,char *argv[])
{
mpz_t composite,n,test_yp2,test_y,rem_y,test_xp2;
if(argc!=2)
{
fprintf(stderr,"usage rsacrack number\n");
return -1;
}
mpz_init_set_str(composite,argv[1],10);
mpz_init(n);
mpz_init(test_y);
mpz_init(rem_y);
mpz_init(test_xp2);
mpz_init(test_yp2);
for(mpz_init_set_ui(n,1);;mpz_add_ui(n,n,1))
{
mpz_mul(test_yp2,composite,n);
mpz_sqrtrem(test_y,rem_y,test_yp2);
if(mpz_cmp_ui(rem_y,0)!=0)
mpz_add_ui(test_y,test_y,1);
mpz_mul(test_yp2,test_y,test_y);
mpz_mod(test_xp2,test_yp2,composite);
if(mpz_perfect_square_p (test_xp2))
{
printf("Found perfect square ");
mpz_out_str(stdout,10,test_xp2);
printf("\n");
return(0);
}
if(test_xp2->_mp_size<=2)
{
printf("Found small xp2");
mpz_out_str(stdout,10,test_xp2);
printf("\n");
}
}
}