-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptxor.cpp
43 lines (35 loc) · 1.39 KB
/
cryptxor.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
#include "cryptxor.h"
QVector<ushort> CryptXOR::crypt(const QVector<ushort> input) {
QVector<ushort> output = input;
for (int i = 0; i < input.size(); i++)
output[i] ^= m_key[i % (sizeof(m_key) / sizeof(char)) ];
return output;
}
QString CryptXOR::toString(QVector<ushort> vector){
QString result = "";
for (QVector<ushort>::iterator i = vector.begin();i != vector.end() ;++i)
result += uchar(*i);
return result;
}
QVector<ushort> CryptXOR::toVector(QString input) {
QVector<ushort> result;
for (QString::iterator i = input.begin(); i != input.end(); ++i)
result << (*i).cell();
return result;
}
CryptXOR::CryptXOR() {
m_key << 79 << 47 << 31 << 109 << 59 << 23 << 131071 << 19 << 3 << 199 << 7 << 5 << 37 << 71 << 43 << 7 << 11 << 73
<< 163 << 127 << 193 << 53 << 157 << 179 << 13 << 101 << 3 << 83 << 151 << 149 << 173 << 107 << 181 << 8191
<< 139 << 127 << 197 << 29 << 31 << 61 << 17 << 2147483647 << 524287 << 89 << 97 << 191 << 67 << 41 << 113
<< 131 << 137 << 103 << 167 << 1;
}
CryptXOR::CryptXOR(QVector<int> vector) {
m_key = vector;
}
QString CryptXOR::crypt(const QString input) {
QVector<ushort> vector = toVector(input);
return toString(crypt(vector));
}
bool CryptXOR::authenticate(QString tryPassword, QString encryptedPassword) {
return tryPassword == crypt(encryptedPassword);
}