|
@ -0,0 +1,73 @@ |
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
|
|
std::string load_file(std::string filename, size_t end_cut = 0) |
|
|
|
|
|
{ |
|
|
|
|
|
std::stringstream ret; |
|
|
|
|
|
std::ifstream file(filename); |
|
|
|
|
|
while(file.good()) |
|
|
|
|
|
{ |
|
|
|
|
|
ret<<(char)file.get(); |
|
|
|
|
|
} |
|
|
|
|
|
auto rret = ret.str(); |
|
|
|
|
|
rret.resize(rret.size()-end_cut); |
|
|
|
|
|
return rret; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv) |
|
|
|
|
|
{ |
|
|
|
|
|
std::vector<std::string> params; |
|
|
|
|
|
for(int i=0;i<argc;i++) |
|
|
|
|
|
{ |
|
|
|
|
|
params.push_back(std::string(argv[i])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(params.size()==2) |
|
|
|
|
|
{ |
|
|
|
|
|
auto ciphertext = load_file(params[1],4); |
|
|
|
|
|
int jumper=0; |
|
|
|
|
|
bool is_okay = true; |
|
|
|
|
|
do{ |
|
|
|
|
|
is_okay=true; |
|
|
|
|
|
for(size_t idx=0;idx<ciphertext.size();idx++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!isgraph((char)(ciphertext[idx]-jumper+idx))) |
|
|
|
|
|
{ |
|
|
|
|
|
is_okay=false; |
|
|
|
|
|
jumper++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}while((!is_okay) && jumper<=256); |
|
|
|
|
|
if(is_okay) |
|
|
|
|
|
{ |
|
|
|
|
|
for(size_t idx=0;idx<ciphertext.size();idx++) |
|
|
|
|
|
{ |
|
|
|
|
|
std::cout<<(char)(ciphertext[idx]-jumper+idx); |
|
|
|
|
|
} |
|
|
|
|
|
}else{ |
|
|
|
|
|
std::cout<<"Unable to find a valid representation"<<std::endl; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if(params.size()==3) |
|
|
|
|
|
{ |
|
|
|
|
|
auto ciphertext = load_file(params[1],4); |
|
|
|
|
|
auto zeroed = load_file(params[2],4); |
|
|
|
|
|
assert(ciphertext.size()==zeroed.size()); |
|
|
|
|
|
for(size_t idx=0;idx<ciphertext.size();idx++) |
|
|
|
|
|
{ |
|
|
|
|
|
std::cout<<(char)(ciphertext[idx]-zeroed[idx]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
std::cout<< |
|
|
|
|
|
"codebreak 0.1.0\n" |
|
|
|
|
|
"usage:\n" |
|
|
|
|
|
"codebreak encrypted_file [0ed_ciphertext]" |
|
|
|
|
|
<<std::endl; |
|
|
|
|
|
} |
|
|
|
|
|
} |