diff options
Diffstat (limited to 'src/crypt/cryptclasscaesar.cpp')
| -rw-r--r-- | src/crypt/cryptclasscaesar.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/crypt/cryptclasscaesar.cpp b/src/crypt/cryptclasscaesar.cpp index 23914a2..c1094ef 100644 --- a/src/crypt/cryptclasscaesar.cpp +++ b/src/crypt/cryptclasscaesar.cpp @@ -1,8 +1,12 @@ #include "cryptclasscaesar.h" +const int CryptClassCaesar::lowerBound = 0x30; +const int CryptClassCaesar::upperBound = 0x7A; + CryptClassCaesar::CryptClassCaesar() { - + oldKey = -1; + buildMap(); } CryptClassCaesar::~CryptClassCaesar() @@ -13,9 +17,39 @@ 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))); + + } +} |
