Guest User

crypto

a guest
Jan 6th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. #include <iostream> // <- standardowe wejscie wyjscie
  2. #include <fstream>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. int main(int argc, char ** argv)//argc to liczba calkowita informujaca o tym ile argumentow zostalo przekazanych. PYTANIE!
  7. {
  8. cout<<"**************************************************************"<< endl;
  9. cout << "*\t\t ******************* \t\t *"<< endl;
  10. cout << "*\t\t * CRYPTO WKR 2017 * \t\t *"<< endl;
  11. cout << "*\t\t ******************* \t\t *"<< endl;
  12. cout<<"**************************************************************"<< endl;
  13.  
  14. if (argc == 2) // pierwszym parametrem jest nazwa programu
  15. {
  16. if( argv[1][0]=='-' && argv[1][1]=='h' && strlen(argv[1]) == 2 || std::string(argv[1])=="--help")
  17. {
  18. cout<<"* Prosze uzupelnic pole pomocy w miare rozwoju aplikacji. *"<< endl;
  19. cout<<"* W chwili obecnej program zbudowany jest jako szablon, *"<< endl;
  20. cout<<"* ktory powinien byc uzupelniany o kolejne algorytmy *"<< endl;
  21. cout<<"* kryptograficzne. Powodzenia. *"<< endl;
  22. cout<<"**************************************************************"<< endl;
  23. cout<<"* Dolecowy program powinien dzialac w nastepujacy sposob: *"<< endl;
  24. cout<<"* W wierszu polecen wywolujemy nazwe programu i parametry *"<< endl;
  25. cout<<"* programu, gdzie: *"<< endl;
  26. cout<<"* -bc szyfr blokowy w trybie c/d (szyfrowanie/deszyfrowanie);*"<< endl;
  27. cout<<"* -sc szyfr strumieniowy w trybie c/d *"<< endl;
  28. cout<<"* (szyfrowanie/deszyfrowanie); *"<< endl;
  29. cout<<"* -hf funkcja skrotu bez trybow; *"<< endl;
  30. cout<<"* -ac szyfr asymetryczny w trybie c/d *"<< endl;
  31. cout<<"* (szyfrowanie/deszyfrowanie); *"<< endl;
  32. cout<<"* -i sciezka pliku wejsciowego (tekstu jawnego, *"<< endl;
  33. cout<<"* wiadomosci); *"<< endl;
  34. cout<<"* -o sciezka pliku wyjsciowego (tekstu zaszyfrowanego, *"<< endl;
  35. cout<<"* skrotu); *"<< endl;
  36. cout<<"* -k sciezka klucza; *"<< endl;
  37. cout<<"* -h, --help to pomoc (wystepuje bez innych parametrow); *"<< endl;
  38. cout<<"**************************************************************"<< endl;
  39. cout<<"*Przyklad: *"<< endl;
  40. cout<<"*crypto.exe -bc d -i C:\\in.txt -o D:\\out.txt -k C:\\key.txt *"<< endl;
  41. cout<<"**************************************************************"<< endl;
  42. cout<<"* Porgram operuje na plikach tekstowych. *"<< endl;
  43. cout<<"**************************************************************"<< endl;
  44. }
  45. else
  46. {
  47. cout<< argc<<endl;
  48. cout<<"blednie wprowadzone parametr/parametry. (Blad: E001)" <<endl;
  49. }
  50. }
  51. else
  52. { fstream input;
  53. fstream output;
  54. fstream key;
  55. bool flaga_algorytmu=false;
  56. int flaga_poprawnosci_parametrow=0;
  57. int wybor_algorytmu=0;
  58. for (int i = 0; i < argc; i++)
  59. {
  60.  
  61. if (argv[i][0] == '-')
  62. {
  63. if(argc==i+1 || argv[i+1][0] == '-')
  64. {
  65. if(std::string(argv[i])=="-hf")
  66. {
  67. cout << argv[i] << ":";
  68. cout << "Ok, wyznaczenie skrotu do dzialania nie potrzebuje parametru ani pliku klucza;" << endl;
  69. }
  70. else if(std::string(argv[i])=="-bc")
  71. {
  72. flaga_algorytmu=true;
  73. cout << argv[i] << ": ";
  74. cout << "Nie podano parametru pracy szyfru blokowego;" <<endl;
  75. }
  76. else if(std::string(argv[i])=="-sc")
  77. {
  78. flaga_algorytmu=true;
  79. cout << argv[i] << ": ";
  80. cout << "Nie podano parametru pracy szyfru strumieniowego;" <<endl;
  81. }
  82. else if(std::string(argv[i])=="-ac")
  83. {
  84. flaga_algorytmu=true;
  85. cout << argv[i] << ": ";
  86. cout << "Nie podano parametru pracy szyfru asymetrycznego;" <<endl;
  87. }
  88. else if(std::string(argv[i])=="-i")
  89. {
  90. cout << argv[i] << ": ";
  91. cout << "Nie podano sciezki pliku wejsciowego;" <<endl;
  92. }
  93.  
  94. else if(std::string(argv[i])=="-o")
  95. {
  96. cout << argv[i] << ": ";
  97. cout << "Nie podano sciezki pliku wyjsciowego;" <<endl;
  98. }
  99. else if(std::string(argv[i])=="-k")
  100. {
  101. cout << argv[i] << ": ";
  102. cout << "Nie podano pliku klucza;" <<endl;
  103.  
  104. }
  105. else
  106. {
  107. cout << argv[i] << ": ";
  108. cout << "Niepoprawny parametr pracy programu;"<<endl;
  109. }
  110. }
  111. else
  112. {
  113.  
  114.  
  115. if(std::string(argv[i])=="-i")
  116. {
  117. input.open(argv[i+1], ios::in);
  118.  
  119. if(input.good()==true)
  120. {
  121. cout << "Dane wejsciowe zostana pobrany z pliku: " << argv[++i] << endl;
  122. }
  123. else
  124. {
  125. cout << argv[i] << ": ";
  126. cout << "Niepoprawna sciezka pliku wejsciowego!"<<endl;
  127. }
  128. }
  129.  
  130. else if(std::string(argv[i])=="-o")
  131. {
  132. output.open(argv[i+1], ios::out);
  133.  
  134. if(output.good()==true)
  135. {
  136. cout << "Dane wyjsciowe zostana zapisane do pliku: " << argv[++i] << endl;
  137. }
  138. else
  139. {
  140. cout << argv[i] << ": ";
  141. cout << "Niepoprawna sciezka pliku wejsciowego!"<<endl;
  142. }
  143. }
  144. else if(std::string(argv[i])=="-k")
  145. {
  146. key.open(argv[i+1], ios::in);
  147.  
  148. if(key.good()==true)
  149. {
  150. cout << "Klucz zostanie pobrany z pliku: " << argv[++i] << endl;
  151. }
  152. else
  153. {
  154. cout << argv[i] << ": ";
  155. cout << "Niepoprawna sciezka klucza!"<<endl;
  156. }
  157. }
  158.  
  159. else if(std::string(argv[i])=="-bc")
  160. {
  161. if(std::string(argv[i+1])=="c" || std::string(argv[i+1])=="d")
  162. {
  163. cout << "Szyfr blokowy bedzie pracowal w trybie (szyfrowania -> c , deszyfrowania -> d): " << argv[++i] << endl;
  164. }
  165. else
  166. {
  167. cout << argv[i] << ": ";
  168. cout << "Niepoprawny tryb pracy szyfru;"<<endl;
  169. }
  170. }
  171.  
  172. else if(std::string(argv[i])=="-sc")
  173. {
  174. if(std::string(argv[i+1])=="c" || std::string(argv[i+1])=="d")
  175. {
  176. cout << "Szyfr strumieniowy bedzie pracowal w trybie (szyfrowania -c , deszyfrowania -d): " << argv[++i] << endl;
  177. }
  178. else
  179. {
  180. cout << argv[i] << ": ";
  181. cout << "Niepoprawny tryb pracy szyfru;"<<endl;
  182. }
  183. }
  184.  
  185. else if(std::string(argv[i])=="-as")
  186. {
  187. if(std::string(argv[i+1])=="c" || std::string(argv[i+1])=="d")
  188. {
  189. cout << "Szyfr asymetryczny bedzie pracowal w trybie (szyfrowania -c , deszyfrowania -d): " << argv[++i] << endl;
  190. }
  191. else
  192. {
  193. cout << argv[i] << ": ";
  194. cout << "Niepoprawny tryb pracy szyfru;"<<endl;
  195. }
  196. }
  197. else
  198. {
  199. cout << argv[i] << ": ";
  200. cout << "Niepoprawny parametr pracy programu;"<<endl;
  201. }
  202.  
  203. }
  204. }
  205.  
  206. }
  207.  
  208. }
  209.  
  210. getchar();
  211. return 0;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment