work in progress
This commit is contained in:
63
059/main.cpp
63
059/main.cpp
@@ -12,7 +12,7 @@ Your task has been made easy, as the encryption key consists of three lower case
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -20,5 +20,66 @@ int main(){
|
|||||||
|
|
||||||
cout << "Hello this is Patrick" << endl;
|
cout << "Hello this is Patrick" << endl;
|
||||||
|
|
||||||
|
ifstream inFile;
|
||||||
|
inFile.open("../txts/cipher.txt");
|
||||||
|
|
||||||
|
if(!inFile){
|
||||||
|
cerr << "Unable to open file: ../txts/cipher.txt" << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<unsigned char> encrypted;
|
||||||
|
while(true){
|
||||||
|
unsigned int current;
|
||||||
|
inFile >> current;
|
||||||
|
|
||||||
|
if(!inFile) break;
|
||||||
|
|
||||||
|
encrypted.push_back(current);
|
||||||
|
inFile.get();
|
||||||
|
}
|
||||||
|
encrypted.pop_back();
|
||||||
|
|
||||||
|
inFile.close();
|
||||||
|
|
||||||
|
for(unsigned char i = 'a'; i <= 'z'; ++i){
|
||||||
|
for(unsigned char j = 'a'; j <= 'z'; ++j){
|
||||||
|
for(unsigned char k = 'a'; k <= 'z'; ++k){
|
||||||
|
const unsigned char key[] = {i,j,k};
|
||||||
|
|
||||||
|
vector<unsigned char> decoded;
|
||||||
|
for(size_t pos = 0; pos < encrypted.size(); ++pos){
|
||||||
|
decoded.push_back(encrypted[pos] ^ key[pos % 3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid = true;
|
||||||
|
for(auto d : decoded){
|
||||||
|
valid = (d >= '0' && d <= '9');
|
||||||
|
valid |= (d >= 'a' && d <= 'z');
|
||||||
|
valid |= (d >= 'A' && d <= 'Z');
|
||||||
|
valid |= (d == ' ' || d == ',' || d == '.' || d == '?' || d == '!');
|
||||||
|
valid |= (d == ';' || d == ':' || d == '-' || d == '\'' || d == '(' || d == ')');
|
||||||
|
|
||||||
|
if(!valid){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!valid){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int asciiSum = 0;
|
||||||
|
for(auto d : decoded){
|
||||||
|
asciiSum += d;
|
||||||
|
cout << d;
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
cout << asciiSum << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user