# File

```LAB Experiments
3416/3415 ‫للفصل الدراسي الثاني للعام الجامعي‬
422 :‫المقرر‬
900 :‫الشعبة‬
7 :‫المستوي‬
..................................:‫الرقم الجامعي‬
‫جامعة سلمان بن عبد العزيز‬
‫كلية اآلداب والعلـوم بوادي الدواسر‬
‫قســـم علوم الحاسب و المعلومات‬
..................................: ‫اســم الطالـب‬
Total Marks Allotted: 1 Marks
Evaluation Items
Marks
Attentive
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
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 &amp;&amp; phi%i==0;i+2)
{ FLAG = 1;
return; }
FLAG = 0; }
void encrypt()
{ int i; C = 1;
for(i=0;i&lt; e;i++)
printf(&quot;Enter Two Relatively Prime Numbers\t: &quot;);
scanf(&quot;%d%d&quot;,&amp;p,&amp;q);
n = p*q;
phi=(p-1)*(q-1);
printf(&quot;\n\tF(n)\t= %d&quot;,phi);
do {
printf(&quot;\n\nEnter e\t: &quot;);
scanf(&quot;%d&quot;,&amp;e);
check();
}while(FLAG==1);
1
Mohammed Rahmath
C=C*M%n;
C = C%n;
printf(&quot;\n\tEncrypted keyword : %d&quot;,C);
}
void decrypt() {
int i; M = 1;
for(i=0;i&lt; d;i++)
M=M*C%n;
M = M%n;
printf(&quot;\n\tDecrypted keyword : %d&quot;,M);
}
void main()
{ int p,q,s;
clrscr();
d = 1;
do {
s = (d*e)%phi;
d++; }while(s!=1);
d = d-1;
printf(&quot;\n\tPublic Key\t: {%d,%d}&quot;,e,n);
printf(&quot;\n\tPrivate Key\t: {%d,%d}&quot;,d,n);
printf(&quot;\n\nEnter The Plain Text\t: &quot;);
scanf(&quot;%d&quot;,&amp;M);
encrypt();
printf(&quot;\n\nEnter the Cipher text\t: &quot;);
scanf(&quot;%d&quot;,&amp;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
```