Classical-Cryptography - PowerPoint PPT Presentation

About This Presentation
Title:

Classical-Cryptography

Description:

Classical-Cryptography_Classical-Cryptography_Classical-Cryptography – PowerPoint PPT presentation

Number of Views:0
Date added: 22 January 2025
Slides: 7
Provided by: Badlit
Tags:

less

Transcript and Presenter's Notes

Title: Classical-Cryptography


1
Classical Cryptography - Hill Cipher
Hill cipher is a polygraphic substitution
cipher based on linear algebra. Each letter
is represented by a number modulo 26. Often
the simple scheme A 0, B 1, ..., Z 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 x n matrix,
against modulus 26. To decrypt the message,
each block is multiplied 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 n x n
matrices (modulo 26). Examples Input
Plaintext ACT Key GYBNQKURP Output
Ciphertext POH Input Plaintext GFG
2
Key HILLMAGIC Output Ciphertext
SWK Encryption We have to encrypt the message
ACT (n3).The key is GYBNQKURP which can be
written as the nxn matrix
6 24 1 13 16 10 20 17 15 The message ACT is
written as vector
o 2 19
The enciphered vector is given as
3
which corresponds to ciphertext of POH
Decryption To decrypt the message, we turn the
ciphertext back into a vector, then simply
multiply by the inverse matrix of the key matrix
(IFKVIVVMI in letters).The inverse of the matrix
used in the previous example is
For the previous Ciphertext POH
4
which gives us back ACT. Assume that all the
alphabets are in upper case. Below is the
implementation of the above idea for n3.
Python3 code to implement Hill Cipher
keyMatrix 0 3 for i in range(3)
Generate vector for the message messageVector
0 for i in range(3)
Generate vector for the cipher cipherMatrix
0 for i in range(3)
Following function generates the key
matrix for the key string def getKeyMatrix(key)
k 0
for i in range(3) for j in range(3)
keyMatrixij ord(keyk) 65
5
k 1
Following function encrypts the message def
encrypt(messageVector) for i in range(3) for j
in range(1) cipherMatrixij 0 for x in
range(3) cipherMatrixij (keyMatrixix
messageVectorxj) cipherMatrixij
cipherMatrixij 26 def HillCipher(message,
key) Get key matrix from the key string
getKeyMatrix(key) Generate vector for the
message for i in range(3) messageVectori0
ord(messagei) 65 Following function
generates the encrypted vector
encrypt(messageVector)
6
Generate the encrypted text
from the encrypted vector CipherText
for i in range(3) CipherText.append(chr(cipher
Matrixi0 65)) Finally print the
ciphertext print("Ciphertext ",
"".join(CipherText)) Driver Code def main()
Get the message to be encrypted message
"ACT" Get the key key "GYBNQKURP" HillCiphe
r(message, key) if name " main "
main()
Write a Comment
User Comments (0)
About PowerShow.com