NIS EXP9
NIS EXP9
9
Aim: Write a program to implement Simple Columnar transposition
Technique
Introduction:
Example:
Consider the plain text hello world, and let us apply the simple columnar
transposition technique as shown below
The plain text characters are placed horizontally and the cipher text is created with
vertical format as : holewdlo lr. Now, the receiver has to use the same table to
decrypt the cipher text to plain text.
Program:
# Python3 implementation of
# Columnar Transposition
import math
key = "HACK"
# Encryption
def encryptMessage(msg):
cipher = ""
# track key indices
k_indx = 0
msg_len = float(len(msg))
msg_lst = list(msg)
key_lst = sorted(list(key))
# calculate column of the matrix
col = len(key)
for j in range(row):
dec_cipher[j][curr_idx] = msg_lst[msg_indx]
msg_indx += 1
k_indx += 1
null_count = msg.count('_')
if null_count > 0:
return msg[: -null_count]
return msg
# Driver Code
msg = "Geeks for Geeks"
cipher = encryptMessage(msg)
print("Encrypted Message: {}".
format(cipher))
print("Decryped Message: {}".
format(decryptMessage(cipher)))
Output:
Conclusion: