Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have python code I need help with. When decrypting, it is just returning whatever I am inputting. It encrypts and decrypts by file input.
I have python code I need help with. When decrypting, it is just returning whatever I am inputting. It encrypts and decrypts by file input. Usage is "python script.py e input.txt for encryption and d for decryption. It is a double transposition cipher, need help fixing it to where it outputs the proper decrypted message. Encryption works just fine.
# Global constants
NUMROWS
NUMCOLS
ROWTRANSPOSITION
COLTRANSPOSITION
def encrypttext:
table for in rangeNUMCOLS for in rangeNUMROWS
index
for in rangeNUMROWS:
for in rangeNUMCOLS:
if index lentext:
table textindex
index
else:
tableij # Padding if text length is less than table size
# Transpose rows
table table i for in ROWTRANSPOSITION
# Transpose columns
table list row i for in COLTRANSPOSITION for row in table
# Output encrypted text
for row in table:
printjoinrow end
def decrypttext:
table for in rangeNUMCOLS for in rangeNUMROWS
index
for in ROWTRANSPOSITION:
for in COLTRANSPOSITION:
table index
index
# Reverse column transposition
table listrowi for in sortedrangeNUMCOLS keylambda x: COLTRANSPOSITION.indexx for row in table
# Reverse row transposition
table table i for in ROWTRANSPOSITION
# Output decrypted text
for row in table:
printjoinrow end
def main:
if lensysargv or sysargv not in ed:
printUsage: python
script.py e d
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started