TextCracker v.1.0

Posts 1–6 of 6 · Page 1 of 1
TextCracker v.1.0
Well I think I've done the the most I can do with XOR, and it's time to move on to other encryptions. On realizing how pitifully weak XOR encryption are I have decided to release the full source for my TextCracker as well as the executable. Its time to move on to more advanced encryptions....

Full Source:
[PHP]
#include <iostream>
#include <fstream>
using namespace std;

void start();
void XOR_char_crack(char* str, bool brute);
bool encrypt(char *src, char *dest, char k);
bool filterStrings(unsigned char* str, int l);
bool brute = true;
int filter = 0;


int main()
{
start();
system("pause");
return 0;
}

void start(){
char filename1[50] = "";
char filename2[50] = "";
char key;
char choice;
char ch;
cout << "Would you like to crack a text file?\n" << endl;
cout << "q.) Quit\n";
cout << "1.) XOR ASCII Crack\n";
cout << "2.) Decrypt XOR ASCII with key\n";
cout << "3.) XOR Encrypt your own file\n";
cin >> choice;

switch(choice){
case 'q':
break;

case '1':
system("cls");
cout <<"Type the name of the file you want cracked: ";
cin >> filename1;

while(true)
{
cout <<"Try realistic keys? (keyboard characters) (y/n)\n";
cin >> ch;
if(ch == 'y' || ch =='Y'){brute = false; break;}
if(ch =='n' || ch =='N'){brute = true; break;}
else cout<<"Not a valid choice.\n";
}

for(bool exit = false; !exit; )
{
cout <<"Would you like to enable a filter? (y/n)";
cin >> ch;

switch(ch){
case 'y':
cout << "Select Filtration Level: \n";
cout << "1. Filter extended ASCII characters\n";
cout << "2. Target character strings only. (strings of letters)\n";
cin >> filter;
exit = true;
cout<<"\nWARNING: These results have been filtered.\n\n";
break;
case 'n':
filter = 0;
exit = true;
break;
default:
cout <<"Invalid option. Enter \'y\' for yes or \'n\' for no.\n";
break;
}
}
XOR_char_crack(filename1, brute);
system("pause");
system("cls");
start();
break;
case '2':
system("cls");
cout <<"Type the name of the file you want the decrypter to read: ";
cin >> filename1;
cout <<"Type the name of the file you would like to send the decrypted message to: ";
cin >> filename2;
cout << "What key is the message encrypted with?" << endl;
cin >> key;
if(encrypt(filename1, filename2, key)) cout <<"File successfully decrypted.\n";
else cout << "Decyprtion failed.\n";
system("pause");
system("cls");
start();
break;

case '3':
system("cls");
cout <<"Type the name of the file you want the encrypter to read: ";
cin >> filename1;
cout <<"Type the name of the file you would like to send the encrypted message to: ";
cin >> filename2;
cout << "What key would you like to encrypt this message in?" << endl;
cin >> key;
if(encrypt(filename1,filename2, key))cout <<"File successfully encrypted.\n";
else cout <<"Encryption failed.\n";
system("pause");
system("cls");
start();
break;

default:
system("cls");
start();
break;
}
}

void XOR_char_crack(char* str, bool brute)
{
fstream file(str, ios::binary | ios::in | ios:ut);
fstream dump("dump.txt", ios::in | ios:ut | ios::trunc);

if(!file)
{
cout << "ERROR. Cannot open specified file. File must be in same directory as decryptor.\n";
return;
}
if(!dump)
{
cout << "ERROR. Cannot open dump.txt file.\n";
return;
}

char ch;
unsigned char temp[20] = "";
unsigned char k = 0;
if(!brute)k=32;
do
{
for(int i=0; str[i]; i++)
{
file.get(ch);
temp[i] = (ch ^ k);
}
file.seekg(ios::beg);
if(filter)
{
if(filterStrings(temp, filter))
{
dump << "Key of: " << k << " Produces: " << temp << endl << endl;
cout << "Key of: " << k << " Produces: " << temp << endl << endl;
}
}
k++;
if(!brute && k> 126) break;
}while(k != 0);

return;
}

bool encrypt(char *src, char *dest, char k)
{
fstream ifile(src, ios::binary | ios::in | ios:ut);
fstream efile(dest, ios::binary | ios::in | ios:ut | ios::trunc);
unsigned char key = k;
char ch;

if(!ifile)
{
cout << "ERROR. Cannot open first file.\n";
return 0;
}
if(!efile)
{
cout << "ERROR. Cannot open second file.\n";
return 0;
}
cout << "Contents of file1:\n\n";
while(ifile)
{
ifile.get(ch);
if(ifile) cout << ch;
efile.put(ch^key);
}
cout << endl << endl;
cout << "The first file has been encrypted with a key of '" << key <<"' and saved to the second file.\n";
cout << "Encrypted message: \n\n";
efile.seekg(ios::beg);
while(efile)
{
efile.get(ch);
if(efile)cout << ch;
}
cout<< endl;
ifile.close();
efile.close();
cout << endl;
return 1;
}

bool filterStrings(unsigned char* str, int l)
{
int count = 0;
if (l == 0) return true;
else if (l == 1)
{


for(int i = 0; str[i]; i++)
{
if(str[i] >= 32 && str[i] <= 127)count++;
else count = 0;
if(count >= 3)return true;
}
}
else
{
for(int i = 0; str[i]; i++)
{
if(str[i] >= 65 && str[i] <= 122)count++;
else count = 0;
if(count >= 3)return true;
}
}
}

[/PHP]
Sorry I didn't comment my code.

I guess you guys can play around with it if you want... I know you get hours of fun from typing into a console.... =/
TextCracker v.1.0.rarattachment deleted · 8 downloads before removal
I'm sorry but what should this do? text Cracker for what? does it encrypt passwords? =P Sry idk what this should do! Teach me xD
Quote Originally Posted by bakycar View Post
I'm sorry but what should this do? text Cracker for what? does it encrypt passwords? =P Sry idk what this should do! Teach me xD
lol it is clearly in the visible in the code...

Code:
void start(){
    char filename1[50] = "";
    char filename2[50] = "";
    char key;
    char choice;
    char ch;
    cout << "Would you like to crack a text file?\n" << endl;
    cout << "q.) Quit\n";
    cout << "1.) XOR ASCII Crack\n";
    cout << "2.) Decrypt XOR ASCII with key\n";
    cout << "3.) XOR Encrypt your own file\n";
    cin >> choice;
Quote Originally Posted by lalakijilp View Post
lol it is clearly in the visible in the code...

Code:
void start(){
    char filename1[50] = "";
    char filename2[50] = "";
    char key;
    char choice;
    char ch;
    cout << "Would you like to crack a text file?\n" << endl;
    cout << "q.) Quit\n";
    cout << "1.) XOR ASCII Crack\n";
    cout << "2.) Decrypt XOR ASCII with key\n";
    cout << "3.) XOR Encrypt your own file\n";
    cin >> choice;
And what do you need to crack a .txt file for? I dont get it..
Quote Originally Posted by bakycar View Post
And what do you need to crack a .txt file for? I dont get it..
Well if a text file was XOR encrypted with a key, this would help you find that key. It can also Encrypt any text file you want with a XOR encryption as well as Decrypt messages that people sent you encrypted with XOR. As for what you would want to do with it that is really up to you. Its really just there to learn by.

I also added some filters that you can use to narrow down your results and added a common key search that will only try keys located on the keyboard... not that brute force really matters with XOR.... On my next ecryptor, which will use a rotation in conjunction with the XOR I will include a secondary filter that will examine possible matches more closely, maybe try to add a dictionary filter... and so on. Guess this will be like my little pet project, and will become more advanced as time goes on. I'm really just doing it because it keeps up my C++ skill while learning ASM.
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

Talk with us