-
Notifications
You must be signed in to change notification settings - Fork 0
/
ritik.c
32 lines (31 loc) · 801 Bytes
/
ritik.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
#include <stdio.h>
long long int power(int a, int b, int mod)
{
long long int t;
if (b == 1)
return a;
t = power(a, b / 2, mod);
if (b % 2 == 0)
return (t * t) % mod;
else
return (((t * t) % mod) * a) % mod;
}
long int calculateKey(int a, int x, int n)
{
return power(a, x, n);
}
void main()
{
int n, g, x, a, y, b;
printf("Enter the value of n and g :");
scanf("%d%d", &n, &g);
printf("Enter the value of x for the first person : ");
scanf("%d", &x);
a = power(g, x, n);
printf("Enter the value of y for the second person : ");
scanf("%d", &y);
b = power(g, y, n);
printf("key for the first person is :%lld\n", power(b, x, n));
printf("key for the second person is :%lld\n", power(a, y, n));
getch();
}