aboutsummaryrefslogtreecommitdiff
path: root/src/encryption_functions.cpp
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2020-05-22 01:18:24 +0300
committerCrystalwarrior <varsash@gmail.com>2020-05-22 01:18:24 +0300
commitc8e12558cdd3fd0769b81679ad09edf1f29b780f (patch)
tree7dae2225e574c3ee55d6b82a1d2f399db4ace5c0 /src/encryption_functions.cpp
parentdfac0652c8eb9bd48ceea7ae755e9c2f7e5cb1a2 (diff)
Clang-ify the code with this styling using Visual Studio Code:
{ BasedOnStyle: LLVM, UseTab: Never, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Stroustrup, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All } (this is the Visual Studio preset with only "BreakBeforeBraces" changed from Allman to Stroustrup)
Diffstat (limited to 'src/encryption_functions.cpp')
-rw-r--r--src/encryption_functions.cpp73
1 files changed, 34 insertions, 39 deletions
diff --git a/src/encryption_functions.cpp b/src/encryption_functions.cpp
index ffbe0cd..f26d4d4 100644
--- a/src/encryption_functions.cpp
+++ b/src/encryption_functions.cpp
@@ -4,60 +4,55 @@
QString fanta_encrypt(QString temp_input, unsigned int p_key)
{
- //using standard stdlib types is actually easier here because of implicit char<->int conversion
- //which in turn makes encryption arithmetic easier
+ //using standard stdlib types is actually easier here because of implicit char<->int conversion
+ //which in turn makes encryption arithmetic easier
- unsigned int key = p_key;
- unsigned int C1 = 53761;
- unsigned int C2 = 32618;
+ unsigned int key = p_key;
+ unsigned int C1 = 53761;
+ unsigned int C2 = 32618;
- QVector<uint_fast8_t> temp_result;
- std::string input = temp_input.toUtf8().constData();
+ QVector<uint_fast8_t> temp_result;
+ std::string input = temp_input.toUtf8().constData();
- for (unsigned int pos = 0 ; pos < input.size() ; ++pos)
- {
- uint_fast8_t output = input.at(pos) ^ (key >> 8) % 256;
- temp_result.append(output);
- key = (temp_result.at(pos) + key) * C1 + C2;
- }
+ for (unsigned int pos = 0; pos < input.size(); ++pos) {
+ uint_fast8_t output = input.at(pos) ^ (key >> 8) % 256;
+ temp_result.append(output);
+ key = (temp_result.at(pos) + key) * C1 + C2;
+ }
- std::string result = "";
+ std::string result = "";
- for (uint_fast8_t i_int : temp_result)
- {
- result += omni::int_to_hex(i_int);
- }
+ for (uint_fast8_t i_int : temp_result) {
+ result += omni::int_to_hex(i_int);
+ }
- QString final_result = QString::fromStdString(result);
+ QString final_result = QString::fromStdString(result);
- return final_result;
+ return final_result;
}
QString fanta_decrypt(QString temp_input, unsigned int key)
{
- std::string input = temp_input.toUtf8().constData();
+ std::string input = temp_input.toUtf8().constData();
- QVector<unsigned int> unhexed_vector;
+ QVector<unsigned int> unhexed_vector;
- for(unsigned int i=0; i< input.length(); i+=2)
- {
- std::string byte = input.substr(i,2);
- unsigned int hex_int = strtoul(byte.c_str(), nullptr, 16);
- unhexed_vector.append(hex_int);
- }
+ for (unsigned int i = 0; i < input.length(); i += 2) {
+ std::string byte = input.substr(i, 2);
+ unsigned int hex_int = strtoul(byte.c_str(), nullptr, 16);
+ unhexed_vector.append(hex_int);
+ }
- unsigned int C1 = 53761;
- unsigned int C2 = 32618;
+ unsigned int C1 = 53761;
+ unsigned int C2 = 32618;
- std::string result = "";
+ std::string result = "";
- for (int pos = 0 ; pos < unhexed_vector.size() ; ++pos)
- {
- unsigned char output = unhexed_vector.at(pos) ^ (key >> 8) % 256;
- result += output;
- key = (unhexed_vector.at(pos) + key) * C1 + C2;
- }
-
- return QString::fromStdString(result);
+ for (int pos = 0; pos < unhexed_vector.size(); ++pos) {
+ unsigned char output = unhexed_vector.at(pos) ^ (key >> 8) % 256;
+ result += output;
+ key = (unhexed_vector.at(pos) + key) * C1 + C2;
+ }
+ return QString::fromStdString(result);
}