Tоshkеnt aхbоrоt tехnоlоgiyalari univеrsitеti kriptografiya 2 fanidan Loyiha ishi Bajardi


Download 202.03 Kb.
bet5/5
Sana18.06.2023
Hajmi202.03 Kb.
#1564941
1   2   3   4   5
Bog'liq
loyiha ishi

int result = min(fi, e);
while (result > 0) {
if (fi % result == 0 && e % result == 0) {
break;
}
result--;
}


// Return gcd of a and b
return result;
}
//////////////////////////////////////////////
int modulo(int x, int N){
return (x % N + N) % N;
}
void decimal_to_binary(int op1, int aOp[]){
int result, i = 0;
do{
result = op1 % 2;
op1 /= 2;
aOp[i] = result;
i++;
}while(op1 > 0);
}
int modular_exponentiation(int a, int b, int n){
int *bb;
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;
}
Download 202.03 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling