File

advertisement
LAB Experiments
3416/3415 ‫للفصل الدراسي الثاني للعام الجامعي‬
422 :‫المقرر‬
900 :‫الشعبة‬
7 :‫المستوي‬
..................................:‫الرقم الجامعي‬
‫جامعة سلمان بن عبد العزيز‬
‫كلية اآلداب والعلـوم بوادي الدواسر‬
‫قســـم علوم الحاسب و المعلومات‬
..................................: ‫اســم الطالـب‬
Total Marks Allotted: 1 Marks
Evaluation Items
Marks
Attentive
Assign work (Student Task)
Knowledge Based
Total Marks Secured
Session:
Date:
Aim: Design and implication of encryption and decryption algorithms.
Objective: Make the student to send the packet errorless and securely. Keeping in that
intension make him to-do design the encryption and decryption algorithms using RSA
as it is one of the standard secured algorithm.
Tools:
Softwares : Any c editor
Hard ware : Connected LAN lab
Operating System : Windows Version
o
o
o
o
o
o
o
Public key algorithm invented in 197 by Ron
Rivest, Adi Shamir and Leonard Adleman (RSA)
Sup orts Encryption and Digital Signatures
Most widely used public key algorithm
Gets its security from integer factorization
problem
Relatively easy to understand and implement
RSA Algorithm
int phi,M,n,e,d,C,FLAG;
int check()
{ int i;
for(i=3;e%i==0 && phi%i==0;i+2)
{ FLAG = 1;
return; }
FLAG = 0; }
void encrypt()
{ int i; C = 1;
for(i=0;i< e;i++)
printf("Enter Two Relatively Prime Numbers\t: ");
scanf("%d%d",&p,&q);
n = p*q;
phi=(p-1)*(q-1);
printf("\n\tF(n)\t= %d",phi);
do {
printf("\n\nEnter e\t: ");
scanf("%d",&e);
check();
}while(FLAG==1);
1
Mohammed Rahmath
C=C*M%n;
C = C%n;
printf("\n\tEncrypted keyword : %d",C);
}
void decrypt() {
int i; M = 1;
for(i=0;i< d;i++)
M=M*C%n;
M = M%n;
printf("\n\tDecrypted keyword : %d",M);
}
void main()
{ int p,q,s;
clrscr();
d = 1;
do {
s = (d*e)%phi;
d++; }while(s!=1);
d = d-1;
printf("\n\tPublic Key\t: {%d,%d}",e,n);
printf("\n\tPrivate Key\t: {%d,%d}",d,n);
printf("\n\nEnter The Plain Text\t: ");
scanf("%d",&M);
encrypt();
printf("\n\nEnter the Cipher text\t: ");
scanf("%d",&C);
decrypt();
getch();
}
/*************** OUTPUT *************/
Enter Two Relatively Prime Numbers :
F(n) =
Enter e :
Public Key : {
Private Key : {
,
}
,
}
Enter The Plain Text :
Encrypted keyword :
Enter the Cipher text :
Decrypted keyword :
2
Mohammed Rahmath
Download