Question: 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
NUM_ROWS =6
NUM_COLS =4
ROW_TRANSPOSITION =[3,5,0,2,1,4]
COL_TRANSPOSITION =[3,2,0,1]
def encrypt(text):
table =[['' for _ in range(NUM_COLS)] for _ in range(NUM_ROWS)]
index =0
for i in range(NUM_ROWS):
for j in range(NUM_COLS):
if index len(text):
table [i][j]= text[index]
index +=1
else:
table[i][j]='' # Padding if text length is less than table size
# Transpose rows
table =[table [i] for i in ROW_TRANSPOSITION]
# Transpose columns
table =[list (row [i] for i in COL_TRANSPOSITION) for row in table]
# Output encrypted text
for row in table:
print("".join(row), end='')
def decrypt(text):
table =[['' for _ in range(NUM_COLS)] for _ in range(NUM_ROWS)]
index =0
for i in ROW_TRANSPOSITION:
for j in COL_TRANSPOSITION:
table index]
index +=1
# Reverse column transposition
table =[list(row[i] for i in sorted(range(NUM_COLS), key=lambda x: COL_TRANSPOSITION.index(x))) for row in table]
# Reverse row transposition
table table [i] for i in ROW_TRANSPOSITION]
# Output decrypted text
for row in table:
print("'.join(row), end='')
def main():
if len(sys.argv)!=3 or sys.argv[1] not in ['-e','-d']:
print("Usage: python
script.py [-e |-d]=r
 I have python code I need help with. When decrypting, it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!