Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

LIST OF EXPERIMENTs

1. Write a program to encrypt and decrypt a Password.


, Inplement the substitution mono alphabetic technique by using
Caesar Cipher algorithm.
3. Write a Progran to implement Play fair Cipher algorithm.
4. Write a program to demonstrate polyalphabetic cipher by using
HillCipher algorithm:
5. Implement Substitution and transposition technique by using
Vigenere Cipher algorithm.
6. Write a program to implement Rail fence- row & Column

Transformation technique.
7. Demonstrate Data Encryption Standard Algorithm using Cryptool.
8. Implement the RSA Algorithm using Cryptool.
9. Write a program to demonstrate Diffiee-Hellman's key exchange.
10. Demonstrate Message digest (MD5) Algorithm
11. Implement the SHA-1hashing Algorithm
12. Demonstrate how to provide secure data storage, secure data
transmission and for creating digital signatures (GnuPG)
13. Setup a honey pot and monitor the honeypot on network (KF
Sensor)
14. Perform wireless audit on an access point or a router and

decrypt WEP and WPA. (VI Stumbler)


Program. NO: 01

1. Enerypt and Decrypt a Password.


program:
#include<stdio.h
#includesconio.h
#include<string.h
void encrypt(char password| |.int key)
I unsigned int i;
for(i-0;i<strlen(password);tti)
i password[i]-password|i}-key:

void decrypt(char password[|].int key)


unsigned int i;
for(i-0;i<strlen(password);++i)
passwordil-password|ij+key:

void main()
char password[20):
clrscr():
printf("Enter the password: \n"):
scanf("%s'",password);
printf("Password= %s \n".password);
encrypt(password,0xFACA):
printf("Encrypted value= %s \n",password;
decrypt(password,0xFACA);
printf("Decrypted value= %s \n",password);
getch();

Output:

Passuorda intrusion
Encrypted
Decrypted
nlue
u Iue
fiinär SAi
intrus ion
Program. NO: 02

Implement the substitution mono alphabetic technique by


using Caesar Cipher algorithm
AIM:

To implement the simple substitution technique named Caesar cipher.


DESCRIPTION:

To encrypta message with a Caesar cipher. each letter in the message is changed using
a simple rule: shift by three. Each letter is replaced by the letter three letters ahead in the
alphabet. A becomes D, B becomes E. and so on. For the last letters, we can think of the
alphabet as a circle and "wrap around". Wbecomes Z. X becomes A, Y becomes B. and Z
becomes C. To change a message back, cach letter is replaced by the one three before it.

EXAMPLE:

ABCDEF

ABCDEF

D-(p-k)aalse
ALGORITHM:

STEP-1: Read the plain text from the user.


STEP-2: Read the key valuc from thc uscr.
STEP-3: If the key is positive then encrypt the text by adding the key with cach
character in the plain text.
STEP-4: Else subtract the key from the plain text.

STEP-5: Display the cipher text obtained above.

PROGRAM: (Caesar Cipher)


#include <stdio.h>
#include <string.h>
#include<conio.h>
#include <ctype.h>
void main()
char plain[10]. cipher[10]:
int key. i, length.
int result:
clrscr():
printf"n Enter the plain text:");
scanf("os", plain);
printf("n Enter thc key value:"):
scanf("od", &key);
printf"\n \n \tPLAIN TEX: %s".plain);

printf("n \n \tENCRYPTED TEXT: "):


for (i =0, length = strlen(plain); i < length; itt)

cipher[i]-plain[i] + key:
if (isupper(plain[il) && (cipher[i] > 'Z))
cipher[i] = cipher[i] - 26:
if (islower(plain[i)) && (cipher[i]>'z)) cipher[i) =cipherli) -26; print"%e", cipher[i)): }
printf("n \n tAFTER DECRYPTION: "%
for(i=0;i<length;it +)
plain{i|-cipher|1|-key: if(isupperteipher[i&&(plan[iA)
plainl1] plain|i|+26; if(islowertcipherli)& &(plain[i}a)
plainil plain[i]+26h. pintf("oc"plain(i):

getch():

Output:
G Turbo C" DE

Enter the pla in text:he 11o


Enter the key value:3
PLAIN TEXt: hello
ENCRYPTED TEXT: khoor
APTER DECRYPTI ON he llo
Program. NO: 03

IMPLEMENTATION OF PLAYEAIR CIPHER


AIM:

To write a C program to implement the Play fair Substitution technique.


DESCRIPTION:
The Play air cipher starts with ereating a key table. The key table is a 5x5 grid of
letters that will act as the key for encrypting your plaintext. Each of the 25 letters must be
unique and one letter of the alphabet is omitted from the table (as there are 25 spots and 26
letters in the alphabet).

To encrypt a message, one would break the message into diagrams (groups of2 letters)
such that, for example, "Hello World" becomes "HELLO WORLD", and map
them out on
the key table. The two letters of the diagram are considercd as the opposite corncrs of a
rectangle in the key table. Note the relative position of the corners of this rectangle. Then
apply the following 4 rules, in order, to each pair of letters in the
plaintext:
1. If both letters are the same (or only one letter is left),
add an "X" after the first letter

2. If the letters appear on the same row of your table,


replace them with the letters to
their immediate right respectively
3. If the letters appear on the same column of your table, replace them with the letters
immediately below respectively
4, If the letters are not on the same row or column, replace them with the letters on the
same row respectively but at the other pair of cornerS of the rectangle defined by the
original pair.
D. Playfar Coher
Examdel: Plainlext: CRYPIOIS TOO EASY Key NFOSEC Ciphertext:
Grouped lext: CR YP TO IS TO XO EA SY
Ciphertext: AQ TY YB NI Y8 YF C8 02
|HJ N
F
H K
D
ALGORITHM:

STEP-I:Read the plain text from the user.


STEP-2: Read the keyword from the user.
matrix in the row order
STEP-3: Arrange the keyword without duplicates in a 5*5
alphabetical order.
and fill the remaining cells with missed out letters in
Note that 'i' and takes the same cell.
by
STEP-4: Group the plain text in pairs and match the corresponding corner letters
forming a rectangular grid.
STEP-5: Display the obtained cipher text.

PROGRAM: (Playfair Cipher)


#include<stdio.h>

#include<conio.h>
#include<string.h>
#include<ctype.h>
#define MX 5

void playfair(char chl,char ch2, char key[M>X][MX])

int ij,w,x,y,z;
FILE *out;
if(out=fopen("cipher.txt","a+"))=NULL)

printf("File Currupted."):

for(i=0;i<MX;it+)

for(j=0:j<MX;j++)

if(chl=-key[i]j)
w=0;

xj:
clse ifich2--key[il[i)

y-i;

}}

lprint"od%d %d%d",w,x,y,z);:
iflw=y)

x-{x+l)%5;z-(z+l )%5;
printf("%c%c" key[w][x].keylyl[z);
fprintf(out, "%c%c" key[w][x],keylyl[z):
else if(x=F)

w-(w+1)%5:y-(y+l )%5;
printf("%c%c",key[w][x],keylyl z):
fprintf(out, "%c%c" key[w](x],key[ylz)):

else

printf("%c%c",key[w][z],key[yl[x); fprintf(out,
"%c%e" key[w][z],key[y][x]):

fclose(out);

void main()

int i,j,k-0,1,m=0,n;
char key[MX]|MX],keyminus(25],keystr| 10],str[2S]-(03:
char

alpa|26|-'A,BC,D'"E"F"G,HT"KL!'

,"M;N"O,P,QR"S,"T,U,V"w"'XYZ'
clrscr():
printf("nEnter key:"):
gets(keystr):
printf"nEnter the plain text:"):
gets(str);
n=strlen(keystr):

llconvert the characters to uppertext for (i=0; i<n; it+)

if(keystr[i]keystr[ij-";

clse if(keystr[i]==")keystr[i]-1; keystr[i] =


toupper(keystr[i):

i<strlen(str); itt)
lconvert all the characters of plaintext to uppertext for (i-0;

if(str[il--j')str[ij-":
else if(str[il=')str[i]-";
str[i] = toupper(str[i]):

j-0;
for(i-0;i<26;i++)
{
for(k-0;k<n;k++)

if(keystr[k]==alpa[i])
break;
else ifialpafi]--")
break;

if(k==n)

keyminus[jl-alpafi}j+t;
wstuct key keymatrix

fori-0MX,itt)

fori-0;jMX;j++)

if(k<n)

key[i)i]-keystr[k):
k++;}
else

key[ilü]=keyminus[m];mt+;

printf("%c ",key[i]i);

printf("n");

printf("nn Entered text :%slnCipher Text :"str); for(i=0;i<strlen(str); i++){

if(str[i]=')strli]T;
if(str[it 1]=-\0)
playfair(str[i;Xkey):
else

if(str[it I]=)str[itlJ";
if(str[i]=-str[it1)
playfair(strlil'X". key):
clse

playfair(str[il,strli+1|1key);itt;
getch):

Output:

GT Turbo C+ DE

Enter key:hello
the plain text:cse

EnteredText
Cipher tex-DRU
Program. NO: 04

IMPLEM ENTATION OF HILL CIPHER


AIM:
substitution techniques.
To write a C program to implement the hill cipher
DESCRIPTION:
Each letter is represented by a number modulo 26. Often the simple scheme A=0, B

-1...Z= 25, is used, but this isnot an essential feature of thecipher. To encrypl a message, cach
block of nletters is multiplied by an invertible n xn matrix, against modulus 26. To decrypt the
message, each block is multiplicd by the inverse of the matrix used for encryption. The matrix
used for encryption is the cipher key, and it should be chosen randomly from the set of invertible
nxn matrices (modulo 26).

EXAMPLE:

171
9 2 19 57 (iodl 26)= = 'PFO'
3 17 ? 19 456 14

ALGORITHM:

STEP-1: Read the plain text and key from the user.
STEP-2: Split the plain text into groups of length three.
STEP-3: Arrange the keyword in a 3*3 matrix.
STEP-4: Multiply the t wo matrices to obtain the cipher text of length three.
STEP-5: Combine all these groups to get the complete cipher text.

k
PROGRAM: (Hill Cipher)
#include<stdio.h>

#include<conio.h>

#include<string.h>
int main(){

unsigned int a[3][3]-{{6,24,1}.{13,16,10},(20,17,15}}; unsigned int


b[3[3]-{{8,5,10}.(21,8,21}.(21,12,8) }:

int ij, t-0:


unsigncd int c[20],d[20]:
char msg[20]:
clrscr():
printf("Enter plain text\n "):
scanf("%s",msg);
for(i-0;i<strlen(msg);it+)
{ ci] msg[i]-65:
printf("%d ".c{i)):

for(i=0;i<3;it+)

t-0; for(j-0:j<3:j++)

t=t+(a[i][ij*ci):

d[il-%26;

printf("\nEncrypted Cipher Text :");


for(i-0;i<3;i++)
printf(" oc",d[i]+65);
for(i=0;i<3;itt)

t-0;
for(j-0:j<3:j++)
pnt"nlnpted Cpher lex ").

pintti""+6).
getch).
return 0:

Turbo C* DE
Enter plain text
19
Encrypted Cipher Text
Decrypted Cipher Text
Program. NO: 05

IMPLEMENTATION OF VIGENERE CIPHER

AIM:
To implement the Vigenere Cipher substitution techniquc using C program.
DESCRIPTION:
To enerypt, a table of alphabets can be used, temed a tabula recta, Vigenre square, or
Vigenère table. It consists of the alphabet written out 26 times in different rows, cach alphabet
shifted cyclhcally to the let compared to the previous alphabet. corresponding to the 26 posible
Cacsar ciphers. At different points in the encryption process, the cipher uses a different alphabet
from one of the rows. The alphabet uscd at cach point depends on arepcating keyword.

Each row starts with a key letter. The remainder of the row holds the letters A to Z.
Although there are 26 key rowvs shown, you will only use as many keys as there are unique letters
in the key string. here just 5 keys. (L, E, M, 0, N. For successive letters of the message, we are
going to take successive letters of the key string. and encipher each message letter using its
coresponding key row. Choose the next letter of the key, go along that row find the column
heading that matches the message character; the letter at the intersection of (key-row, msg-col]
is the enciphered letter.
Encypiat-CP+eiedle
EXAMPLE:

A IL(C

L3ze-3>3*>*

M>NeiDry

EF
ALGORITHM:

STEP-l: Arrange the alnhabets in row and column of a26*26 matrix.

STEP-2: Circulate the alphabcts in cach row to position left such that the first letter is
attached to last.

STEP-3: Repeat this process for all 26 rows and construct the final key matrix.
STEP-4:The keyword and the plain text is read from the user.
STEP-5: The characters in the keyword are repcated scquentially so as to match with that
of the plain text.

STEP-6: Pick the first letter of the plain text and that of the keyword as the row indices
and column indices respectively.
STEP-7: The junction character where these two mect forms the cipher character.
STEP-8: Repeat the above steps to generate the entire cipher text.

PROGRAM: (Vigenere Cipher)

#include <stdio.h>
#include<conio.h>
#include <ctype.h>
#include <string.h>
void encipher():
void decipher():
vojd main()

int choice:

clrscr():
while(1 )

printf("n l. Encrypt Text"); printf("\2. Decrypt Text"):


printf("\3. Exit"); printf("\ninEnter Your Choice : "):
scanf("%d",&choicc); if(choice = 3)
exit(0);
clse if(choice = 1)
encipher(0;
clse if(choice = 2)

decipher():
else

printf("Please Enter Valid Option.");

void encipher()

unsigncd int ij:


char input(50],key[ 10];
printf("n\nEnter Plain Text: "):
scanf("%s",input);
printf("nEnter Key Value: "):
scanf"%s",key);
printf("nResultant Cipher Text: ");
for(i-0,j-0;i<strlen(input);it+.j++)
{
if(j>=strlen(key))
lj-0;

printf("%e",65+((toupper(input|i)-65)+(toupper(key[i])
65))%26));

void decipher()

unsigned int i,j:


char input[50],key[10]}:
int value:
printf("nlnEnter Cipher Text: ");:
scanf("%s", input);
printf("\nlnEnter the key valuc: "):
scanf("%s",key);
for(i-0,j=-0;i<strlen(input);i++,j++)
alue (ouppenput|1) o)euppekevli) o):
i alue0)
i value= value -1:

printt("oe".65 +(value % 26)):

L Encrypt Iext2 Decrypt Text3 Extt


Enter Your Choice 1

Enter PLain Texta hai


Enter Key Ualue hello
Resultant Cipher Text 0ET
1 Encrypt Text 2 Decrypt Iext 3 Bit
Enter Your Choice 2

Enter Ciphe Text 0ET


Enter the, key value:; helo
-Encrypt Iext 24becrypt T o t i e
Snter You Chotce, 3
ALGORITHM: EXAMPLE: message DESCRIPTION:
top"rails" AIM:
Program.NO: 06
STEP-1l:
STEP-2:
STEP-5: STEP-4:STEP-3: WIRE cipher
yeldsthe rail. To
of In write
is the an the
then
imaginary rail
message a
Arrange NowArrange Read
text. Readcolumns
cipher ERO C
read
fence IMPLEMENTATION
program to
the read the off
SUAE is
characters of the the the Plain EYOURS
ELF BC
REDSAV A
WEAREDI 16.5HOR
AUT in fence,cipher,
written
the keyword plain
charactlers rows.
text.
SCOVE then implement
plain the
row
text
VAR
2 downwards
moving plain TRANSFORMATION
TECHNIQUE
text. depending in 3
wise of 4
the row text the
BDEV up OF
or keyword columnar again when is rail
column on written fence RAIL
the until we
in SCACDOFESEY
number matrix downwards transposition
wise sorted the reach FENCE-
in fornmat.
of whole the
the order
columns bottom
former plaintext and technique.
and ROW
the ot
diagonally
rail.
order
corresponding the isWhen &
to plain written COLUMN
get
text. we on
the L. successive
out. reach
The the
else
/*Deciphering*/
if(1%2--0)printf("nCipher 10;ci] for(i-0;i<:it+) for(i-0,j-0:i<l.i++) main()
Ciphering* #include<conio.h
voidtincludestdio.h>
#include<string. h PROGRAM:Fence)
(Rail
k-(W2)+I; k-W2; cj++]-afil:
if(i%2==1) clj-+]=a[i]:
if(i%2==0) printf"nnEnter
I=strlen(a):
gets(a):printf"n\titclrser): char ij.kl:int

a(20].c(20].d[20):
text
after RAIL
the
applying FENCE
input

string:
rail TECHNIQUE"):
lence ");
:");
printf("ns"c):
Due Enter
TextCipher

cecontrsine
after TurboC++DE getch): printf"
printf"os".d): i=k,j=l:isl-)for i-0,1-0,1<k.for
text the d[l]=0':
input j=j-2:
di]-c[i): djl-c(1).
decryption nText
after
string
TECHNIQUE
FENCE
RAIL after
applying
decryption
coputercoNputer
rail

fence :
scienco: science "):
hie
???
mcdp $-A' S-8modp
-mocp mcdp Ag
EXAMPLE:
Bob. wilh scCret shared establisl1a wants
to Alice thatassume Le's Bob, and
Alice parties, twO the havng begins
by proceSs Thesimple. very itscll
isalgoritlhm
in The AES.
algonthms
like eneryption symmetne inuse eryptoaphy
lor keys cxchangin: method
of aas
usSed
prlarily network.
is lt ublie overa cxchanging
data communication
for secret for usel Ibe
can thatparties tbetwcen
wo seCTet shared establishesa Exchange Keyiellman Dilie
DESCRIPTION:
usingClanguape. alzoith1n lExchange Hellnan
Key Dittie implemcnt
the lo
AIM:
ALGORITIM EXCHANGE KEYELLMAN IMPLEMENTATION
DIEFE OF
09
Program.
NO:
scanf("%d",&y);
person:
"); sccond the for yvaluc
of printf"Enter
the
a-powcr(g,x,n);
scanf("%d",&x);
:");person first the for xvalueofprintf("Enter
the
scanf("%d%d",&n,&g): g:"); and nof valueprintf("Enter
the
clrscr();
n,g,x,a,y,
b; int
main() void
power(a,x,n); return
calculateKey(int
n)int x,int a, int long
(*)%mod)*a)%mod; return
clse
(t*)%mod; return
if(b%2-0)
t-power(a,b/2,
mod):
returm
a;
if(b=1)
int;t long long
mod) int b,
power(int
int a, int long long
#include<conio.h>
#include<stdio.h>
Exchange) Hellman
Key (Diffie
PROGRAM:
p.mod apower
of key
secret onc's other the as
key sccretcommon their compute them both
of NowSTEP-6:
Alice. to
back same the sends
and Bas
key secret computes
his and kbey public selectsa also Similarly
Bob STEP-5:
Bob. tosendsA Alice ThenSTEP-4:
modp his
gas keyAsecret computes AliceSTEP-3:
a.key public random selectsa AliceSTEP-2:
and keysg
p. public same the shares h
Bob and Alice BotSTEP-1:
ALGORITHM:
is:1 person second the for key
first the
15person secondis:1 thepersonfor yof
value the forEnter key
person:6 first the for x value
of the Enter
7 andg n of
value the Enter
DETurboC
n".power(a.y.n)): getch():
ld
person
is second thprintf("key
e for
n".power(b.x,n). ld
personis first thprintf"key
e for
g.y,n). powerf b

You might also like