Advertisement
Guest User

Created by Roxas - Icesun1989 - XundeX - Copyright reserved.

a guest
Dec 8th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <string.h>
  4. #include <Math.h>
  5.  
  6. using namespace std;
  7.  
  8. char alf[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  9.  
  10. void codifica_cesare()
  11. {
  12. char m[100];
  13.  
  14. fflush(stdin); // Svuota lo standard d'input
  15.  
  16. cout<<"Inserisci il testo codificare_>";
  17.  
  18. cin.getline(m,100);
  19.  
  20. for(int i=0; i<strlen(m);i++)
  21. {
  22. if(m[i]!= 32)
  23. {
  24. for(int j=0;j<strlen(alf);j++)
  25. {
  26. if(m[i]==alf[j])
  27. {
  28. int aux=(j+3)%26;
  29. m[i]=alf[aux];
  30. break;
  31. }
  32. }
  33. }
  34. }
  35. cout<<"Il mesaggio codificato e'_> "<<m<<endl;
  36. }
  37.  
  38. void decodifica_cesare()
  39. {
  40. char m[100];
  41.  
  42. fflush(stdin); // Svuota lo standard d'input
  43.  
  44. cout<<"Inserisci un messaggio da decodificare_> ";
  45.  
  46. cin.getline(m,100);
  47.  
  48. for(int i=0; i<strlen(m);i++)
  49. {
  50. if(m[i]!= 32)
  51. {
  52. for(int j=0;j<strlen(alf);j++)
  53. {
  54. if(m[i]==alf[j])
  55. {
  56. int aux;
  57. if((j-3)<0)
  58. {
  59. aux=26+(j-3);
  60. }
  61. else
  62. {
  63. aux=(j-3)%26;
  64. }
  65.  
  66. m[i]=alf[aux];
  67.  
  68. break;
  69. }
  70. }
  71. }
  72. }
  73. cout<<"Il messaggio codificato e'_> "<<m<<endl;
  74. }
  75.  
  76.  
  77. int main(){
  78.  
  79. int opc,opc2;
  80.  
  81. system("COLOR 0A");
  82.  
  83. do{
  84. cout<<"========================================================================================"<<endl;
  85. cout<<" Menu: "<<endl;
  86. cout<<" 1 - Cifrario di Cesare: "<<endl;
  87. cout<<" ......Coming soon...... "<<endl;
  88. cout<<" ......Coming soon...... "<<endl;
  89. cout<<" ......Coming soon...... "<<endl;
  90. cout<<" ......Coming soon...... "<<endl;
  91. cout<<"========================================================================================"<<endl;
  92. cout<<"Inserire l'opzione_> ";
  93.  
  94. cin>>opc;
  95.  
  96. switch(opc)
  97. {
  98. case 1: system("cls");
  99. do{
  100. cout<<"======================"<<endl;
  101. cout<<"Menu"<<endl;
  102. cout<<"1 - Codifica"<<endl;
  103. cout<<"2 - Decodifica"<<endl;
  104. cout<<"3 - Esci"<<endl;
  105. cout<<"======================"<<endl;
  106. cout<<"Inserire l'opzione_> ";
  107. cin>>opc2;
  108.  
  109. switch(opc2)
  110. {
  111. case 1: codifica_cesare(); break;
  112. case 2: decodifica_cesare(); break;
  113. }
  114. }
  115. while(opc2!=3);
  116. system("cls");
  117. break;
  118. }
  119. }
  120. while(opc!=1);
  121. return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement