-
February 23rd, 2005 06:20 AM
#1
XOR Encryption Attempt
Okay, I've been following a thread on here where an AO user explained XOR to me (I forget who, sorry). But anyways, I wrote a simple C++ app that takes an input file, and XOR's it against the corresponding bytes of another file, and outputs it to an encrypted file...but my problem is, why doesn't it decrypt correctly...when I encrypted a TXT file with "hello", i got some weird ASCII characters...expected. But when I decrypted it, I got "helloou". I used the key "this is garbage.".
Code:
#include <iostream.h>
#include <fstream.h>
char inpath[50], keypath[50], outpath[50];
char buf1, buf2, buf3;
main()
{
cout << "Input file: ";
cin >> inpath;
cout << "File for key: ";
cin >> keypath;
cout << "Output file: ";
cin >> outpath;
ifstream infile(inpath);
ifstream keyfile(keypath);
ofstream outfile(outpath);
while(!infile.eof())
{
infile.get(buf1);
keyfile.get(buf2);
buf3 = buf1 ^ buf2;
outfile.put(buf3);
}
cout << "Process Complete!" << endl;
infile.close();
keyfile.close();
outfile.close();
system("pause");
}
Geek isn't just a four-letter word; it's a six-figure income.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
|
Bookmarks