algoritma enkripsi klasik

algoritma enkripsi klasik menggunakan metode caesar

#include<iostream.h>
#include<string>
#include<conio.h>
void main()
{
    cout<<"Tulis Pesan : ";
    char inmsg[1000];
    int i, j, length,choice;
    cin.getline(inmsg,100);
    length = strlen(inmsg);

    clrscr();
    cout<<"Enter your choice \n1. Enkripsi \n2. Deskripsi \n";
    cout<<"Pilih : "; cin>>choice;
    clrscr();
    if(choice==1)
    {
    		  // pilihan jenis enkripsi
         int pil_enc;
         int enc;
         cout<<" 1. Caesar "<<endl;
         cout<<" 2. Rot13  "<<endl;
         cout<<" 3. with Key "<<endl;

         cout<<"Pilih Algoritma Enkripsi : "; cin>>pil_enc;

         if (pil_enc == 1){ enc = 3;}
         if (pil_enc == 2) { enc = 13;}
         if (pil_enc == 3) {
         int enckey;
         cout<<"Masukan key : "; cin>>enckey;
         enc = enckey;
         }

         for(i=0;i<length;i++)
         {
             if(isalpha(inmsg[i]))
             {
                 inmsg[i]=tolower(inmsg[i]);
                 for(j=0;j<enc;j++)
                 {
                    if(inmsg[i]=='z')
                    {
                        inmsg[i]='a';
                    }
                    else
                    {
                        inmsg[i]++;
                    }
                 }
             }
         }
         cout<<"enkripsi pesan adalah \""<<inmsg<<"\"\n";
         getch();
    }


    if (choice == 2)
    {
    // pilihan jenis deskripsi
         int pil_dec;
         int dec;
         cout<<" 1. Caesar "<<endl;
         cout<<" 2. Rot13  "<<endl;
         cout<<" 3. with Key "<<endl;
         cout<<"Pilih Algoritma Deskripsi : "; cin>>pil_dec;

         if (pil_dec == 1){ dec = 3;}
         if (pil_dec == 2) { dec = 13;}
         if (pil_dec == 3) {
         int deckey;
         cout<<"Masukan key : "; cin>>deckey;
         dec = deckey;
         }

        for(i=0;i<length;i++)
        {
             if(isalpha(inmsg[i]))
             {
                 inmsg[i]=tolower(inmsg[i]);
                 for(j=0;j<dec;j++)
                 {
                     if(inmsg[i]=='a')
                     {
                        inmsg[i]='z';
                     }
                     else
                     {
                        inmsg[i]--;
                     }
                 }
            }
       }
    cout<<"Deskripsi pesan anda adalah  \""<<inmsg<<"\"\n";
    getch();
    }
}


About Author

amir thoham


Comment & Discussions

    Please LOGIN before if you want to give the comment.