forked from vec21/RsaImplementation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_functions.cpp
38 lines (33 loc) · 986 Bytes
/
crypto_functions.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
#include "crypto_functions.h"
long long int encrypt(double message, int public_key, int n){
int e = public_key;
long long int encrpyted_text = 1;
while (e--) {
encrpyted_text *= message;
encrpyted_text %= n;
}
return encrpyted_text;
}
long long int decrypt(int encrpyted_text, int private_key, int n){
int d = private_key;
long long int decrypted = 1;
while (d--) {
decrypted *= encrpyted_text;
decrypted %= n;
}
return decrypted;
}
vector<int> encoder(string message, int public_key, int n){
vector<int> form;
// calling the encrypting function in encoding function
for (auto& letter : message)
form.push_back(encrypt((int)letter, public_key, n));
return form;
}
string decoder(vector<int> encoded, int private_key, int n){
string s;
// calling the decrypting function decoding function
for (auto& num : encoded)
s += decrypt(num, private_key, n);
return s;
}