summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/crypt/cryptclasscaesar.cpp39
-rw-r--r--src/crypt/cryptclasscaesar.h5
-rw-r--r--src/crypt/cryptclassnullcipher.cpp4
3 files changed, 30 insertions, 18 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)));
}
}
diff --git a/src/crypt/cryptclasscaesar.h b/src/crypt/cryptclasscaesar.h
index d419232..45f7588 100644
--- a/src/crypt/cryptclasscaesar.h
+++ b/src/crypt/cryptclasscaesar.h
@@ -4,6 +4,7 @@
#include "cryptclassbase.h"
#include <QMap>
#include <QDebug>
+#include <QMessageBox>
class CryptClassCaesar : public CryptClassBase
{
@@ -22,8 +23,8 @@ private:
int oldKey;
QMap<char, char> substitutionsMap;
- const static int lowerBound;
- const static int upperBound;
+ const static int LOWERBOUND;
+ const static int UPPERBOUND;
};
#endif // CRYPTCLASSCAESAR_H
diff --git a/src/crypt/cryptclassnullcipher.cpp b/src/crypt/cryptclassnullcipher.cpp
index 29e9dd7..b4ed284 100644
--- a/src/crypt/cryptclassnullcipher.cpp
+++ b/src/crypt/cryptclassnullcipher.cpp
@@ -11,10 +11,6 @@ void CryptClassNullCipher::encrypt()
m_cryptText = m_clearText;
}
-
-
-
-
void CryptClassNullCipher::decrypt()
{
m_clearText = m_cryptText;