Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stdlib.h>
- #include<string.h>
- #include<math.h>
- const int MAX=50;
- using namespace std;
- typedef char cad[MAX];
- typedef int pw[MAX];
- void ing_clave(int &con,int &dig);
- void ord_pw(pw p1, pw &p2, int rango);
- void cambio(int &a,int &b);
- void menu(int &op);
- void ing_frase(cad &fr,int &ocup);
- void encrip(cad f,cad &e,int r1,int r2,pw contra);
- main()
- {
- pw pass,auxp;
- cad palabra,enc;
- int i,ocup,j,clave,aux,aux2,calculo,k,cont_dig,ocup2,opcion;
- bool band,ok,error;
- j=0;
- i=0;
- ing_frase(palabra,ocup);
- ing_clave(clave,cont_dig);
- auxp[0]=clave%10;
- aux=clave/10;
- for (k=1;k<=ocup;k++)
- {
- if (aux==1)
- {
- auxp[k]=1;
- aux=clave/pow(10,k);
- }
- if (aux==0)
- {
- auxp[k]=0;
- aux=clave/pow(10,k);
- }
- else
- {
- auxp[k]=aux%10;
- aux=aux/10;
- }
- }
- k=0;
- ocup2=cont_dig-1;
- ord_pw(auxp,pass,ocup2);
- for (i=0;i<=ocup2;i++)
- {
- cout<<" "<<pass[i];
- }
- encrip(palabra,enc,ocup,ocup2,pass);
- return 0;
- }
- void ing_clave(int &con,int &dig)
- {
- dig=0;
- int aux;
- bool contar;
- do
- {
- aux=0;
- cout<<"Ingrese Clave: ";
- cin>>con;
- if (con<0)
- cout<<"Error: La clave debe ser positiva"<<endl;
- else
- {
- aux=con;
- contar=aux>0;
- while(contar==true)
- {
- dig++;
- aux=aux/10;
- if (aux==0)
- contar=false;
- }
- }
- if (dig<3)
- cout<<"Error: La clave debe ser de mas de 3 digitos"<<endl;
- }while(dig<3);
- cout<<"Clave: "<<con<<endl;
- }
- void ord_pw(pw p1,pw &p2,int rango)
- {
- int i,j;
- j=0;
- i=rango;
- for (j=0;j<=rango;j++)
- {
- p2[j]=p1[i];
- i--;
- }
- }
- void cambio (int &a,int &b)
- {
- int aux;
- aux=a;
- a=b;
- b=aux;
- }
- void menu (int &op)
- {
- cout<<"\n*** MENU ***"<<endl;
- cout<<"1: Ingreso de Frase y clave"<<endl;
- cout<<"2: Encriptacion de la frase"<<endl;
- cout<<"3: Desencriptacion de la frase"<<endl;
- cout<<"4: Salir"<<endl;
- cout<<"Elija opcion: ";
- cin>>op;
- }
- void ing_frase(cad &fr,int &oc)
- {
- int i,j;
- bool band,error,ok;
- j=0;
- i=0;
- while (true)
- {
- band=false;
- ok=false;
- while (ok==false)
- {
- oc=0;
- i=0;
- error=false;
- cout<<"Ingrese frase: ";
- gets(fr);
- while (band==false)
- {
- if (fr[j] == '\0')
- {
- oc=j-1;
- band=true;
- }
- j++;
- }
- for(i=0;i<=oc;i++)
- {
- if (fr[i]!=32)
- {
- if (fr[i]<65 || fr[i]>122)
- {
- error=true;
- }
- else
- {
- if (fr[i]>90&&fr[i]<97)
- error=true;
- }
- }
- }
- if (error==true)
- cout<<"Error: Ingreso incorrecto"<<endl;
- else
- ok=true;
- }
- cout<<"Frase: "<<fr<<endl;
- break;
- }
- }
- void encrip (cad f,cad &e,int r1,int r2,pw contra)
- {
- int k=0;
- int i=0;
- for (i=0;i<=r1;i++)
- {
- e[i]=f[i]+contra[k];
- k++;
- if (k>r2)
- k=0;
- }
- cout<<"Frase: "<<e<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement