fork download
  1. #include <iostream>
  2. #include <string.h>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. void szyfrujCezar(char*);
  7. void deszyfrujCezar(char*);
  8. void szyfrujROT(char*);
  9. void deszyfrujROT(char*);
  10. void kodowanie(char *napis);
  11.  
  12. int main()
  13. {
  14. int liczba;
  15. cout << "Wybierz Szyfr: \n" << endl;
  16. cout << "1. Szyfr Cezara" << endl;
  17. cout << "2. ROT-13" << endl;
  18. cout << "3. Szyfr Przestawieniowy" << endl;
  19.  
  20. switch(liczba)
  21. {
  22. case 1:
  23. void szyfrujCezar(char*);
  24. void deszyfrujCezar(char*);
  25. break;
  26.  
  27. case 2:
  28. void szyfrujROT(char*);
  29. void deszyfrujROT(char*);
  30. break;
  31.  
  32. case 3:
  33. void kodowanie(char *napis);
  34. break;
  35. }
  36. }
  37. void szyfrujCezar(char* s)
  38. {
  39. for(int i=0;i<strlen(s);i++)
  40. {
  41. s [i] = tolower(s [i]) - 97;
  42. if((s [i]>=0)&&(s [i]<=26)) s [i] = (s [i] + 3) % 26;
  43. s [i] = s [i] + 97;
  44. }
  45. };
  46.  
  47. void deszyfrujCezar(char* s)
  48. {
  49. for(int i=0;i<strlen(s);i++)
  50. {
  51. s [i] = tolower(s [i]) - 97;
  52. if((s [i]>=0)&&(s [i]<=26)) s [i] = (s [i]+26 - 3) % 26;
  53. s [i] = s [i] + 97;
  54. }
  55. };
  56.  
  57. int main2()
  58. {
  59. char* napis=new char[256];
  60. cout << "Podaj tekst do zaszyfrowania / odkodowania:" << endl;
  61. cin.getline(napis,255,'\n');
  62. char c=0;
  63. while(1)
  64.  
  65. {
  66. cout << "Chcesz zaszyfrowac czy odszyfrowac [Z/O]? ";
  67. cin.get(c);
  68. if((c=='z')||(c=='Z')||(c=='o')||(c=='O')) break;
  69. else
  70. {
  71. cout << "Nieprawidlowy wybor!" << endl;
  72. cin.get(c);
  73. }
  74. }
  75. cout << "Napis po ";
  76. if((c=='z')||(c=='Z'))
  77. {
  78. cout << "zaszyfrowaniu:" << endl;
  79. szyfrujCezar(napis);
  80. }
  81. else if((c=='o')||(c=='O'))
  82. {
  83. cout << "odszyfrowaniu:" << endl;
  84. deszyfrujCezar(napis);
  85. }
  86. cout << napis << endl;
  87. system("pause");
  88. return 0;
  89. }
  90. void szyfrujROT(char* s)
  91. {
  92. for(int i=0;i<strlen(s);i++)
  93. {
  94. s [i] = tolower(s [i]) - 97;
  95. if((s [i]>=0)&&(s [i]<=26)) s [i] = (s [i] + 13) % 26;
  96. s [i] = s [i] + 97;
  97. }
  98. };
  99.  
  100. void deszyfrujROT(char* s)
  101. {
  102. for(int i=0;i<strlen(s);i++)
  103. {
  104. s [i] = tolower(s [i]) - 97;
  105. if((s [i]>=0)&&(s [i]<=26)) s [i] = (s [i]+26 - 13) % 26;
  106. s [i] = s [i] + 97;
  107. }
  108. };
  109.  
  110. int main3()
  111. {
  112. char* napis=new char[256];
  113. cout << "Podaj tekst do zaszyfrowania / odkodowania:" << endl;
  114. cin.getline(napis,255,'\n');
  115. char c=0;
  116. while(1)
  117. {
  118. cout << "Chcesz zaszyfrowac czy odszyfrowac [Z/O]? ";
  119. cin.get(c);
  120. if((c=='z')||(c=='Z')||(c=='o')||(c=='O')) break;
  121. else
  122. {
  123. cout << "Nieprawidlowy wybor!" << endl;
  124. cin.get(c);
  125. }
  126. }
  127. cout << "Napis po ";
  128. if((c=='z')||(c=='Z'))
  129. {
  130. cout << "zaszyfrowaniu:" << endl;
  131. szyfrujROT(napis);
  132. }
  133. else if((c=='o')||(c=='O'))
  134. {
  135. cout << "odszyfrowaniu:" << endl;
  136. deszyfrujROT(napis);
  137. }
  138. cout << napis << endl;
  139. system("pause");
  140. return 0;
  141. }
  142. void kodowanie(char *napis)
  143. {
  144. int dl = strlen(napis);
  145. for(int i=0; i<dl-1; i+=2)
  146.  
  147. {
  148. char pom = napis[i];
  149. napis[i] = napis[i+1];
  150. napis[i+1] = pom;
  151. }
  152. }
  153. int main4()
  154.  
  155. {
  156. char napis[100];
  157.  
  158. cout<<"Podaj napis: ";
  159. cin.getline(napis, 100);
  160.  
  161. kodowanie(napis);
  162.  
  163. cout<<"Szyfr: ";
  164. cout<<napis<<endl;
  165.  
  166. kodowanie(napis);
  167. return 0;
  168. }
  169.  
Success #stdin #stdout 0s 3344KB
stdin
Standard input is empty
stdout
Wybierz Szyfr: 

1. Szyfr Cezara
2. ROT-13
3. Szyfr Przestawieniowy