Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <string.h>
- #include <Math.h>
- using namespace std;
- 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'};
- void codifica_cesare()
- {
- char m[100];
- fflush(stdin); // Svuota lo standard d'input
- cout<<"Inserisci il testo codificare_>";
- cin.getline(m,100);
- for(int i=0; i<strlen(m);i++)
- {
- if(m[i]!= 32)
- {
- for(int j=0;j<strlen(alf);j++)
- {
- if(m[i]==alf[j])
- {
- int aux=(j+3)%26;
- m[i]=alf[aux];
- break;
- }
- }
- }
- }
- cout<<"Il mesaggio codificato e'_> "<<m<<endl;
- }
- void decodifica_cesare()
- {
- char m[100];
- fflush(stdin); // Svuota lo standard d'input
- cout<<"Inserisci un messaggio da decodificare_> ";
- cin.getline(m,100);
- for(int i=0; i<strlen(m);i++)
- {
- if(m[i]!= 32)
- {
- for(int j=0;j<strlen(alf);j++)
- {
- if(m[i]==alf[j])
- {
- int aux;
- if((j-3)<0)
- {
- aux=26+(j-3);
- }
- else
- {
- aux=(j-3)%26;
- }
- m[i]=alf[aux];
- break;
- }
- }
- }
- }
- cout<<"Il messaggio codificato e'_> "<<m<<endl;
- }
- int main(){
- int opc,opc2;
- system("COLOR 0A");
- do{
- cout<<"========================================================================================"<<endl;
- cout<<" Menu: "<<endl;
- cout<<" 1 - Cifrario di Cesare: "<<endl;
- cout<<" ......Coming soon...... "<<endl;
- cout<<" ......Coming soon...... "<<endl;
- cout<<" ......Coming soon...... "<<endl;
- cout<<" ......Coming soon...... "<<endl;
- cout<<"========================================================================================"<<endl;
- cout<<"Inserire l'opzione_> ";
- cin>>opc;
- switch(opc)
- {
- case 1: system("cls");
- do{
- cout<<"======================"<<endl;
- cout<<"Menu"<<endl;
- cout<<"1 - Codifica"<<endl;
- cout<<"2 - Decodifica"<<endl;
- cout<<"3 - Esci"<<endl;
- cout<<"======================"<<endl;
- cout<<"Inserire l'opzione_> ";
- cin>>opc2;
- switch(opc2)
- {
- case 1: codifica_cesare(); break;
- case 2: decodifica_cesare(); break;
- }
- }
- while(opc2!=3);
- system("cls");
- break;
- }
- }
- while(opc!=1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement