Friday, July 31, 2009

Just finished my c++ encryption program. Anyone want to check my code?

The source code for my encryption program is too big to fit here so i uploaded it as a text file to a file hosting site. The link is below. Its not strong encryption but its enough to be unreadable to the eye. There are 5 "encryption keys" that it has to choose from. Each file contains 254 five digit numbers it the format:


46578


65448


94814


61167


etc, etc.


I generated the files using another program I wrote. If you want that file a link to it is below with link to the keys also in case you want to try the program.


What do you think of my code? How can I improve it? I used basically all of my c++ knownledge in this program, based on that what should I learn next?


Encryptor: http://www.mediafire.com/?qxyk94zx2xr


Key maker: http://www.mediafire.com/?wzzhnykelgm


Keys: http://www.mediafire.com/?z4nyuxmgfd0


http://www.mediafire.com/?yd2myvsf3mu


http://www.mediafire.com/?tzyyyxfwu2k


http://www.mediafire.com/?ww4ttkzmtpf


http://www.mediafire.com/?qefwd2t1zjx





Thanks

Just finished my c++ encryption program. Anyone want to check my code?
(1)





ifstream KeyRead;


KeyRead.open(EncrKey);


if(!KeyRead.is_open())


{


cerr %26lt;%26lt; "File failed to open for read. Program ending." %26lt;%26lt; endl;


system("pause");


return 1;


};





A file can be open but still in a failed state. You should read up on failbit, eofbit, etc. A common way to check for a properly opened file would be more like





if(! KeyRead) because operator! () will return true if failbit or badbit are set.





(2)


char OutFile[15] = "Messagex.encr";


....


FileTestTries++;


OutFile[7] = FileTestTries+48;





This is goofy. Take the time to write a real (and genuinely useful) function that appends numbers properly to the end of a filename string. Using std::string this is brain dead simple and then just us string.c_str() if you need to dump to char* strings.





(3) int FileTestLoop - use bool with true/false.





(4) ofstream Write, KeyRead; -- *really* bad variable names. Outfile, ofile, something like that. You can easily be using a library some day that has some function named Write(). Not a show stopper but get in good habits now.





(5) for(int z=0; z%26lt;UserInCount; z++)





Minor but ++z is slightly faster so try to get into the habit of using it in loops like this.





It's late and I can't read any more but in general it looks like a good effort. Keep going and keep learning. You are off to a good start.


No comments:

Post a Comment