write a python program that ciphers a plain text message using double transposition scheme and vise versa. The program should accept five tuples of input: plain text, row, column, permutation of row and columns.
Pain Text: attack at dawn
Matrix Row Size: 5
Matrix Column Size: 3
Row Permutation Order: 3,5,1,4,2
Column permutation order: 1,3,2
Encrypted Text:
Solution:
...............................................................................................................................................................
Please find below instructions, code and snipptet
Instructions :
The indentation may not get presevred in check editor, so please check indentation when you paste. Attached screenshot of code to help you with that
Code
## python 2
text = raw_input("Enter Text : ") # take user input
encOrDec = int(input("Enter 0 to encrypt and 1 to decrypt :
"))
nRowsMat = int(input("Matrix row size : "))
nColsMat = int(input("Matrix col size : "))
RowPermutationOrder = input("Row permutation order (python list) :
")
ColPermutationOrder = input("Column permutation order (python list)
: ")
msgMatrix =[] # will hold initial message
for i in range (0,nRowsMat):
temp=[]
for j in range (0,nColsMat):
if(nColsMat*i+j < len(text)):
if(text[nColsMat*i+j] == ' '): # fill initialmatrix with the
message rowwise, replalace spaces with 'x'
temp.append('x')
else:
temp.append(text[nColsMat*i+j])
else:
temp.append('x')
msgMatrix.append(temp)
rowPermutedMatrix = []
for row in RowPermutationOrder: # for each row
rowPermutedMatrix.append(msgMatrix[row-1]) # permute the rows
colPermutedMatrix = [['0']*nColsMat for _ in range(nRowsMat)] # initalize variable to store matrix after colPermutation
startCol=-1
for col in ColPermutationOrder:
colVals=list([])
for i in range(0,nRowsMat):
colVals.append(rowPermutedMatrix[i][col-1]) # extract value of
current column
startCol = startCol + 1
for i in range(0,nRowsMat):
colPermutedMatrix[i][startCol] = colVals[i] # put the first column
in permuted matrix
cipheredMsg =''
for i in range(0,nRowsMat):
for j in range(0, nColsMat):
if(encOrDec==1 and colPermutedMatrix [i][j] == 'x'): # if user is
deciphering reverse 'x' with spaces
colPermutedMatrix [i][j] = ' '
cipheredMsg = cipheredMsg + colPermutedMatrix [i][j]
print("Output message is : ")
print(cipheredMsg)
Snippets of Code and Output
write a python program that ciphers a plain text message using double transposition scheme and vise...
Please write in Java in Jgrasp check code before posting Please
write in Java in Jgrasp check code before posting
Please write in Java in Jgrasp check code before posting, will
give thumbs up
FOP- 2. Write a program that ciphers a plain text message using double transposition scheme and vice versa. [50 Marks) The program should accept five tuples of input: plain text, row, column, permutation of row and columns. An example of encrypted text for the plain text...