Source code : Keamanan Pertukaran Kunci Kriptografi Algoritma Hybrid
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
int i1,i2,j,k1,k2,p1,p2,q1,q2,flag,e1,e2,x1,x2,d1,d2;
clrscr();
cout<<"======================================";
cout<<"\n\t PROSES ALGORITMA 'RSA' ==";
cout<<"\n======================================\n";
cout<<"\n Alice memilih p1 = ";
cin>>p1;
cout<<"\n Alice memilih q1 = ";
cin>>q1;
cout<<"\n Bob memilih p2 = ";
cin>>p2;
cout<<"\n Bob memilih q2 = ";
cin>>q2;
cout<<"\n =================================\n";
int n1=p1*q1,n2=p2*q2;
int fn1=(p1-1)*(q1-1),fn2=(p2-1)*(q2-1);
cout<<"\n Nilai dari Alice (p1,q1) = "<<p1<<" "<<q1;
cout<<"\n\n Hasil dari Alice (n1,fn1) = "<<n1<<" "<<fn1;
cout<<"\n\n Nilai dari Bob (p2,q2) = "<<p2<<" "<<q2;
cout<<"\n\n Hasil Dari Bob (n2,fn2) = "<<n2<<" "<<fn2;
cout<<"\n =================================\n";
cout<<"\n\n Alice memilih kunci public e1 (1 < e1< "<<fn1<<") = ";
cin>>e1;
cout<<"\n\n Bob memilih kunci public e2 (1 < e2< "<<fn2<<") = ";
cin>>e2;
int sk1,sk2;
for(i1=1;i1>0;i1++)
{
x1=i1*e1;
d1=x1%fn1;
if(d1==1)
{
cout<<"\n\n Private Key Alice = "<<i1;
sk1=i1;
break;
}
}
for(i2=1;i2>0;i2++)
{
x2=i2*e2;
d2=x2%fn2;
if(d2==1)
{
cout<<"\n\n Private Key Bob = "<<i2;
sk2=i2;
break;
}
}
cout<<"\n\n===============================================================";
cout<<"\n PROSES MENGENKRIPSI & MENDEKRIPSI MASING-MASING BILANGAN ==";
cout<<"\n===============================================================\n";
int pt1,pt2;
cout<<"\n\n Masukan Plain Text Alice (R1)= ";
cin>>pt1;
cout<<"\n\n Masukan Plain Text Bob (R2) = ";
cin>>pt2;
int m1=1;
for(i1=0;i1<e2;i1++)
m1=(m1*pt1)%n2;
m1=m1%n2;
cout<<"\n\n Hasil Cipher Text Alice = "<<m1;
int m2=1;
for(i2=0;i2<e1;i2++)
m2=(m2*pt2)%n1;
m2=m2%n1;
cout<<"\n\n Hasil Cipher Text Bob = "<<m2;
cout<<"\n\nTekan Enter Untuk melihat hasil deskripsi !!";
cout<<"\n============================================\n";
getch();
k1=1;
for(i1=0;i1<sk1;i1++)
k1=(k1*m2)%n1;
k2=k1%n1;
k2=1;
for(i2=0;i2<sk2;i2++)
k2=(k2*m1)%n2;
k2=k2%n2;
cout<<"\n Hasil Decrypted Text Alice = "<<k1;
cout<<"\n\n Hasil Decrypted Text Bob = "<<k2;
cout<<"\n\n======================================";
cout<<"\nMASING-MASING MENGHITUNG P DAN Q ==";
cout<<"\n======================================\n";
int hq=k1*k2;
cout<<"\n Q hasil dari (R1 x R2) = "<<hq;
int hp=1,ex=e1*e2;
for(i2=0;i2<n2;i2++)
hp=(hp*n1)%ex;
hp=hp%ex;
cout<<"\n\n P hasil dari 'n1%n2 mod (e1 x e2)'= "<<hp;
cout<<"\n\n Enter untuk melanjutkan !! !!";
cout<<"\n============================================\n";
getch();
int xa,yb;
cout<<"\n\n\n\n\n\n=============================================================";
cout<<"\n DI LANJUTKAN DENGAN PROSES ALGORITMA 'Deffie-Hellman' ==";
cout<<"\n=============================================================\n";
cout<<"\n\n Alice memilih X = ";
cin>>xa;
cout<<"\n\n Bob memilih Y = ";
cin>>yb;
int hx=1;
for(i1=0;i1<xa;i1++)
hx=(hx*hp)%hq;
hx=hx%hq;
cout<<"\n\n X hasil dari (P%x mod Q) = "<<hx;
int hy=1;
for(i2=0;i2<yb;i2++)
hy=(hy*hp)%hq;
hy=hy%hq;
cout<<"\n\n Y hasil dari (P%y mod Q) = "<<hy;
int ka=1;
for(i1=0;i1<xa;i1++)
ka=(ka*hy)%hq;
ka=ka%hq;
cout<<"\n\n=====================================================\n";
cout<<"\n=== Hasil Key untuk Alice (Y%x mod Q) = "<<ka;
int kb=1;
for(i2=0;i2<yb;i2++)
kb=(kb*hx)%hq;
kb=kb%hq;
cout<<"\n\n=== Hasil Key untuk Bob (X%y mod Q) = "<<kb;
cout<<"\n\n=====================================================\n";
cout<<"\n\n Selanjutnya anggota kelompok kami'Enter' ";
getch();
cout<<"\n\n=======================================================================";
cout<<"\n=====\t\t ANGGOTA KELOMPOK =====";
cout<<"\n=======================================================================";
cout<<"\n=====\t 1. TEGUH FERDI SETIAWAN (NIM 14.11.0085) =====";
cout<<"\n=====\t 2. APIP BASUKI RAHMAN (NIM 14.11.0088) =====";
cout<<"\n=====\t 3. NOVIYAN NANDA P (NIM 14.11.0093) =====";
cout<<"\n=====\t 4. NOVAN TRI AJI (NIM 14.11.0079) =====";
cout<<"\n=======================================================================";
cout<<"\n=====\t\t KELAS TI 2014 B =====";
cout<<"\n=======================================================================";
getch();
}
Belum ada tanggapan untuk "Keamanan Pertukaran Kunci Kriptografi dengan Algoritma Hybrid : Diffie-Hellman dan RSA Menggunakan Bahasa Pemrograman C++"
Post a Comment