int count = 0, c = 0, d = 1, i;
//bning ikkilik o'lchamini topish
count = (int) (log(b)/log(2)) + 1;
bb = (int *) malloc(sizeof(int*) * count);
decimal_to_binary(b, bb);
for (i = count - 1; i >= 0; i--) {
c = 2 * c;
d = (d*d) % n;
if (bb[i] == 1) {
c = c + 1;
d = (d*a) % n;
}
}
return d;
}
int get_d(int e, int fi){
EE ee;
ee = extended_euclid(e, fi);
return modulo(ee.x, fi);
}
int main(int argc, char* argv[]) {
int p, q, fi, n, e, d;
printf("p ning qiymatini kiriting: ");
scanf("%d", &p);
printf("q ning qiymatini kiriting: ");
scanf("%d", &q);
n = p*q;
fi = (p - 1) * (q - 1);
printf("e ning qiymatini kiriting: ");
scanf("%d", &e);
printf("fi(N): %d\n", fi);
if(gcd(fi, e) == 1){
d = get_d(e, fi);
printf("Maxfiy kalit: (d = %d)\n", d);
}
else{
printf("fi(N) va e o'zaro tub emas !!!");
}
return 0;
}
Dostları ilə paylaş: |