Professional Documents
Culture Documents
Cs Lab Manual 1
Cs Lab Manual 1
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
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
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:
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
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
#include<conio.h>
#include<string.h>
#include<ctype.h>
#define MX 5
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):
if(keystr[i]keystr[ij-";
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");
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
-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(){
for(i=0;i<3;it+)
t-0; for(j-0:j<3:j++)
t=t+(a[i][ij*ci):
d[il-%26;
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
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-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.
#include <stdio.h>
#include<conio.h>
#include <ctype.h>
#include <string.h>
void encipher():
void decipher():
vojd main()
int choice:
clrscr():
while(1 )
decipher():
else
void encipher()
printf("%e",65+((toupper(input|i)-65)+(toupper(key[i])
65))%26));
void decipher()
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