summaryrefslogtreecommitdiffstats
path: root/src/crypt/cryptclasscaesar.cpp
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-04-01 22:37:26 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-04-01 22:37:26 +0200
commita343a48147917bec91fce25605b8746fad308b21 (patch)
tree8ce35c1c1bf0bb41dd6d21d42ca0b44fb5cd3f4e /src/crypt/cryptclasscaesar.cpp
parenta82f77cd33275262684a8beda8d3e12c6950d9be (diff)
downloadIT-Sicherheit-a343a48147917bec91fce25605b8746fad308b21.tar.gz
IT-Sicherheit-a343a48147917bec91fce25605b8746fad308b21.zip
Formatting and CryptClassCaesar::encrypt changes
Diffstat (limited to 'src/crypt/cryptclasscaesar.cpp')
-rw-r--r--src/crypt/cryptclasscaesar.cpp39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/crypt/cryptclasscaesar.cpp b/src/crypt/cryptclasscaesar.cpp
index c1094ef..d7c7827 100644
--- a/src/crypt/cryptclasscaesar.cpp
+++ b/src/crypt/cryptclasscaesar.cpp
@@ -1,7 +1,7 @@
#include "cryptclasscaesar.h"
-const int CryptClassCaesar::lowerBound = 0x30;
-const int CryptClassCaesar::upperBound = 0x7A;
+const int CryptClassCaesar::LOWERBOUND = 0x30;
+const int CryptClassCaesar::UPPERBOUND = 0x7A;
CryptClassCaesar::CryptClassCaesar()
{
@@ -19,26 +19,41 @@ void CryptClassCaesar::encrypt()
qDebug("CryptClassCaesar::encrypt");
buildMap();
- QByteArray tmp = getClearText();
+ m_cryptText.clear();
- for (int i = 0; i < tmp.size(); i++)
+ m_clearText = m_clearText.toUpper();
+ m_clearText.replace(QByteArray("Ä"), QByteArray("AE"));
+ m_clearText.replace(QByteArray("Ö"), QByteArray("OE"));
+ m_clearText.replace(QByteArray("Ü"), QByteArray("UE"));
+ m_clearText.replace(QByteArray("ß"), QByteArray("SS"));
+
+ for (int i = 0; i < m_clearText.size(); i++)
{
- tmp[i] = substitutionsMap[tmp[i]];
+ if (m_clearText[i] >= (char) LOWERBOUND && m_clearText[i] <= (char) UPPERBOUND)
+ {
+ m_cryptText.append(substitutionsMap[m_clearText[i]]);
+ }
}
- setCryptText((unsigned char*) tmp.data(), tmp.size());
-
}
void CryptClassCaesar::decrypt()
{
- qDebug("CryptClassCaesar::encrypt");
+ qDebug("CryptClassCaesar::decrypt");
}
void CryptClassCaesar::buildMap()
{
- if (oldKey == getKey().toInt())
+ bool ok = false;
+
+ if (oldKey == getKey().toInt(&ok))
{
+ if (ok == false)
+ {
+ QMessageBox::warning(NULL, "Key invalid",
+ "The key for Ceasar should only be a number.");
+ }
+
return;
}
@@ -46,10 +61,10 @@ void CryptClassCaesar::buildMap()
substitutionsMap.clear();
- for (int i = 0; i < (upperBound - lowerBound); i++)
+ for (int i = 0; i <= (UPPERBOUND - LOWERBOUND); i++)
{
- substitutionsMap.insert((char)(lowerBound + i),
- (char)(lowerBound + (i + oldKey) % (upperBound - lowerBound)));
+ substitutionsMap.insert((char)(LOWERBOUND + i),
+ (char)(LOWERBOUND + (i + oldKey) % (UPPERBOUND - LOWERBOUND)));
}
}