Sei sulla pagina 1di 5

JSS ACADEMY OF TECHNICAL EDUCATION, BANGALORE-560060

DEPARTMENTOF COMPUTER SCIENCE AND ENGINERING

ACADEMIC YEAR: 2018(EVEN SEM)

SUBJECT: CRYPTOGRAPHY, NETWORK SECURITY AND CYBER LAW

ASSIGNMENT 2

NAME:

HAREESHA G : 1JS16CS406 MAHESH J R : 1JS16CS411

SURYA G :

1JS16CS426

TOPIC: IMPLEMENTATION OF HILL CIPHER IN PYTHON

NAME OF THE FACULTY INCHARGE: Mr. Rohitaksha K

MARKS OBTAINED:

What is Cryptography?

Cryptography is associated with the process of converting ordinary plain text into unintelligible text and vice-versa. It is a method of storing and transmitting data in a particular form so that only those for whom it is intended can read and process it. Cryptography not only protects data from theft or alteration, but can also be used for user authentication.

Hill cipher

Hill cipher is a substitution cipher based on linear algebra. Invented by Lester S. Hill in 1929, it was the first polygraphic cipher in which it was practical (though barely) to operate on more than three symbols at once. The

following discussion assumes an elementary knowledge of matrices. Each letter is

represented by a number modulo 26. Often the simple scheme A = 0, B = 1,

= 25 is used, but this is not an essential feature of the cipher. To encrypt a message,

each block of n letters (considered as an n-component vector) is multiplied by an invertible n × n matrix, against modulus 26. To decrypt the message, each block is multiplied by the inverse of the matrix used for encryption.

, Z

The matrix used for encryption is the cipher key, and it should be chosen randomly from the set of invertible n × n matrices (modulo 26). The cipher can, of course, be adapted to an alphabet with any number of letters; all arithmetic just needs to be done modulo the number of letters instead of modulo 26.

Encryption

Plain text: HELP

Decryption

Cipher text: HIAT

Implementation of Hill Cipher in Python

def hill(code):

decryptionKey = [[3,3],

[2,5]]

code = code.lower() output = [[0],[0]] counter = 0 for character in code:

number = ord(character) - 97 output[counter][0] = number counter += 1

result = [[0],

[0]]

for i in range(len(decryptionKey)):

for j in range(len(output[0])):

for k in range(len(output)):

result[i][0] += decryptionKey[i][k] * output[k][j]

unCiphered = "" for r in result:

numeric_letter = r[0] % 26 val = chr(numeric_letter + 97) unCiphered = unCiphered + val

return unCiphered

def main():

code = input("Enter ciphertext: ") print plaintext = ""

while(code):

ciphertext = code[:2] code = code[2:] plaintext = plaintext + hill(ciphertext) print(plaintext) print

main()

Output