blob: c1094efede6effb4efcecddf4c233342ee6df6b4 (
plain)
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
|
#include "cryptclasscaesar.h"
const int CryptClassCaesar::lowerBound = 0x30;
const int CryptClassCaesar::upperBound = 0x7A;
CryptClassCaesar::CryptClassCaesar()
{
oldKey = -1;
buildMap();
}
CryptClassCaesar::~CryptClassCaesar()
{
}
void CryptClassCaesar::encrypt()
{
qDebug("CryptClassCaesar::encrypt");
buildMap();
QByteArray tmp = getClearText();
for (int i = 0; i < tmp.size(); i++)
{
tmp[i] = substitutionsMap[tmp[i]];
}
setCryptText((unsigned char*) tmp.data(), tmp.size());
}
void CryptClassCaesar::decrypt()
{
qDebug("CryptClassCaesar::encrypt");
}
void CryptClassCaesar::buildMap()
{
if (oldKey == getKey().toInt())
{
return;
}
oldKey = getKey().toInt();
substitutionsMap.clear();
for (int i = 0; i < (upperBound - lowerBound); i++)
{
substitutionsMap.insert((char)(lowerBound + i),
(char)(lowerBound + (i + oldKey) % (upperBound - lowerBound)));
}
}
|