Getting back into Encryption
Yeh well I am getting back into encryption again. The first time I was just testing the waters, but this time I think I'm going to really make some head way. My first goal is to master XOR encryption.
I have created a sample program here which encrypts a message with a variable lengthed key. So now my simple brute force 1 key method won't work to crack it:
This code I am going to write over the next few weeks is meant to be cleaner and more concise then anything I've done before. I will be experimenting with incorporating unicode, and conversions between unicode and ASCI. Create techniques for cracking files, determining key length, using dictionaries, and a lot more. Like I said I hope to get atleast a decent understanding of some very rudimentary techniques.
I have created a sample program here which encrypts a message with a variable lengthed key. So now my simple brute force 1 key method won't work to crack it:
Code:
#include <iostream>
#include <fstream>
using namespace std;
void XOREncrypt(unsigned char* key, char* plaintext);
int main()
{
char plaintext[50];
unsigned char key[50];
for(;;)
{
cout<<"Plaintext file name: ";
cin >> plaintext;
cout<<"Encryption Key: ";
cin >> key;
XOREncrypt(key, plaintext);
}
return 1;
}
void XOREncrypt(unsigned char* key, char* plaintext)
{
fstream plainfile(plaintext, ios::in | ios::out | ios::binary);
fstream cipherfile("ciphertext.txt", ios::in | ios::out | ios::binary | ios::trunc);
int i = 0;
char ch;
while(plainfile)
{
plainfile.get(ch);
if(plainfile)
{
cipherfile.put(ch ^ key[i]);
i++;
if(!key[i]) i = 0;
}
}
cout<< "XOR Encryption finished. Check ciphertext.txt" << endl;
return;
}
