943,769 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3185
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Sep 12th, 2009
0

Re: Why does this not work?

Thanks for your help.
I was wondering how I could use a algorithm library with this and which one to use.

Also the password part still does not work with my compiler I don't know it it worked with yours or not.
Reputation Points: 13
Solved Threads: 0
Light Poster
kernel>panic is offline Offline
44 posts
since Mar 2009
Sep 12th, 2009
0

Re: Why does this not work?

Click to Expand / Collapse  Quote originally posted by Kioti16 ...
Thanks for your help.
I was wondering how I could use a algorithm library with this and which one to use.

Also the password part still does not work with my compiler I don't know it it worked with yours or not.
It has nothing to do with the compiler. I commented your password code out and stuck it to the side since it was hard to follow and had nothing to do with the encryption as far as I could tell. It's in its own function. It's a trivial function now since its commented out. Uncomment it out if you like and rewrite it or whatever, but don't name a text file a dll file because all it does is confuses people.

Regarding algorithm, I don't know where you are thinking about using it, so I have no idea how to answer your question. There are all sorts of ways to improve the program. I suppose you could use algorithm possibly. I can't see, off the top of my head, where you would use it here. This program just replaces each character with a different character using a Caesar Cipher.

http://en.wikipedia.org/wiki/Caesar_cipher
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,373 posts
since Jan 2008
Sep 12th, 2009
0

Re: Why does this not work?

Ok I need to get a few things straight.
1 The reason there is a password is because it is a encryption program and if it didn't have a password someone could just use it and get my algorithm.

2 The reason it is a .dll file is for the exact reason you said to confuse people so they don't think it is a password file, and I am hoping once I get the password part working to make the password get encrypted.

3 I removed the comment tags already(I am not that stupid).

So what I need to do is:

1 Get the password protection working.

2 Make the password get encrypted, and set up the program so the password file cant just be deleted to make a new password.

3 Add an algirithum like acr4 to the encrypting and decrypting part.
Using a .h header file or some .lib file.

Sorry if I sound rude but I have only been doing c++ 3 years and am only a beginner getting frustrated.

Thank you very much.
Reputation Points: 13
Solved Threads: 0
Light Poster
kernel>panic is offline Offline
44 posts
since Mar 2009
Sep 12th, 2009
0

Re: Why does this not work?

Click to Expand / Collapse  Quote originally posted by Kioti16 ...
Ok I need to get a few things straight.
1 The reason there is a password is because it is a encryption program and if it didn't have a password someone could just use it and get my algorithm.

2 The reason it is a .dll file is for the exact reason you said to confuse people so they don't think it is a password file, and I am hoping once I get the password part working to make the password get encrypted.

3 I removed the comment tags already(I am not that stupid).

So what I need to do is:

1 Get the password protection working.

2 Make the password get encrypted, and set up the program so the password file cant just be deleted to make a new password.

3 Add an algirithum like acr4 to the encrypting and decrypting part.
Using a .h header file or some .lib file.

Sorry if I sound rude but I have only been doing c++ 3 years and am only a beginner getting frustrated.

Thank you very much.

There's a difference between confusing people who are trying to debug your code and confusing people who are trying to break your encryption. Get the program correct first, then you can obfuscate the code all you want. The obfuscation comes later. Anyone who had the source code could immediately see that you aren't loading a dll, despite the name. It's not going to trick anyone. Anyone who had the source code will also see that your key is hard-coded into the code. Don't confuse your "key" with the "password" stored in your text file. The password stored in the file has nothing to do with the encryption and decryption. It simply aborts the program if you don't have the right program. You also have the password file hard-coded in the file, so anyone with the source code knows immediately where to look. If you want security, you need to have the key and/or password read in as command line arguments. That way you can have the source code and you still won't know what the key is and where the pssword is stored. Anyone with the source code immediately can bypass the password anyway, so all you're left with is the key.

Regarding comments and names, normally the bad guy trying to revese engineer your program won't have the source code. They have the executable. You keep the source code close to the vest. All comments and names are stripped out of the executable anyway by the compiler. Comment all you want, name everything whatever you want and it's all irrelevant because you only release the executable.

A good encryption/decryption program/algorithm allows you to be completely transparent with the source code. Use an algorithm like Triple DES or AES and I can show you my source code and you still can't break it without the key. I was assuming that since this is a Caesar Cipher, this project was just for fun since no one actually uses that since it's way too easy to break.

Anyway, we have no way of knowing where you're coming from when you post if you don't tell us in the beginning. We're assuming that you're trying to create good, well-organized easy-to-follow code. As mentioned, if you want security, don't hard-code the key, password, or password file. Read them in as command line arguments or ask them to type it in. Or I suppose you could have a hash function and hash a password and hard-code the hash value into the program. A good hash formula won't allow you to go backwards from the hash to the password.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,373 posts
since Jan 2008
Sep 12th, 2009
0

Re: Why does this not work?

That sounds like great stuff.
But there is a problem I know what your talking about but I do not know how to put it in to code.
I know you don't have time to code this for me but could you give me some help?

My friend and I are competing we each have a encryption program and mine when we started was way ahead of his but now his is using all the stuff you are talking about he's using hash to store the password and no hard coded stuff.

But he has it so much easier, he is using Python.

What can I do?
Thanks.
Reputation Points: 13
Solved Threads: 0
Light Poster
kernel>panic is offline Offline
44 posts
since Mar 2009
Sep 12th, 2009
1

Re: Why does this not work?

Well, here's the program I posted earlier using command line arguments and adding the password stuff back in.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstdlib>
  5. using namespace std;
  6. string str;
  7.  
  8. void Message() {
  9. cout <<"*-----------------------------------*\n"
  10. <<"| Welcome to Crypto! |\n"
  11. <<"*-----------------------------------*\n";
  12. cout <<"Please type a command.\n"
  13. <<"Type \"m\" for the command menu.\n";
  14. return;
  15. }
  16.  
  17. void Encrypt(char *filename, int key)
  18. {
  19. system("CLS");
  20. ifstream in;
  21. ofstream out;
  22. char c;
  23. string fileContent;
  24.  
  25. in.open(filename);
  26.  
  27. if(in.fail()) {
  28. in.close();
  29. cout <<"Could not find file: "<<filename<<endl;
  30. system("PAUSE");
  31. system("CLS");
  32. Message();
  33. return;
  34. }
  35.  
  36. while(in.get(c))
  37. {
  38. fileContent += c;
  39. }
  40. in.close();
  41. for(size_t i = 0; i < fileContent.size(); i++)
  42. {
  43. fileContent[i] += key;
  44. }
  45. out.open(filename, ios::trunc);
  46. out << fileContent;
  47. out.close();
  48.  
  49. cout <<"FILE ENCRYPTED!\n";
  50. system("PAUSE");
  51. system("CLS");
  52. Message();
  53. }
  54.  
  55. void Decrypt(char *filename, int key)
  56. {
  57. system("CLS");
  58. ifstream in;
  59. ofstream out;
  60. char c;
  61. string fileContent;
  62.  
  63. in.open(filename);
  64.  
  65. if(in.fail())
  66. {
  67. in.close();
  68. cout <<"Could not find file: "<<filename<<endl;
  69. system("PAUSE");
  70. system("CLS");
  71. Message();
  72. return;
  73. }
  74.  
  75.  
  76.  
  77. while(in.get(c))
  78. {
  79. fileContent += c;
  80. for(size_t i = 0; i < fileContent.size(); i++)
  81. {
  82. fileContent[i] -= key;
  83. }
  84. }
  85.  
  86. in.close();
  87. out.open(filename, ios::trunc);
  88. out << fileContent;
  89. out.close();
  90.  
  91. cout <<"FILE DECRYPTED!\n";
  92. system("PAUSE");
  93. system("CLS");
  94. Message();
  95. }
  96.  
  97.  
  98. bool PasswordCheck (char* filename)
  99. {
  100. ifstream file_in(filename);
  101. char pass[80];
  102. char input_line[80];
  103.  
  104. if (! file_in)
  105. {
  106. file_in.close();
  107. return false;
  108. }
  109.  
  110. cout <<"Please type your password: ";
  111. cin.getline(pass, 80);
  112. while( file_in.getline(input_line, 80) )
  113. {
  114. if(strcmp(input_line, pass) == 0)
  115. return true;
  116. }
  117.  
  118. return false;
  119. }
  120.  
  121.  
  122. int main(int argc, char* argv[])
  123. {
  124. char filename[20];
  125. char comd;
  126.  
  127. int key = atoi (argv[1]);
  128.  
  129.  
  130. if (!PasswordCheck (argv[2]))
  131. {
  132. cout << "Bad password. Exiting program.\n";
  133. return 0;
  134. }
  135.  
  136.  
  137. system("CLS");
  138. cout <<"*-----------------------------------*\n"
  139. <<"| Welcome to Crypto! |\n"
  140. <<"*-----------------------------------*\n";
  141. cout <<"Please type a command.\n"
  142. <<"Type \"m\" for the command menu.\n";
  143.  
  144.  
  145. while(true)
  146. {
  147. cin >> comd;
  148. switch(comd)
  149. {
  150. case 'e' :
  151. system("CLS");
  152. cout <<"Please type name of file to encrypt (.txt): ";
  153. cin >> filename;
  154. Encrypt(filename, key);
  155. break;
  156.  
  157. case 'd' :
  158. system("CLS");
  159. cout <<"Please type name of file to encrypt (.txt): ";
  160. cin >> filename;
  161. Decrypt(filename, key);
  162. break;
  163.  
  164. case 'm' :
  165. cout <<"\n<COMMAND MENU>\n"
  166. <<"*--------------------*\n"
  167. <<"| e = 'Encrypt' |\n"
  168. <<"| d = 'Decrypt' |\n"
  169. <<"| m = 'Command Menu' |\n"
  170. <<"| q = 'Quit' |\n"
  171. <<"*--------------------*\n";
  172. break;
  173.  
  174. case 'q' :
  175. cout <<"\nThanks For Using 'Crypto'\n";
  176. system("PAUSE");
  177. return 0;
  178. break;
  179.  
  180. default :
  181. break;
  182. }
  183. }
  184. }

Compile it. Think of a key like 1, 2, 3, 4, whatever. Create a password file in a text editor called ""setpCS4.dll" or whatever you want to call it, then run it like this (assuming your program is called "encryptionProgram.exe" and your password file is "setupCS4.dll" and your key is 5):

encryptionProgram 5 setupCS4.dll
I left the decryption bug in there that I told you about earlier. Again, pick an easy file like "jklm" and an easy key like 1, then encypt it and see what it looks like. Now decrypt it and note the problem and what is happening. Line 127 and 130 are where the program grabs the command line arguments.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,373 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Command Line Arguments(CLA)
Next Thread in C++ Forum Timeline: 1540-0063 (S) The text "eventqueue_t" is unexpected.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC