Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<math.h>
  5. const int MAX=50;
  6. using namespace std;
  7. typedef char cad[MAX];
  8. typedef int pw[MAX];
  9. void ing_clave(int &con,int &dig);
  10. void ord_pw(pw p1, pw &p2, int rango);
  11. void cambio(int &a,int &b);
  12. void menu(int &op);
  13. void ing_frase(cad &fr,int &ocup);
  14. void encrip(cad f,cad &e,int r1,int r2,pw contra);
  15. main()
  16. {
  17. pw pass,auxp;
  18. cad palabra,enc;
  19. int i,ocup,j,clave,aux,aux2,calculo,k,cont_dig,ocup2,opcion;
  20. bool band,ok,error;
  21. j=0;
  22. i=0;
  23. ing_frase(palabra,ocup);
  24. ing_clave(clave,cont_dig);
  25. auxp[0]=clave%10;
  26. aux=clave/10;
  27. for (k=1;k<=ocup;k++)
  28. {
  29. if (aux==1)
  30. {
  31. auxp[k]=1;
  32. aux=clave/pow(10,k);
  33. }
  34. if (aux==0)
  35. {
  36. auxp[k]=0;
  37. aux=clave/pow(10,k);
  38. }
  39. else
  40. {
  41. auxp[k]=aux%10;
  42. aux=aux/10;
  43. }
  44. }
  45. k=0;
  46. ocup2=cont_dig-1;
  47. ord_pw(auxp,pass,ocup2);
  48. for (i=0;i<=ocup2;i++)
  49. {
  50. cout<<" "<<pass[i];
  51. }
  52. encrip(palabra,enc,ocup,ocup2,pass);
  53. return 0;
  54. }
  55.  
  56. void ing_clave(int &con,int &dig)
  57. {
  58. dig=0;
  59. int aux;
  60. bool contar;
  61. do
  62. {
  63. aux=0;
  64. cout<<"Ingrese Clave: ";
  65. cin>>con;
  66. if (con<0)
  67. cout<<"Error: La clave debe ser positiva"<<endl;
  68. else
  69. {
  70. aux=con;
  71. contar=aux>0;
  72. while(contar==true)
  73. {
  74. dig++;
  75. aux=aux/10;
  76. if (aux==0)
  77. contar=false;
  78. }
  79. }
  80. if (dig<3)
  81. cout<<"Error: La clave debe ser de mas de 3 digitos"<<endl;
  82. }while(dig<3);
  83. cout<<"Clave: "<<con<<endl;
  84. }
  85.  
  86. void ord_pw(pw p1,pw &p2,int rango)
  87. {
  88. int i,j;
  89. j=0;
  90. i=rango;
  91. for (j=0;j<=rango;j++)
  92. {
  93. p2[j]=p1[i];
  94. i--;
  95. }
  96. }
  97.  
  98. void cambio (int &a,int &b)
  99. {
  100. int aux;
  101. aux=a;
  102. a=b;
  103. b=aux;
  104. }
  105.  
  106. void menu (int &op)
  107. {
  108. cout<<"\n*** MENU ***"<<endl;
  109. cout<<"1: Ingreso de Frase y clave"<<endl;
  110. cout<<"2: Encriptacion de la frase"<<endl;
  111. cout<<"3: Desencriptacion de la frase"<<endl;
  112. cout<<"4: Salir"<<endl;
  113. cout<<"Elija opcion: ";
  114. cin>>op;
  115. }
  116.  
  117. void ing_frase(cad &fr,int &oc)
  118. {
  119. int i,j;
  120. bool band,error,ok;
  121. j=0;
  122. i=0;
  123. while (true)
  124. {
  125. band=false;
  126. ok=false;
  127. while (ok==false)
  128. {
  129. oc=0;
  130. i=0;
  131. error=false;
  132. cout<<"Ingrese frase: ";
  133. gets(fr);
  134. while (band==false)
  135. {
  136. if (fr[j] == '\0')
  137. {
  138. oc=j-1;
  139. band=true;
  140. }
  141. j++;
  142. }
  143. for(i=0;i<=oc;i++)
  144. {
  145. if (fr[i]!=32)
  146. {
  147. if (fr[i]<65 || fr[i]>122)
  148. {
  149. error=true;
  150. }
  151. else
  152. {
  153. if (fr[i]>90&&fr[i]<97)
  154. error=true;
  155. }
  156. }
  157. }
  158. if (error==true)
  159. cout<<"Error: Ingreso incorrecto"<<endl;
  160. else
  161. ok=true;
  162. }
  163. cout<<"Frase: "<<fr<<endl;
  164. break;
  165. }
  166. }
  167.  
  168. void encrip (cad f,cad &e,int r1,int r2,pw contra)
  169. {
  170. int k=0;
  171. int i=0;
  172. for (i=0;i<=r1;i++)
  173. {
  174. e[i]=f[i]+contra[k];
  175. k++;
  176. if (k>r2)
  177. k=0;
  178. }
  179. cout<<"Frase: "<<e<<endl;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement