forked from rahul22mrk/hackoctoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_AB_Balance.cpp
44 lines (43 loc) · 924 Bytes
/
A_AB_Balance.cpp
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
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
#include <math.h>
#include <vector>
#define int long long
using namespace std;
int gcd(int a, int h){
int temp;
while (1){
temp = a%h;
if (temp == 0)
return h;
a = h;
h = temp;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double p = 3;
double q = 7;
double n = p*q;
double e = 2;
double phi = (p-1)*(q-1);
while (e < phi){
if (gcd(e, phi)==1)
break;
else
e++;
}
int k = 2;
double d = (1 + (k*phi))/e;
double msg = 12;
cout <<"Message data = "<< msg;
double c = pow(msg, e);
c = fmod(c, n);
cout << "\nEncrypted data = " << c;
double m = pow(c, d);
m = fmod(m, n);
cout << "\nOriginal Message Sent = " << m;
return 0;
}