#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void main()
{
clrscr();
int p,q,b,e,Qn,n,f,m=0,d,y,a;
char kata[25],z;
unsigned long int ac[25]; // muatan panjang char
randomize();
do{
b=0;
p=random(10);
for(int i=2; i<=p; i++)
{
if(p%i==0)
b++;
}
clrscr();
}while(b!=1);
do{
b=0;
q=random(10);
for(int i=2; i<=q; i++)
{
if(q%i==0)
b++;
}
clrscr();
}while(b!=1);
n=p*q;
do{
b=0;
cout<<"Input e: "; cin>>e;
for(int i=2; i<=e; i++)
{
if(e%i==0)
b++;
}
clrscr();
}while(e>n || b!=1);
Qn=(p-1)*(q-1);
cout<<"bilangan p : "<<p<<endl;
cout<<"bilangan q : "<<q<<endl;
cout<<"bilangan e : "<<e<<endl;
cout<<"bilangan n : "<<n<<endl;
cout<<"bilangan Qn: "<<Qn<<endl;
cout<<endl;
cout<<"pilih menu :"<<endl;
do{
m++;
f=(1+(m*Qn))%e; // mencari nilai m bulat di misalkan 0
}while(f!=0);
d =(1+(m*Qn))/e; // mencari d
do{
cout<<"1. Plain Text ----> Chipertext";
cout<<"\n2. Chipertext ----> Plain Text";
cout<<"\n3. Keluar";
cout<<"\n\nInput Pilihan : ";cin>>y;
switch(y){
case 1 :{
clrscr();
cout<<"Enkripsi";
cout<<"\n\n Public KEY";
cout<<"\ne: "<<e<<"\tn: "<<n;
cout<<"\n\nInput Kata : "; gets(kata);
for(int i=0; i<strlen(kata); i++) //mendetil jumlah kata
{
int nm=1;
char kcl='a',bsr='A';
while(kata[i]!=bsr && kata[i]!=kcl)
{
nm++;
bsr++;
kcl++;
}
ac[i]=nm;
int pn=1;
for(int j=0; j<e; j++)
{pn = pn*ac[i];
pn = pn%n;}
ac[i]= pn;
cout<<kata[i]<<" : \t"<<ac[i]<<endl;
}
break;}
case 2 :{
clrscr();
cout<<"Deskripsi";
cout<<"\n\nPRIVAT KEY";
cout<<"\nd: "<<d<<"\tn: "<<n;
cout<<"\nInput Banyak Karakter : ";cin>>a;
for(int i=1; i<=a; i++)
{
cout<<endl<<i<<". ";cin>>ac[i-1];
int pn=1;
for(int j=0; j<d; j++)
{pn=pn*ac[i-1];
pn=pn%n;}
ac[i-1]=pn;
char kcl='a';
for(int k=1; k<ac[i-1]; k++)
kcl++;
cout<<" : "<<kcl<<endl;
}
break;}
default :{cout<<"Pilihan Tidak Ada";
break;
}
}
if(y!='3')
{cout<<"\n\nLagi (Y/T)? ";cin>>z;}
}while(z=='y' || z=='Y');
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar