Let's XOR our example text file with the password "longpassword123." %'pl$=#-m:f49ne%!+#*"<#8(=w%#)#<8<s#>+pbml<(nz#8nf"'!zm@DF +u)!!s)?nP$(*-l+p8anw)>:/l9+p8cnp(+=g*>*ebm1y{5{uw Check out the full C program: #include <fstream> #include <stdio.h> #include <string.h> using namespace std; char srcfile[30], dstfile[30], key[255]; void main() { printf("Source file: "); scanf("%s",srcfile); printf("nDestination file: "); scanf("%s",dstfile); printf("nPassword (up to 255 chars): "); //the start of the key preparation process for (int i=0; i<255; i++) key[i]='§'; scanf("%s",key); int temp=0; char key_backup[255]; for (i=0;i<255;i++) { if (key[i]=='') break; temp=i; } strcpy(key_backup, key); for (i=temp; i>=0; i--) key[temp-i]=key[temp-i] & (~key_backup[i]); //key preparation process is done; we're ready to XOR! ifstream s(srcfile, ios::binary); ofstream d(dstfile, ios::binary); if (!s || !d) printf("nERROR: Couldn't open one of the files!"); i=0; char c; while ((s.read((char*)&c, sizeof(c)))) { if (key[i]=='') i=0; c=key[i] ^ c; d.write((char*)&c, sizeof(c)); i++; } s.close(); d.close(); printf("nAll done. "); } Once again, the download button below leads to an archive that contains the ready-to-run executable and source code of the above algorithm. Enjoy!
blog comments powered by Disqus |
|
|
|
|
|
|
|