You are on page 1of 8

Cryptography Techniques

Assignment 1
Name: Agrima Khanna
Roll Number: 2019UCO1511

1. Construct a Playfair matrix with the key algorithm.


Answer:
A L G O R

I/J T H M B

C D E F K

N P Q S U

V W X Y Z

2.Using the given Playfair matrix, Encrypt this message:


I only regret that I have but one life to give for my country.

Answer:

IO NL YR EG RE TX TH AT IH AV EB UT ON EL IF ET OG IV EF

MA PA ZO QH GJ HW HM LI TM IA JH PB AS DG MC DH RO CA FJ
OR MY CO UN TR YX

RA FO FA NP BL ZY

3. Encrypt the message “meet me at the usual place at ten rather than eight o clock”.

using the Hill cipher with the key ( 7 3 ) . Show your calculations and the result.
25
Answer:

Alphabet:

A B C D E F G H I J K L M

0 1 2 3 4 5 6 7 8 9 10 11 12

N O P Q R S T U V W X Y Z

13 14 15 16 17 18 19 20 21 22 23 24 25

K= (73 ) => 2*2 matrix


25

P=

ME ET ME AT T H EU SU AL PL AC

12 4 4 19 12 4 0 19 19 7 4 20 18 20 0 11 15 11 02

EA TT EN RA TH ER TH AN EI GH

40 19 19 4 13 17 0 19 7 4 17 19 7 0 13 48 67
TO CL OC KA

19 14 2 11 14 2 10 0

C = KP mod 26

1. ( 7 3 )( 12 ) mod 26 = ( 96 ) mod 26 = ( 18 ) = ( S )
2 5 4 44 18 S

2. ( 7 3 )( 4 ) mod 26 = ( 85 ) mod 26 = ( 7 ) = ( H )
2 5 19 103 25 Z

3. ( 7 3 )( 12 ) mod 26 = ( 96 ) mod 26 = ( 18 ) = ( S )
2 5 4 44 18 S

4. ( 7 3 )( 0 ) mod 26 = ( 57 ) mod 26 = ( 5 ) = ( F )
2 5 19 95 17 R

5. ( 7 3 )( 19 ) mod 26 = ( 154 ) mod 26 = ( 24 ) = ( Y )


2 5 7 73 21 V

6. ( 7 3 )( 4 ) mod 26 = ( 88 ) mod 26 = ( 10 ) = ( K )
2 5 20 108 4 E

7. ( 7 3 )( 18 ) mod 26 = ( 186 ) mod 26 = ( 4 ) = ( E )


2 5 20 136 6 G

8. ( 7 3 )( 0 ) mod 26 = ( 33 ) mod 26 = ( 7 ) = ( H )
2 5 11 55 3 D

9. ( 7 3 )( 15 ) mod 26 = ( 138 ) mod 26 = ( 8 ) = ( I )


2 5 11 85 7 H
10. ( 7 3 )( 0 ) mod 26 = ( 6 ) mod 26 = ( 6 ) = ( G )
2 5 2 10 10 K

11. ( 7 3 )( 4 ) mod 26 = ( 28 ) mod 26 = ( 2 ) = ( C )


2 5 0 8 8 I

12. ( 7 3 )( 19 ) mod 26 = ( 190 ) mod 26 = ( 8 ) = ( I )


2 5 19 133 3 D

13. ( 7 3 )( 4 ) mod 26 = ( 67 ) mod 26 = ( 15 ) = ( P )


2 5 13 73 21 V

14. ( 7 3 )( 17 ) mod 26 = ( 119 ) mod 26 = ( 15 ) = ( P )


2 5 0 34 8 I

15. ( 7 3 )( 19 ) mod 26 = ( 154 ) mod 26 = ( 24 ) = ( Y )


2 5 7 73 21 V

16. ( 7 3 )( 4 ) mod 26 = ( 79 ) mod 26 = ( 1 ) = ( B )


2 5 17 93 15 P

17. ( 7 3 )( 19 ) mod 26 = ( 154 ) mod 26 = ( 24 ) = ( Y )


2 5 7 73 21 V

18. ( 7 3 )( 0 ) mod 26 = ( 39 ) mod 26 = ( 13 ) = ( N )


2 5 13 65 13 N

19. ( 7 3 )( 4 ) mod 26 = ( 52 ) mod 26 = ( 0 ) = ( A )


2 5 8 48 22 W
20. ( 7 3 )( 6 ) mod 26 = ( 63 ) mod 26 = ( 11 ) = ( L )
2 5 7 47 21 V

21. ( 7 3 )( 19 ) mod 26 = ( 175 ) mod 26 = ( 19 ) = ( T )


2 5 14 108 4 E

22. ( 7 3 )( 2 ) mod 26 = ( 47 ) mod 26 = ( 21 ) = ( V )


2 5 11 59 8 H

23. ( 7 3 )( 14 ) mod 26 = ( 104 ) mod 26 = ( 0 ) = ( A )


2 5 2 38 12 M

24. ( 7 3 )( 10 ) mod 26 = ( 70 ) mod 26 = ( 18 ) = ( S )


2 5 0 20 20 U
Encrypted Text: sshz ss fr yvk eeghd ihgkc ii dpv piyvbp yvnn awlvt e vhams u

4. Using the Vigenère cipher, encrypt the word “cryptographic” using the word “eng”.
Answer:
Key: engengengenge

Plaintext: cryptographic

Alphabet:

A B C D E F G H I J K L M

0 1 2 3 4 5 6 7 8 9 10 11 12
N O P Q R S T U V W X Y Z

13 14 15 16 17 18 19 20 21 22 23 24 25

Key (Ki) 4 13 6 4 13 6 4 13 6 4 13 6 4

Plaintext (Pi) 2 17 24 15 19 14 6 17 0 15 7 8 2

P i + Ki 6 30 30 19 32 20 10 30 6 19 20 14 6

Ciphertext 6 4 4 19 6 20 10 4 6 19 20 14 6
(Ci = (Pi + Ki) mod 26)

Ciphertext: geetgukegtuog

5. Write a C/C++/Java/python program that can encrypt and decrypt using the general
Caesar cipher.
Answer:
CODE:
#include <iostream>
using namespace std;
string encrypt(string text,int n)
{
string result = "";
for (int i=0;i<text.length();i++)
{
if (isupper(text[i]))
result += char(int(text[i]+n-65)%26 +65);

else
result += char(int(text[i]+n-97)%26 +97);
}
return result;
}
int main()
{
string text;
int num;
cout<<"Main menu\n1.Encrypt\n2.Decrypt\nChoice: ";
cin>>num;
switch(num)
{
case 1:
cout<<"\nEnter plaintext to be encrypted: ";
cin>>text;
cout << "\nCiphertext: " << encrypt(text,3);
break;
case 2:
cout<<"\nEnter ciphertext to be decrypted: ";
cin>>text;
cout << "\nPlaintext: " << encrypt(text,23);
break;
default: cout<<"\nEnter valid number.";
}
return 0;
}
OUTPUT:

You might also like