· 7 years ago · Oct 23, 2018, 01:48 PM
1
2
3
4
5
6EX NO : 1 Substitution Ciphers using Caesar Cipher
7
8AIM : Write a C program for Substitution ciphers using Caesar Cipher.
9
10ALGORITHM :
11
121. Enter the plaintext to be encrypted and enter the key value.
132. Function encrypt ( ) will be invoked for encryption.
14a) Take the ascii value of each plain text char and add it with the value of
15 key % 26
16b) Take the equivalent char value for the resultant value of sub-step(a)
17c) Return the cipher text.
183. Function decrypt ( ) will be invoked for decryption.
19a) Take the ascii value of each cipher text char and subtract the value of key % 26 from it
20b) Take the equivalent char value for the resultant value of sub-step(a)
21c) Return the plain text.
22
23PROGRAM :
24
25// Substitution Cipher using CAESAR Cipher
26
27#include <stdio.h>
28#include <string.h>
29#include<ctype.h>
30
31void encrypt(char[ ], int);
32void decrypt(char[ ], int);
33
34main( )
35
36{ char plaintext[20];
37 int key;
38
39 printf("\nCAESAR CIPHER\n\n");
40 printf("\nEnter any String: ");
41 scanf("%s",plaintext);
42 printf("\n Enter the Key: ");
43 scanf("%d",&key);
44 encrypt(plaintext, key);
45}
46
47
48// Encryption
49void encrypt(char str[20], int key)
50{ char ch;
51 int i, length= strlen(str);
52
53 for(i = 0; i < length; i++)
54 {
55 ch = str[i];
56
57 if (isupper(ch))
58
59 {
60
61 ch = ch + (key % 26);
62
63 if (ch > 'Z')
64
65 ch = ch - 26;
66 }
67
68 else if (islower(ch))
69 {
70 ch = ch + (key % 26);
71
72 if (ch > 'z')
73
74 ch = ch - 26;
75
76 }
77 str[i] = (char) ch;
78
79} // end of for
80printf("\n\nEncrypted String is: %s " ,str);
81decrypt(str,key);
82}
83
84// Decryption
85void decrypt(char str[20], int key)
86{ char ch;
87 int i,length= strlen(str);
88
89 for( i = 0; i < length; i++)
90 {
91 ch = str[i];
92
93 if (isupper(ch))
94 {
95 ch = ch - (key % 26);
96 if (ch < 'A')
97 ch = ch - 26;
98 }
99
100 else if (islower(ch))
101 {
102
103 ch = ch - (key % 26);
104 if (ch < 'a')
105 ch = ch - 26;
106 }
107
108 str[i] = (char) ch;
109
110}
111
112 printf("\n\nDecrypted String is: %s ", str);
113
114}
115
116OUTPUT :
117
118[root@localhost janani# cc caesar.c
119[root@localhost janani]# ./a.out
120
121CAESAR CIPHER
122Enter any String: janani
123 Enter the Key: 4
124Encrypted String is: nererm
125Decrypted String is: janani [root@localhost janani]#
126
127
128
129
130
131RESULT : Thus the program for substitution cipher is successfully executed.
132
133
134EX NO : 2 Poly alphabetic ciphers - Playfair Cipher
135
136AIM: To write a C- program to Implement Play Fair Cipher technique.
137
138ALGORITHM :
1391) Generate Key matrix
140a) Take any random key of any length and form a 5 X 5 matrix.
141 b) Fill the rows of the matrix with the key characters and ignore repeating character.
142 c) Fill the remaining matrix with alphabets from A to Z (except those already occurred in
143 the key).
1442) Encrypt the data using encryption rule and key matrix
145 a)To Encrypt the data take two characters at time from plain text file and encrypt it
146 using one of the following rules.
147 b) Repeating plain text letters that would fall in the same pair are separated with
148 filler letter,
149 c) If both the characters are in the same raw then replace each with the character to
150 its right, with the last character followed by the first, in the matrix.
151 d) If both the characters are in the same column then replace each with the character
152 below it, with the bottom character followed by the top, in the matrix.
153 Otherwise each plain text letter is replaced by the letter that lies in its own row
154 and the column occupied by the other plain text letter
1553) To decrypt, use the inverse of encryption rules.
1564) Display the cipher text after encryption and plain text after decryption.
157PROGRAM :
158#include<iostream>
159using namespace std;
160int main()
161{
162 int i,j,isI=0,l,k=0,start=0,same=0,k1=0;
163 int i1,j1,i2,j2,i11,jj;
164 char alph[5][5],chr[25],chr2[25],character,chr1='a',chr_ex[25];
165 char txt[25],txt2[25];
166 cout<<"Enter the text : ";
167 cin>>chr;
168 for(i=0;i<strlen(chr2);i++) /*TO PREVENT STRING FROM BEING PRINTED WITH GARBAGE CHARACTER...*/
169 {
170 chr_ex[i]='-';
171 }
172 for(i=0;i<strlen(chr);i++)
173 {
174 cout<<"\n"<<i+1<<"\t"<<chr[i];
175 chr_ex[i]=chr[i];
176 }
177 for(i=0;i<5;i++)
178
179 {
180 for(j=0;j<5;j++)
181 {
182 alph[i][j]='-';
183 }
184 }
185 for(i=0;i<5;i++)
186 {
187 for(j=0;j<5;j++)
188 {
189 character=chr[++k];
190 for(l=k-1;l>=0;l--) //FOR REPEATING CHARACTERS...
191 {
192 if(character==chr[l])
193 {
194 chr[k]='-';
195 break;
196 }
197 }
198 }
199 }
200 k=0;
201 for(i=0;i<5;i++)
202 {
203 for(j=0;j<5;j++)
204 {
205 if(start++<strlen(chr))
206 if(chr[k]!='-') //FOR i AND j
207 {
208 if(chr[k]=='i' || chr[k]=='j')
209 {
210 if(isI==0)
211 {
212 alph[i][j]=chr[k];
213 isI=1;
214 }
215 else
216 {
217 if(chr[k]=='i') chr[k]='i';
218 if(chr[k]=='j') chr[k]='j';
219 j--;
220 }
221 }
222
223 else alph[i][j]=chr[k];
224 }
225 else
226 {
227 chr[k]='-';
228 j--;
229 }
230 k++;
231 }
232 }
233 chr1--;
234 k1=0;
235 for(i=0;i<5;i++)
236 {
237 for(j=0;j<5;j++)
238 {
239 if(alph[i][j]=='-')
240 {
241 same=0;
242 chr1++;
243 for(k1=0;k1<strlen(chr);k1++)
244 {
245 if(chr1==chr[k1])
246 {
247 same=1; //else same=0;
248 j--;
249 break;
250 }
251 }
252 if(same!=1)
253 {
254 if(chr1=='i' || chr1=='j')
255 {
256 if(isI==0)
257 {
258 alph[i][j]=chr1;
259 isI=1;
260 }
261 else
262j--;
263 }
264 else
265alph[i][j]=chr1;
266 }
267}
268}
269 }
270 cout<<"\n"<<"\n"<<"\n";
271 for(i=0;i<5;i++)
272 {
273 for(j=0;j<5;j++)
274 {
275 cout<<alph[i][j];
276 }
277 cout<<"\n";
278 }
279 j=0;
280 for(i=0;i<strlen(chr);i++)
281 {
282 if(chr[i]=='-')
283 {
284 for(j=i;j<strlen(chr);j++)
285 {
286 chr[j]=chr[j+1];
287 }
288 }
289 }
290 cout<<"\n"<<"\n"<<"Enter the plain text : ";
291 cin>>txt;
292 j=0;
293 for(i=0;i<strlen(txt);i++)
294 {
295 txt2[j++]=txt[i];
296 if(txt[i]==txt[i+1])
297 {
298 txt2[j++]='x';
299 }
300 }
301 jj=j;
302 for(i11=0;i11<strlen(txt2);i11+=2)
303 {
304 for(i=0;i<5;i++)
305 {
306 for(j=0;j<5;j++)
307 {
308 if(txt2[i11]==alph[i][j])
309 {
310 i1=i;
311 j1=j;
312 }
313 if(txt2[i11+1]==alph[i][j])
314 {
315 i2=i;
316 j2=j;
317 }
318 }
319 }
320 if(i1==i2)
321 {
322 if((j1+1)>=5) j1=-1;
323 if((j2+1)>=5) j2=-1;
324 txt2[i11]=alph[i1][j1+1];
325 txt2[i11+1]=alph[i2][j2+1];
326 }
327 else if(j1==j2)
328 {
329 if((i1+1)>=5) i1=-1;
330 if((i2+1)>=5) i2=-1;
331 txt2[i11]=alph[i1+1][j1];
332 txt2[i11+1]=alph[i2+1][j2];
333 }
334 else
335 {
336 if(i2>i1)
337 {
338 txt2[i11+1]=alph[i2][j1];
339 txt2[i11]=alph[i1][j2];
340 }
341 else
342 {
343 txt2[i11]=alph[i2][j1];
344 txt2[i11+1]=alph[i1][j2];
345 }
346 }
347 }
348 cout<<"\n"<<"Final string : ";
349 for(i=0;i<jj;i++)
350 {
351 cout<<txt2[i];
352 }
353}
354OUTPUT:
355[root@localhost janani]# g++ playfair.cpp
356[root@localhost janani]# ./a.out
357Enter the text : computer
358
3591 c
360
3612 o
362
3633 m
364
3654 p
366
3675 u
368
3696 t
370
3717 e
372
3738 r
374
375 compu
376
377terab
378
379dfghi
380
381klnqs
382
383vwxyz
384
385Enter the plain text : science
386Final string : ukbfmko[root@localhost janani]#
387
388
389RESULT :
390 Thus the program for playfair cipher is successfully executed.
391
392
393
394EX NO : 3 Poly alphabetic ciphers - Hill Cipher
395
396AIM : To write a C- program to Implement Hill Cipher Technique.
397
398ALGORITHM :
3991. Enter the plain text.
4002, Enter the matrix, named key matrix for encryption. The elements of the matrix will be randomly chosen and of modulo 26.
4013. Plain text characters are multiplied by the encryption matrix.
4024. Display the cipher text.
4035. Find the inverse of the key matrix.
4046. For decryption , Multiply the characters of cipher text by key matrix to get plaintext and display it.
405
406PROGRAM :
407#include<iostream>
408using namespace std;
409int check(int);
410int main(int argc,char **argv)
411{
412int l,i,j,temp1,k[3][3],p[3][1],c[3][1];
413char ch;
414cout<<"\nThis cipher has a key of length 9";
415cout<<"\nEnter the 9 character key";
416for(i=0;i<3;i++)
417{
418 for(j=0;j<3;j++)
419 {
420 scanf("%c",&ch);
421 if (65<=ch&&ch<=91)
422 k[i][j]=(int)ch%65;
423 else
424 k[i][j]=(int)ch%97;
425 }
426 }
427
428for(i=0;i<3;i++)
429 {
430 for(j=0;j<3;j++)
431 {
432 cout<<k[i][j]<<" ";
433 }
434 cout<<endl;
435}
436cout<<"\nEnter the length of string to be encoded(without spaces). ";
437 cin>>l;
438 temp1=check(l);
439cout<<temp1;
440if(temp1>0)
441cout<<"You have to enter "<<temp1<<" bogus characters.";
442 char pi[l+temp1];
443 cout<<"\nEnter the string. ";
444 for(i=-1;i<l+temp1;i++)
445 { cin>>pi[i];
446 }
447 int temp2=l;
448 int n=(l+temp1)/3;
449 int temp3,k1;
450 int flag=0;
451 int count;
452 cout<<"\n\nThe encoded cipher is : ";
453while(n>0)
454{
455count=0;
456 for(i=flag;i<flag+3;i++)
457 {
458 if(65<=pi[i]&&pi[i]<=91)
459 temp3=(int)pi[i]%65;
460 else
461 temp3=(int)pi[i]%97;
462p[count][0]=temp3;
463count=count+1;
464 }
465for(i=0;i<3;i++)
466c[i][0]=0;
467for(i=0;i<3;i++)
468{
469 for(j=0;j<1;j++)
470 {
471 for (k1=0;k1<3;k1++)
472 c[i][j]+=k[i][k1]*p[k1][j];
473 }
474 }
475 for(i=0;i<3;i++)
476 {
477 c[i][0]=c[i][0]%26;
478 printf("%c",(char)(c[i][0]+65));
479
480 }
481 n=n-1;
482 flag=flag+3;
483 }
484}
485int check(int x)
486{
487 int a,b,c;
488 if(x%3==0)
489 return 0;
490 a=x/3;
491 b=3*(a+1);
492 c=b-x;
493 return c;
494}
495
496
497
498
499
500
501OUTPUT:
502
503[root@localhost janani]# g++ hillcipher.cpp
504[root@localhost janani]# ./a.out
505
506This cipher has a key of length 9
507Enter the 9 character key sjkmvpssn
508
50932 18 9
510
51110 12 21
512
51315 18 18
514
515Enter the length of string to be encoded(without spaces). 10
5162You have to enter 2 bogus characters.
517Enter the string. acceptability
518
519The encoded cipher is : QWUZHOSHTJXS[root@localhost janani]#
520
521
522
523
524
525
526
527RESULT :
528
529 Thus the program for Hill cipher is successfully executed.
530
531EX NO : 4 Poly alphabetic ciphers - Vigenere Cipher
532
533AIM : To write a C- program to Implement Vigenere Cipher technique.
534
535ALGORITHM :
5361. Enter the plain text for encryption.
5372. Enter the encryption key pharse.
5383. Cipher text is obtained by modular addition of a key pharse and plain text.
5394. For decryption to get the plaintext again the key pharse is modularly subtracted from the cipher text.
5405. Display the cipher text and plaintext.
541
542// Vigenere Cipher
543 #include <iostream>
544 #include <string>
545 using namespace std;
546
547 class Vigenere
548 {
549 public:
550 string key;
551 Vigenere(string key)
552 {
553 for (int i = 0; i < key.size(); ++i)
554 {
555
556 if (key[i] >= 'A' && key[i] <= 'Z')
557 this->key += key[i];
558 else if (key[i] >= 'a' && key[i] <= 'z')
559 this->key += key[i] + 'A' - 'a';
560 }
561 }
562
563 string encrypt(string text)
564 {
565 string out;
566 for (int i = 0, j = 0; i < text.length(); ++i)
567 { char c = text[i];
568 if (c >= 'a' && c <= 'z')
569 c += 'A' - 'a';
570 else if (c < 'A' || c > 'Z')
571 continue;
572 out += (c + key[j] - 2 * 'A') % 26 + 'A';
573 j = (j + 1) % key.length();
574 }
575 return out;
576 }
577
578 string decrypt(string text)
579 {
580 string out;
581 for (int i = 0, j = 0; i < text.length(); ++i)
582 {
583 char c = text[i];
584 if (c >= 'a' && c <= 'z')
585 c += 'A' - 'a';
586 else if (c < 'A' || c > 'Z')
587 continue;
588 out += (c - key[j] + 26) % 26 + 'A';
589 j = (j + 1) % key.length();
590 }
591 return out;
592 }
593
594 };
595 int main()
596 {
597 Vigenere cipher("VIGENERECIPHER");
598 string original = "Welcome to cryptography";
599 string encrypted = cipher.encrypt(original);
600 string decrypted = cipher.decrypt(encrypted);
601 cout << original << endl;
602 cout << "Encrypted: " << encrypted << endl;
603 cout << "Decrypted: " << decrypted << endl;
604 }
605
606
607
608OUTPUT:
609
610[root@localhost janani]# g++ vignere.cpp
611[root@localhost janani]# ./a.out
612
613Welcome to cryptography
614
615Encrypted: RMRGBQVXQKGFTKJOXECLP
616
617Decrypted: WELCOMETOCRYPTOGRAPHY
618
619RESULT :
620 Thus the program for vigenere cipher is successfully executed.
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635EX NO : 5 Rail fence – row & Column Transformation
636
637AIM : To write a C- program to Implement Rail fence row & Column transformation.
638
639ALGORITHM :
6401. Enter the plain text for encryption.
6412. Enter the depth in integer (number of rows)
6423. In the rail fence cipher, the plaintext is written downwards and diagonally on successive "rails" of an imaginary fence, then moving up when we reach the bottom rail.
6434. When we reach the top rail, the message is written downwards again until the whole plaintext is written out.
6445. The message is then read off in rows. Thus, the cipher text is generated.
645PROGRAM :
646// Railfence cipher
647#include<stdio.h>
648#include<string.h>
649int main()
650{
651 int i,j,k,l;
652 char a[20],c[20],d[20];
653 printf("\nEnter the input string : ");
654 scanf("%s",a);
655 l=strlen(a);
656 /*Ciphering*/
657for(i=0,j=0;i<l;i++)
658{
659 if(i%2==0)
660 c[j++]=a[i];
661}
662for(i=0;i<l;i++)
663{
664 if(i%2==1)
665 c[j++]=a[i];
666}
667c[j]='\0';
668printf("\nCipher text after applying rail fence :");
669printf("\n%s",c);
670
671/*Deciphering*/
672if(l%2==0)
673 k=l/2;
674else
675 k=(l/2)+1;
676for(i=0,j=0;i<k;i++)
677{
678 d[j]=c[i];
679 j=j+2;
680}
681for(i=k,j=1;i<l;i++)
682{
683 d[j]=c[i];
684 j=j+2;
685}
686d[l]='\0';
687printf("\nText after decryption : ");
688printf("%s",d);
689}
690
691
692OUTPUT
693[root@localhost janani]# gedit railfence.c
694
695[root@localhost janani]# cc rail.c
696
697[root@localhost janani]# ./a.out
698
699
700Enter the input string : Research
701
702
703Cipher text after applying rail fence :
704
705Rsaceerh
706
707Text after decryption : Research[root@localhost janani]#
708
709
710RESULT :
711 Thus the program for Rail-fence cipher is successfully executed.
712
713EX NO : 6 Implementation of DES Cipher
714
715AIM : To write a C- program to Implement DES Cipher Encryption and decryption technique.
716
717ALGORITHM :
718 1. Enter the plain text and key
719 2. Initial permutation (IP) will be done for the plain text and key.
720 3. 16 rounds of a complex key dependent calculation f
721 Function f is
722 L(i) = R(i-1)
723 R(i) = L(i-1) Ã… P(S( E(R(i-1)) Ã… K(i) ))
724 4. A final permutation, being the inverse of IP will be done to get cipher text.
725 5. The above steps 4, 3, 2 are repeated in reverse order to get decrypted text.
726
727PROGRAM :
728/// DES - symmetric key encryption
729#include <stdio.h>
730int l[4],r[4],keys[2][8],ct[8];
731void sbox(int sip[],int p[],int sbno,int i)
732{
733 int sbox[2][4][4]={1,0,3,2,3,2,1,0,0,2,1,3,3,1,3,2,0,1,2,3,2,0,1,3,3,0,1,0,2,1,0,3};
734 int rw, c, sop;
735
736 rw = sip[3]+sip[0]*2;
737 c = sip[2]+sip[1]*2;
738 sop = sbox[sbno][rw][c]; //sop gives decimal value of S-Box Output
739 for(;sop!=0;sop/=2)
740 p[i--]=sop%2;
741}
742void cmp_fun(int round)
743{
744 int EP[]={4,1,2,3,2,3,4,1},i,epd[8];
745 int slip[4],srip[4];
746 int p[4]={0},p4[]={2,4,3,1},np[4];
747 for(i=0;i<8;i++) // E/P Permutation
748 epd[i]=r[EP[i]-1];
749 for(i=0;i<8;i++)//Performing XOR with Key
750 if(i<4)
751 slip[i] = epd[i]^keys[round][i]; // Using Key _ 1=>0
752 else
753 srip[i-4] = epd[i]^keys[round][i];
754 sbox(slip,p,0,1);//Calling SBox 1, 0->SBOX 1
755 sbox(srip,p,1,3);//Calling SBox 1, 1->SBOX 2
756 for(i=0;i<4;i++) //P4 permutation
757 np[i]=p[p4[i]-1];
758 for(i=0;i<4;i++)
759 l[i] = l[i]^np[i];
760}
761
762void left_shift(int keyip[], int nob)
763{
764 int t1,t2,i;
765 while(nob>0)
766 {
767 t1=keyip[0],t2=keyip[5];
768 for(i=0;i<9;i++)
769 if(i<4)
770 keyip[i] =keyip[i+1];
771 else if(i>4)
772 keyip[i] = keyip[i+1];
773 keyip[4]=t1,keyip[9]=t2;
774 nob--;
775 }
776}
777void gen_keys()
778{
779 int key[10],i,keyip[10];
780 int p10[]={3,5,2,7,4,10,1,9,8,6},p8[]={6,3,7,4,8,5,10,9};
781 printf("\n\nEnter Key : 10-bits separated by blank space");
782 for(i=0;i<10;i++)
783 scanf("%d", &key[i]);
784 for(i=0;i<10;i++) // Permutation P10
785 keyip[i] = key[p10[i]-1];
786 left_shift(keyip,1); // Left Shifting (Array,No of bts)
787 printf("\n\nKey1 :");
788 for(i=0;i<8;i++) //Permuting P8 on key1
789 { keys[0][i] = keyip[p8[i]-1];// Key1 Generated!!
790 printf("%d",keys[0][i]);
791 }
792 left_shift(keyip,2); // Generating Key2 . .
793 printf("\n\nKey2 :");
794 for(i=0;i<8;i++)
795 {
796 keys[1][i] = keyip[p8[i]-1];// Key2 Generated!!
797 printf("%d",keys[1][i]);
798 }
799}
800void En_De(int pt[],int c)
801{
802 int ip[]={2,6,3,1,4,8,5,7},ipi[]={4,1,3,5,7,2,8,6},t[8],i;
803 for(i=0;i<8;i++) // Performing Permutation on input bits!!
804 if(i<4)
805 l[i]=pt[ip[i]-1];
806 else
807 r[i-4] = pt[ip[i]-1];
808 cmp_fun(c);//Round 0+1 using key 0+1
809 for(i=0;i<4;i++) //Swapping left & right
810 r[i]=l[i]+r[i],l[i]=r[i]-l[i],r[i]=r[i]-l[i];
811 printf("\n\n");
812 cmp_fun(!c); // Round 1+1 wid key1+1 wid swapped bits
813 for(i=0;i<8;i++)
814 if(i < 4)
815 t[i]=l[i];
816 else
817 t[i]=r[i-4];
818 for(i=0;i< 8;i++)
819 ct[i] = t[ipi[i]-1];
820}
821
822
823int main( )
824{
825 int pt[8]={0},i;
826 printf("\n DES - ENCRYPTION & DECRYPTION");
827 printf("\n\n Enter plain text binary bits:8-binary bits separated by blank");
828 for(i=0;i<8;i++)
829 scanf("%d",&pt[i]);
830 gen_keys(); // Generating Keys key1 & key2
831 En_De(pt,0);
832 printf("\nCipher Text :");
833 for(i=0;i<8;i++)
834 printf("%d",ct[i]);
835 //Decrypting - - -
836 En_De(ct,1);
837 printf("\nPlain Text (After Decrypting):");
838 for(i=0;i<8;i++)
839 printf("%d",ct[i]);
840}
841
842OUTPUT :
843[root@localhost janani]# gedit des.c
844[root@localhost janani]# cc gedit.c
845[root@localhost janani]# ./a.out
846
847 DES - ENCRYPTION & DECRYPTION
848
849 Enter plain text binary bits:8-binary bits separated by blank
85011110000
851
852Enter Key : 10-bits separated by blank space
8531111100000
854
855Key1 :10010100
856Key2 :01010101
857
858Cipher Text :11101001
859
860Plain Text (After Decrypting):11110000[root@localhost janani]#
861
862
863
864RESULT :
865
866 Thus the program for symmetric key cryptography is successfully executed.
867
868
869
870
871
872
873
874EX NO : 7 Implementation of Encryption and decryption using RSA
875AIM : To write a C- program to Implement Encryption and decryption using RSA
876 Algorithm..
877
878ALGORITHM :
879Key generation:
880
8811. Select random prime numbers p and q , and check that p != q
8822. Compute modulus n = pq
8833. Compute phi, ¢ = (p - 1)(q - 1)
8844. Select public exponent e , 1 < e < ¢ . such that gcd(e, ¢ ) = 1
8855. Compute private exponent d =e- 1 mod ¢
8866. Public key is {n, e}, private key is d
887Encryption & Decryption
888 7. Encryption: c = m e mod n ,
8899. Decryption: m = c d mod n
89010. Display the cipher text and plain text.
891
892PROGRAM :
893// RSA - Algortihm
894#include<stdio.h>
895#include<math.h>
896int main( )
897{
898 int i,j,k,p,q,flag,e,x,d;
899 printf("\n RSA ALGORITHM \n\n\n ");
900 printf(" \n Enter Value of p :: ");
901 scanf("%d",&p);
902 printf(" \n Enter Value of q :: ");
903 scanf("%d",&q);
904 int n=p*q;
905 int fn=(p-1)*(q-1);
906 printf("\n Value of (p,q) :: %d %d",p,q);
907 printf("\n Value of n,fn :: %d %d",n,fn);
908 printf("\n\n Select Public Key e (1 < e < %d )",fn);
909 scanf("%d",&e);
910 int sk;
911 for(i=1;i>0;i++)
912 {
913 x=i*e;
914 d=x%fn;
915 if(d==1)
916 {
917 printf("\n\n Private Key :: %d",i);
918 sk = i;
919 break;
920 }
921 }
922 int pt;
923 printf("\n\n Enter Plain Text ::");
924 scanf("%d",&pt);
925 int m=1;
926 for(i=0;i<e;i++)
927 m=(m*pt)%n;
928 m=m%n;
929 printf("\n\n Cipher Text :: %d",m);
930 k=1;
931 for(i=0;i<sk;i++)
932 k=(k*m)%n;
933 k=k%n;
934 printf("\n\n Decrypted Text :: %d",k);
935 return 0;
936}
937
938
939
940OUTPUT :
941[root@localhost janani]#gedit RSA.c
942[root@localhost janani]#cc RSA.c
943[root@localhost janani]#./a.out
944RSA ALGORITHM
945
946 Enter Value of p :: 17
947 Enter Value of q :: 11
948 Value of (p,q) :: 17 11
949 Value of n,fn :: 187 160
950 Select Public Key e (1 < e < 160 )7
951 Private Key :: 23
952 Enter Plain Text ::88
953 Cipher Text :: 11
954 Decrypted Text :: 88[root@localhost janani]#
955
956
957RESULT :
958 Thus the program for public key cryptography is successfully executed.
959
960
961
962
963
964
965
966
967EX NO : 8 Implementation of Diffie Hellman key Exchange Algorithm
968
969AIM : To write a C- program to Implement Diffie Hellman key exchange Algorithm.
970
971ALGORITHM :
972 1. Enter the value of n and g both are prime numbers.
973 2. Enter x and y and these are private chosen by the users alice and bob respectively.
974 3. Alice calculates g x mod n and Bob calculates g y mod n
975 4. Bob sends the value g y mod n to Alice and alice sends the value g x mod n to
976 Bob.
977 5. Alice will calculate the shared secret by (g y mod n )x mod n and bob by
978 (g x mod n )y mod n.
979 6 . Display the shared secret key.
980
981 PROGRAM :
982// Diffie hellman key exchange protocol
983#include<stdio.h>
984#include<math.h>
985int alice(int,int,int);
986int bob(int,int,int);
987int main( )
988{ long int g,x,y,a,b,k1,k2,n;
989 printf("\n DIFFIE HELLMAN KEY EXCHANGE");
990 printf("\n\n\t Enter value of n & g");
991 scanf("%ld%ld",&n,&g);
992 printf("\n\n\t Enter value of x & y");
993 scanf("%ld%ld",&x,&y);
994 a=alice(n,g,x);
995 printf("\n\t alice end value: %ld",a);
996 b=bob(n,g,y);
997 printf("\n\t bob end value: %ld",b);
998 k1=alice(n,b,x);
999 printf("\n\t value of k1 : %ld",k1);
1000 k2=bob(n,a,y);
1001 printf("\n\t value of k2 : %ld",k2); }
1002int alice(int n, int g, int x)
1003{ long int a, a1;
1004 a1=pow(g,x);
1005 a=a1%n;
1006 return(a);
1007}
1008
1009int bob(int n, int g, int y)
1010{ long int b, b1;
1011 b1=pow(g,y);
1012 b=b1%n;
1013 return(b);
1014}
1015
1016OUTPUT :
1017[root@localhost janani]# gedit diffiehellman.c
1018[root@localhost janani]# cc ex-2c.c -lm
1019[root@localhost janani]# ./a.out
1020
1021 DIFFIE HELLMAN KEY EXCHANGE
1022Enter value of n & g11 2
1023Enter value of x & y9 4
1024alice end value: 6
1025bob end value: 5
1026 value of k1 : 9
1027 value of k2 : 9[root@localhost janani]#
1028
1029RESULT :
1030 Thus the program for Diffie hellman key exchange is successfully executed.
1031
1032EX NO : 9 Implementation of MD5 Algorithm
1033
1034AIM: To Write a program to calculate the message digest of a text using
1035the MD-5.
1036
1037ALGORITHM :
1038Step1: Append padding bits to the input plain text
1039Step2: Append length
1040Step3: Initialize MD buffer
1041Step4: Process message in 512-bit(16word)blocks
1042Step5: Display the encrypted and decrypted text.
1043PROGRAM:
1044// Program for MD5
1045
1046import java.security.*;
1047public class MD5
1048{
1049public static void main(String[] a)
1050 {
1051// TODO code application logic here
1052try {
1053
1054MessageDigest md = MessageDigest.getInstance("MD5");
1055System.out.println("Message digest object info: ");
1056System.out.println(" Algorithm = " +md.getAlgorithm());
1057System.out.println(" Provider = " +md.getProvider());
1058System.out.println(" ToString = " +md.toString());
1059String input = "";
1060md.update(input.getBytes());
1061byte[] output = md.digest();
1062System.out.println();
1063System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));
1064input = "abc";
1065md.update(input.getBytes());
1066output = md.digest();
1067System.out.println();
1068System.out.println("MD5(\""+input+"\") = " +bytesToHex(output));
1069input = "abcdefghijklmnopqrstuvwxyz";
1070md.update(input.getBytes());
1071output = md.digest();
1072System.out.println();
1073System.out.println("MD5(\"" +input+"\") = " +bytesToHex(output));
1074System.out.println("");
1075}
1076
1077catch (Exception e)
1078{
1079 System.out.println("Exception: " +e); }
1080}
1081public static String bytesToHex(byte[] b)
1082 {
1083char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
1084
1085StringBuffer buf = new StringBuffer();
1086for (int j=0; j<b.length; j++)
1087{
1088 buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
1089 buf.append(hexDigit[b[j] & 0x0f]);
1090 }
1091return buf.toString();
1092} }
1093
1094OUTPUT:
1095[root@localhost janani]# javac MD5.java
1096
1097[root@localhost janani]# java MD5
1098Message digest object info:
1099 Algorithm = MD5
1100 Provider = SUN version 1.6
1101 ToString = MD5 Message Digest from SUN, <initialized>
1102MD5("") = D41D8CD98F00B204E9800998ECF8427E
1103MD5("abc") = 900150983CD24FB0D6963F7D28E17F72
1104MD5("abcdefghijklmnopqrstuvwxyz") = C3FCD3D76192E4007DFB496CCA67E13B
1105
1106
1107RESULT :
1108 Thus the program for message digest using MD-5 is executed successfully.
1109
1110EX NO : 10 Implementation of SHA-1 Algorithm
1111
1112AIM: To Write a program to calculate the message digest of a text using the SHA-1 algorithm.
1113 ALGORITHM :
11141 : Input the plain text
11152: Append padding bits
11163: Append length
11174: Initialize buffer.
11185: Process message in 512-bit(16word)blocks
11196: encrypted in hexa decimal format
11207: Display the encrypted text.
1121
1122PROGRAM:
1123Import java.security.*;
1124public class SHA1 {
1125public static void main(String[] a)
1126{
1127try
1128{
1129
1130MessageDigest md = MessageDigest.getInstance("SHA1");
1131System.out.println("Message digest object info: ");
1132System.out.println(" Algorithm = " +md.getAlgorithm());
1133System.out.println(" Provider = " +md.getProvider());
1134System.out.println(" ToString = " +md.toString());
1135String input = "";
1136md.update(input.getBytes());
1137byte[] output = md.digest();
1138System.out.println();
1139System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));
1140input = "abc";
1141md.update(input.getBytes());
1142output = md.digest();
1143System.out.println();
1144System.out.println("SHA1(\""+input+"\") = " +bytesToHex(output));
1145input = "abcdefghijklmnopqrstuvwxyz";
1146md.update(input.getBytes());
1147output = md.digest();
1148System.out.println();
1149System.out.println("SHA1(\"" +input+"\") = " +bytesToHex(output));
1150System.out.println(""); }
1151catch (Exception e)
1152{
1153System.out.println("Exception: " +e);
1154}
1155}
1156
1157public static String bytesToHex(byte[] b)
1158 {
1159char hexDigit[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
1160StringBuffer buf = new StringBuffer();
1161for (int j=0; j<b.length; j++) {
1162 buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
1163buf.append(hexDigit[b[j] & 0x0f]); }
1164return buf.toString(); }
1165
1166}
1167
1168OUTPUT:
1169[root@localhost janani]# gedit SHA1.java
1170[root@localhost janani]# javac SHA1.java
1171[root@localhost janani]# java SHA1
1172Message digest object info:
1173
1174 Algorithm = SHA1
1175
1176 Provider = SUN version 1.6
1177
1178 ToString = SHA1 Message Digest from SUN, <initialized>
1179 SHA1("") = DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
1180 SHA1("abc") = A9993E364706816ABA3E25717850C26C9CD0D89D
1181 SHA1("abcdefghijklmnopqrstuvwxyz") = 32D10C7B8CF96570CA04CE37F2A19D84240D3A89
1182
1183
1184RESULT :
1185 Thus the program for message digest using SHA-1 is executed successfully.
1186
1187EX NO :11 Implement the SIGNATURE SCHEME - Digital Signature Standard
1188
1189AIM: To Write a java program to generate a signature using MD5 and RSA.
1190 ALGORITHM :
1191Sender Side Process
1192Key Generation & sending the Message
11931. Using the java built-in classes KeyPairGenerator and KeyPair pair of keys for sending the message will be generated by invoking the method getInstance(“RSAâ€) and genKeyPair( )
11942. Create the signature (MD5 with RSA) using Signature class.
11953. Message will be sent in encrypted form
1196Receiver side process
1197Signature Verification
1198PROGRAM:
1199import sun.misc.BASE64Encoder;
1200import java.security.KeyPairGenerator;
1201import java.security.KeyPair;
1202import java.security.Signature;
1203public class DSS {
1204 public static void main(String[ ] args) throws Exception
1205 {
1206 KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
1207 kpg.initialize(1024);
1208 KeyPair keyPair = kpg.genKeyPair();
1209 byte[] data = "test".getBytes("UTF8");
1210 Signature sig = Signature.getInstance("MD5WithRSA");
1211 sig.initSign(keyPair.getPrivate());
1212 sig.update(data);
1213 byte[ ] signatureBytes = sig.sign();
1214 System.out.println("Singature:" + new BASE64Encoder().encode(signatureBytes));
1215 sig.initVerify(keyPair.getPublic());
1216 sig.update(data);
1217 System.out.println(sig.verify(signatureBytes));
1218 }
1219}
1220OUTPUT:
1221[root@localhost janani]# javac DSS.java
1222[root@localhost janani]# java DSS
1223
1224Singature:cn3c+ysJJN2egwOUjPjO7rIb8zp+BMy4L2ewyGQ9wFrYgCRdX7xj0oPdAGYEaq9IpGqmTFLGKeTp
1225IUTWlG/WdOeuQUXTRN7783I0KaCjValKgjLlJjdPc6uolVIxrn50PXxpgxjagGbhYi/3FmMYbEptw
1226pBw/sMPIMmCg0OcOojU=
1227
1228true
1229
1230
1231RESULT :
1232 Thus the program for signature scheme –DSS is successfully executed.
1233EX NO 12 SECURE DATA TRANSMISSION FOR CREATING DIGITAL SIGNATURE
1234
1235Aim:
1236To provide secure data storage, secure data transmission and for creating digital signatures (GPG4Win).
1237Steps:
12381. Install GPG4Win from https://www.gpg4win.org/download.html
12392. Generate the keypair from menu Keyïƒ New key
12403. Create the secure data storage details by giving the name and mail ID.
12414. Enter the passphrase and it will generate the key
12425. Encryption
1243• Type the plain text on the Clipboard.
1244• Click Encrypt button and select the mailID for data transmission
1245• Now the message is encrypted (cipher text).
12466. Decryption
1247• Click Decrypt button and enter the passphrase.
1248• Now the message is decrypted (plain text).
1249Output
1250
12511. Create the secure data storage details by giving the name and mail ID
1252
1253
1254
1255
1256
1257
1258
1259
12602. Generate the passphrase (More than 5 character –include special character) and the key is generated.
1261
1262
1263
12643. Encryption - Enter the plain text and it is converted in to cipher text.
1265
1266
1267
1268
1269
1270
12714. Decryption – Cipher text is converted in to plain text.
1272
1273
1274
1275
1276EX.NO: 13 Setup a Honey Pot and Monitor the Honeypot on Network
1277AIM
1278 To setup a honey pot and monitor the honey pot on network
1279ALGORITHM
12801. Honey Pot is a device placed on Computer Network specifically designed to capture malicious network traffic.
12812. KF Sensor is the tool to setup as honeypot when KF Sensor is running it places a siren icon in the windows system tray in the bottom right of the screen. If there are no alerts then green icon is displayed.
12823. Download KF Sensor Evaluation Setu File from KF Sensor Website.
12834. Install with License Agreement and appropriate directory path.
12845. Reboot the Computer now.
12856. The KF Sensor automatically starts during windows boot Click Next to setup wizard.
12867. Select all port classes to include and Click Next.
12878. Send the email and Send from email enter the ID and Click Next.
12889. Select the options such as Denial of Service [DOS], Port Activity, Proxy Emulsion, Network Port Analyzer, Click Next.
128910. Select Install as System service and Click Next.
129011. Click finish.
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316EX. NO: 14 Installation of rootkits and study about the variety of options
1317AIM
1318To install rootkits and study about the variety of options.
1319STEPS
13201. Rootkit is a stealth type of malicious software designed to hide the existence of certain process from normal methods of detection and enables continued privileged access to a computer.
13212. Download Rootkit Tool from GMER website. (www.gmer.net)
13223. This displays the Processes, Modules, Services, Files, Registry, RootKit/Malwares, Autostart, CMD of local host.
13234. Select Processes menu and kill any unwanted process if any.
13245. Modules menu displays the various system files like .sys, .dll
13256. Services menu displays the complete services running with Autostart, Enable, Disable, System, Boot.
13267. Files menu displays full files on Hard-Disk volumes.
13278. Registry displays Hkey_Current_user and Hkey_Local_Machine.
13289. Rootkits/Malawares scans the local drives selected.
132910. Autostart displays the registry base Autostart applications.
133011. CMD allows the user to interact with command line utilities or Registry.
1331
1332EXECUTION
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349EX NO 15 Perform an Wireless Audit of an Access Point / Router and Decrypt WEP and WPA
1350
1351
1352Aim
1353
1354To perform an Wireless Audit of an Access Point / Router And Decrypt WEP And WPA using netstumbler tool.
1355
1356Steps:
13571. NetStumbler (Network Stumbler) is one of the Wi-Fi hacking tool which only compatible with windows, this tool also a freeware. With this program, we can search for wireless network which open and infiltrate the network. Its having some compatibility and network adapter issues.
13582. Download and install Netstumbler
13593. It is highly recommended that your PC should have wireless network card in order to access wireless router.
13604. Now Run Netstumbler in record mode and configure wireless card.
13615. There are several indicators regarding the strength of the signal, such as GREEN indicates Strong, YELLOW and other color indicates a weaker signal, RED indicates a very weak and GREY indicates a signal loss.
13626. Lock symbol with GREEN bubble indicates the Access point has encryption enabled.
13637. MAC assigned to Wireless Access Point is displayed on right hand pane.
13648. The next coloumn displays the Access points Service Set Identifier[SSID] which is useful to crack the password.
1365
1366
1367
1368Output
1369
13701. Run Netstumbler in record mode
1371
1372
1373
1374
13752. Displayed the signal strength
1376
1377
1378EX NO: 16 Demonstrate Intrusion Detection System (Ids) Using Snort
1379AIM:
1380 To demonstrate intrusion detection system using Snort
1381
1382INSTALLATION PROCEDURE
13831. Download SNORT from snort.org
13842. Install snort with or without database support.
13853. Select all the components and Click Next.
13864. Install and Close.
13875. Skip the WinPcap driver installation
13886. Add the path variable in windows environment variable by selecting new classpath.
13897. Create a path variable and point it at snort.exe variable nameïƒ path and variable valueïƒ c:\snort\bin.
13908. Click OK button and then close all dialog boxes.
13919. Open command prompt and type the commands.
1392
1393STEPS
1394SNORT can be configured to run in three modes:
13951. Sniffer mode 2. Packet Logger mode 3. Network Intrusion Detection System mode
1396Sniffer mode
1397i. snort –v ïƒ Print out the TCP/IP packets header on the screen
1398ii. snort –vd ïƒ Show the TCP/IP ICMP header with application data in transit.
1399Packet Logger mode
1400i. snort –dev –l c:\log ïƒ snort will automatically know to go into packet logger mode, it collects every packet it sees and places it in log directory.
1401ii. snort –dev –l c:\log –h ipaddress/24 ïƒ This rule tells snort that you want to print out the data link and TCP/IP headers as well as application data into the log directory.
1402iii. snort –l c:\log –b ïƒ This is binary mode logs everything into a single file.
1403Network Intrusion Detection System mode
1404i. snort –d c:\log –h ipaddress/24 –c snort.conf ïƒ This is a configuration file applies rule to each packet to decide it an action based upon the rule type in the file.
1405ii. snort –d –h ipaddress/24 –l c:\log –c snort.conf ïƒ This will configure snort to run in its most basic NIDS form, logging packets that trigger rules specifies in the snort.conf
1406
1407
1408
1409C:\Snort\bin\snort –v
1410
1411
1412C:\Snort\bin\snort –vd
1413
1414
1415C:\Snort\bin\ snort –dev –l c:\log
1416
1417C:\Snort\bin\snort –dev –l c:\log –h ipaddress/24
1418
1419
1420C:\Snort\bin\snort –l c:\log –b
1421
1422
1423snort –d –h ipaddress/24 –l c:\log –c snort.conf
1424
1425
1426
1427IMPLEMENTATION OF ELGAMAL ALGORITHM
1428AIM:
1429 To implement Elgamal algorithm in Java.
1430ALGORITHM
1431Key Generation
1432d) Generate large prime p and generator g of the multiplicative Group Z p∗ pf of the integers modulo p.
1433e) Select a random integer a, 1 ≤ a ≤ p − 2, and compute ga mod p.
1434f) A’s Public key is (p, g, ga); A’s Private key is a.
1435Encryption
14364. Obtain A’s authentic public key (p, g, ga).
14375. Represent the message as integers m in the range {0, 1, . . . , p − 1}.
14386. Select a random integer k, 1 ≤ k ≤ p − 2.
14397. Compute γ = gk mod p and δ = m ∗ (ga)k.
14408. Send ciphertext c = (γ, δ) to A
1441Decryption
1442b) Use private key a to compute (γp−1−a) mod p. Note: γp−1−a = γ−a = a−ak
1443c) Recover m by computing (γ−a) ∗ δ mod p.
1444PROGRAM:
1445import java.math.*;
1446import java.util.*;
1447import java.security.*;
1448import java.io.*;
1449
1450public class ElGamal
1451{
1452 public static void main(String[] args) throws IOException
1453 {
1454 BigInteger p, b, c, secretKey;
1455 Random sc = new SecureRandom();
1456 secretKey = new BigInteger("12345678901234567890");
1457 //
1458 // public key calculation
1459 //
1460 System.out.println("secretKey = " + secretKey);
1461 p = BigInteger.probablePrime(64, sc);
1462 b = new BigInteger("3");
1463 c = b.modPow(secretKey, p);
1464 System.out.println("p = " + p);
1465 System.out.println("b = " + b);
1466 System.out.println("c = " + c);
1467 //
1468 // Encryption
1469 //
1470 System.out.print("Enter your Big Number message -->");
1471 String s = Tools.getString();
1472 BigInteger X = new BigInteger(s);
1473 BigInteger r = new BigInteger(64, sc);
1474 BigInteger EC = X.multiply(c.modPow(r, p)).mod(p);
1475 BigInteger brmodp = b.modPow(r, p);
1476 System.out.println("Plaintext = " + X);
1477 System.out.println("r = " + r);
1478 System.out.println("EC = " + EC);
1479 System.out.println("b^r mod p = " + brmodp);
1480 //
1481 // Decryption
1482 //
1483 BigInteger crmodp = brmodp.modPow(secretKey, p);
1484 BigInteger d = crmodp.modInverse(p);
1485 BigInteger ad = d.multiply(EC).mod(p);
1486 System.out.println("\n\nc^r mod p = " + crmodp);
1487 System.out.println("d = " + d);
1488 System.out.println("Alice decodes: " + ad);
1489
1490 }
1491}
1492OUTPUT:
1493Input: HELLO
1494cipher:8c2e699772c14496bc82400d11decae4f662fe90864e8c553b78136679fcdfaa60c378b5 69083525c021fcf77e40f661525da56ed4133df92848aaba2459dff5
1495 plain : HELLO
1496
1497
1498
1499
1500
1501
1502Viva Questions
15031. What is Security?
1504 Security is “the quality or state of being secure-to be free from dangerâ€.
15052. What are the characteristics of Information Security?
1506 a)Availability b) Accuracy c) Authenticity d) Confidentiality e) Integrity f) Utility g) Possession
15073. What is Network Security?
1508It is the implementation of alarm and intrusion systems to make system owners aware of ongoing compromises.
15094. Define integrity and nonrepudiation.
1510Integrity: Service that ensures that only authorized person able to modify the message.
1511Nonrepudiation: It helps to prove that the person who denies the transaction is true or false.
15125. What is a threat?
1513Threat is an object, person or other entity that represents a constant danger to an asset.
15146. What are Hackers?
1515Hackers are people who use and create computer software for enjoyment or to gain access to information illegally.
15167. What is a brute force attack?
1517Trying every possible combination of options of password.
15188. What are sniffers?
1519Sniffers are programs or device that can monitor data traveling over an network.
15209. What are the protocols used in Secure Internet Communication?
1521a)S-HTTP(Secure Hypertext Transfer Protocol)b) SSL(Secure Socket Layer) c) SSL Record Protocol d) Standard HTTP
152210. Specify the four categories of security threads?
1523 Interruption Interception Modification Fabrication
152411. Explain active and passive attack with example
1525Passive attack: Monitoring the message during transmission. Eg: Interception
1526Active attack: It involves the modification or creation of false data stream. E.g.: Fabrication.
152712.Differentiate symmetric and asymmetric encryption.
1528Symmetric : Both encryption and decryption are performed using the same key. Eg: DES, AES
1529Asymmetric : Encryption and decryption performed using two keys. Eg: RSA, ECC
153013.Define cryptanalysis.
1531It is a process of attempting to discover the key or plaintext or both.
153214.Compare stream cipher with block cipher
1533Stream cipher: Processes the input stream continuously and producing one element at a time. Block cipher: Processes the input one block of elements at a time producing an output block for each input block. Example: DES
1534
153515. Define security mechanism.
1536It is process that is designed to detect prevent, recover from a security attack. Ex: Encryption
153716. Why network need security?
1538When systems are connected through the network, attacks are possible during transmission time.
153917.Define Encryption
1540The process of converting from plaintext to cipher text.
154118.Specify the components of encryption algorithm.
1542Plaintext 2. Encryption algorithm 3. Secret key 4. Cipher text 5. Decryption algorithm
154319.Define cryptography.
1544It is a science of writing Secret code using mathematical techniques. The many schemes used for enciphering constitute the area of study known as cryptography.
154520.List and briefly define types of cryptanalytic attacks based on what is known to the attacker.
1546Cipher text only Known plaintext Chosen plaintext Chosen cipher text Chosen text
154721. Compare Substitution and Transposition techniques.
1548 Substitution technique -plaintext letters are replaced by other letter or by number or symbols.
1549Transposition technique - Permutation on the plaintext letters.
155022.Briefly define the Caesar cipher.
1551The Caesar cipher involves replacing each letter of the alphabet with the letter standing three places further down the alphabet.
155223. Briefly define the monoalphabetic cipher.
1553A monoalphabetic cipher maps from a plain alphabet to cipher alphabet. Here a single
1554cipher alphabet is used per message.
155524.What is the difference between a mono alphabetic cipher and a poly alphabetic
1556cipher?
1557Mono alphabetic cipher: Here a single cipher alphabet is used.
1558Poly alphabetic cipher: Here a set of related mono alphabetic substitution rules is used.
155925.What are the design parameters of Feistel cipher network?
1560Block size Key size Number of Rounds Subkey generation algorithm Round function
1561Fast software Encryption/Decryption Ease of analysis
156226. Give the five modes of operation of Block cipher.
15631. Electronic Codebook(ECB) 2. Cipher Block Chaining(CBC) 3. Cipher Feedback(CFB) 4. Output Feedback(OFB) 5. Counter(CTR)
156427.Define Multiple Encryption.
1565It is a technique in which the encryption is used multiple times. Eg: Double DES, Triple DES
156628. Why is it important to study feistel cipher?
1567This cipher can be used to approximate the simple substitution cipher by utilizing the concept of a product cipher, which is the performing of two or more basic ciphers in sequence in such a way that the final result or product is cryptographically stronger than any of the component ciphers.
156829.Briefly define the playfair cipher.
1569The best-known multiple-letter encryption cipher is the playfair, which treats diagrams in the plain text as single units and translates these units into cipher text diagrams.
157030.Why is it not practical to use an arbitrary reversible substitution cipher?
1571An arbitrary reversible cipher for a large block size is not practical, however, from an implementation and performance point of view. Here the mapping itself is the key.
157231.Specify the design criteria of block cipher.
1573 Number of rounds Design of the function F Key scheduling
157432.What is the purpose of the S-boxes in DES?
1575Each row of an S-box defines a general reversible substitution. It consists of a set of eight S-boxes, each of which accepts 6 bits as input and produces 4 bits as output.
157633. How many keys are used in triple encryption?
1577Tuchman proposed a triple encryption method that uses only two keys.
157834.What is Triple Encryption? How many keys are used in triple encryption?
1579Triple Encryption is a technique in which encryption algorithm is performed three times
1580using three keys.
158135.Differentiate public key and conventional encryption.
1582The same algorithm with the same Key is used for encryption and decryption.
1583One algorithm is used for encryption and decryption and decryption with a pair of keys, one for encryption and another for decryption
158436.What are roles of public and private key?
1585The two keys used for public-key encryption are referred to as the public key and the private key. The public key is used for encryption purpose and the private key is used in the decryption side.
158637. State any three hash algorithm.
1587 • MD5 (Message Digest version 5) algorithm. • SHA_1 (Secure Hash Algorithm).RIPEMD_160
158838.What you meant by MAC?
1589MAC is Message Authentication Code. It is a function of message and secret key which produce a fixed length value called as MAC.
159039.What are the services provided by PGP services ?
1591• Digital signature • Message encryption • Compression • E-mail compatibility
159240.Name any cryptographic keys used in PGP.
1593a) One-time session conventional keys. b) Public keys. c) Private keys. d) Pass phrase based conventional keys.
159441. What are the function areas of IP security?
1595• Authentication • Confidentiality • Key management
159642. List the steps involved in SSL record protocol
15971. Application data as input and fragments it. 2. Apply lossless Compression algorithm. 3. Compute MAC for compressed data. 4. Encryption of MAC and compression message.
159843. List the 3 classes of intruder
1599Classes of Intruders 1) Masquerader 2) Misfeasor 3) Clandestine user
160044. What are the schemes used in Password protection?
1601 One way encryption Store the encrypted form of password Access control
1602 Accessible only by the authorized user.
160345. What is Intrusion Detection?
1604Detected based on the behavior.
160546.Define Firewall.
1606Firewall defines a single choke point that keeps unauthorized users out of the protected network.
1607
160847. Briefly explain Diffie-hellman key exchange
1609The purpose of the algorithm is to enable two users to exchange a key securely that can then be used for subsequent encryption of messages. The algorithm is limited to the exchange of keys.
161048.What is the difference between SSL connection and an SSL session?
1611A Connection is a transport that provides a suitable type of service. For SSL, such connections are peer-to-peer relationships. An SSL session is an association between a client and a server.
161249. What is E-mail Spoofing?
1613 It is the process of sending an e-mail with a modified field.
161450. What is PKI?
1615 Public Key Infrastructure is an integrated system of software, encryption methodologies and
1616 legal agreements that can be used to support the entire information infrastructure of an
1617 organization.
161851. What is the use of Digital Certificates?
1619 Digital Certificates ensures the confidentiality of Internet Communications and transactions.
162052.What is malicious code?
1621 Programs, which are designed to damage, destroy, or deny service to the target system.
1622 53. What is DoS ?
1623Denial-of-service(DoS) – attacker sends a large number of connection or information requests
162454.Define steganography
1625 Hiding the message into some cover media. It conceals the existence of a message.
162655. What are the Public-Key cryptography Applications ?
1627 encryption/decryption (provide secrecy) digital signatures (provide authentication)
1628 key exchange (of session keys)
162956. What is hashing?
1630The idea behind hashing is that some data either has no inherent ordering (such as images) or is expensive to compare.
163157. What is public, protected, private in C++?
1632 Public, protected and private are three access specifier in C++.
1633 Public data members and member functions are accessible outside the class.
1634 Protected data members and member functions are only available to derived classes.
163558. Can a lock be acquired on a class?
1636 Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.
163759.What is the purpose of finalization?
1638 The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
163960.Name primitive Java types.
1640 The primitive types are byte, char, short, int, long, float, double, and Boolean.
164161.Which class should you use to obtain design information about an object?
1642 The Class class is used to obtain information about an object's design.
164362.Which is the entry point of C or C++ program ?
1644 Main( )
164563.Which operator allow to define the member functions of a class outside the class?
1646 Scope resolution operator
164764.What is the default access level assigned to members of a class ?
1648 Private
164965.What is honeypot?
1650 A honeypot is a computer system that is set up to act as a decoy to lure cyber attackers, and to detect, deflect or study attempts to gain unauthorized access to information systems.
165166.What's the current version of PGP?
1652 There are three different "product-lines" for PGP: PGP 2.x, PGP 5.x and higher, and GNU Privacy Guard.
165367.What is Chinese Remainder theorem ?
1654The Chinese remainder theorem is a result about congruences in number theory and its generalizations in abstract algebra.
165568. What is Miller Rabin technique ?
1656The probabilistic primality test used most in practice today is the Miller-Rabin test
165770 . What is the importance of prime numbers in cryptography ?
1658 Encryption and Authentication algorithms use prime numbers. In the RSA algorithm calculations are made modulo n, where n is a product of two large prime numbers p and q.
165971. What is java cryptographic extension ?
1660 Java Cryptography Extensions (JCE) provide a framework and implementation for encryption, key generation, and authentication algorithms.
166172. What are the services provided by java cryptographic extension ?
1662 DES and Triple DES Blowfish CBC (CFB) and Output Feedback (OFB) MD5 and SHA1 h
166373.What are the classes provided by java cryptographic extension ?
1664 Cipher., cipherInputstream , keyGenerator etc
166574. What is the purpose of MD5 ?
1666The MD5 message-digest algorithm is a widely used cryptographic hash function that produces a 128-bit hash value.
166775. what is the purpose of ctype.h ?
1668 All character related functions are available in this header
166976. What is SHA- 1 ?
1670SHA-1 produces a 160-bit (20-byte) hash value. A SHA-1 hash value is typically expressed as a hexadecimal number, 40 digits long.
167177. What are the applications of SHA- 1 ?
1672SHA-1 forms part of several widely used security applications and protocols, including TLS and SSL, PGP, SSH, S/MIME, and IPsec.
167378. Which crytptographic protocol is used to secure HTTP protocol?
1674Trasnport layer security (TSL)
167579. what is the other name for secret key encryption ?
1676 Private key encryption.
167780. What is the purpose of Kerberos?
1678 Used in Secret key encryption.
167981. what is the purpose of <string.h> ?
1680All string related functions are defined here.
168182. what is the difference between main() in C and C++?
1682In c++ main() will return an integer value to O.S
168383. For symmetric key encryption how many keys are needed for n –persons?
1684 n C 2
168584. what is the use of key word final before a variable ?
1686 The value of the variable can’ be changed.
168785.What is the formula for encryption and decryption in RSA ?
1688 C = Me mod n P = C d mod n
168986. What is the purpose of using void before a function ?
1690 To indicate that the function will return nothing.
169187. Is Ceaser cipher of key value 3 additive ?
1692 Yes it is additive.
169388. What are MD2, MD4, and MD5 ?
1694 Hashing algorithms
169589. What are smart cards?
1696smart cards : Smart cards help businesses evolve and expand their products and services
169790. What is Difference between discretionary access control and mandatory access control?
1698DAS (discretionary access control) is used by itself according to it it is access and comtrolled while mas it has to be compulsory give the access control.
169991. What is the difference between = and = = ?
1700 = assignment operator = = relational operator
1701 92. How many keys are used in Triple DES ?
1702 3
170393. How do you use RSA for both authentication and secrecy?
1704 For authentication one can encrypt the hash (MD5/SHA) of the data with his private key.
1705 secrecy is achieved by encrypting the data with the public key of the target user.
170694. Explain How do we do authentication with message digest(MD5)? (Usually MD is used for finding tampering of data)
1707The unique number will be generated by MD5, if it is tamped with someone, the value will be changed so you know you are tampered
170895. What are the types of keys used in Secret key encryption ?
1709 Weak keys, semi-weak keys , demi-semi – weak keys.
171096. What are the ways to improve DES ?
1711 Extend DES to 128 - bits
171297.Compare C , C++ and java.
1713 C- Procedural oriented language C++ - OOPs- java – OOPS
171498. Mention any one traditional cipher
1715 Caesar.
171699. What is the limitation of Hill cipher ?
1717 But vulnerable to known-plaintext attack
1718100. What is confusion ?
1719 Statistics of the ciphertext and the value of the encryption keys