-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrsa_encryptor.cpp
More file actions
73 lines (59 loc) · 1.6 KB
/
rsa_encryptor.cpp
File metadata and controls
73 lines (59 loc) · 1.6 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "rsa_encryptor.h"
RSAEncryptor::RSAEncryptor(const RSA &parent, const std::string &m) : RSA(parent) {
this->setM(m);
}
/**
* encryptMessage
*
*
* @param rsa
* @return std::vector<boost::multiprecision::cpp_int>
*/
std::vector<boost::multiprecision::cpp_int> RSAEncryptor::encryptMessage() {
// Convert every char in string to its ascii decimal value
std::vector<boost::multiprecision::cpp_int> asciiValues;
for (char c : this->getM()) {
// Convert each character to its ASCII value
asciiValues.push_back(static_cast<boost::multiprecision::cpp_int>(static_cast<unsigned char>(c)));
}
// Encrypt each ascii value
std::vector<boost::multiprecision::cpp_int> encryptedAsciiValues;
for (const boost::multiprecision::cpp_int& asciiValue: asciiValues)
// Compute the power of the message and the public exponent e modulo n
encryptedAsciiValues.emplace_back(boost::multiprecision::powm(asciiValue, this->getPublicExponentE(), this->getModulusN()));
return encryptedAsciiValues;
}
// Getters
/**
* getM
*
* Getter for M - message
*
* @return std::string
*/
std::string RSAEncryptor::getM() const { return M; }
/**
* getC
*
* Getter for C - encrypted message
*
* @return boost::multiprecision::cpp_int
*/
boost::multiprecision::cpp_int RSAEncryptor::getC() const { return C; }
// Setters
/**
* setM
*
* Setter for M - message
*
* @param m
*/
void RSAEncryptor::setM(std::string m) { M = m; }
/**
* setC
*
* Setter for C - encrypted message
*
* @param c
*/
void RSAEncryptor::setC(boost::multiprecision::cpp_int c) { C = c; }