Question: Python: im trying to get the decode function to return the original value of Python however, it just reprints the letters that were encoded. updated
def decode(data, key): table= generateKeyTable | data= data.upper() i=0 result="" for c in data: rIndex=ord(key[i])-ord('A') cIndex=table[rIndex].index(c) result += table[rIndex][cIndex] i=(i+1) %len(key) return result print(encode("PYTHON", "CS")) print(decode("RQVZQF", "CS")) 1 10 Eldef generateKey Table(): table = [] letters "ABCDEFGHIJKLMNOPQRSTUVW.DEYZ" #create the table by appending multiple lists to the original list for i in range(26): row - [""]. 26 table.append(row) #add letters to the table for y in range(26): for x in range(26): table[x][y] - letters[x] ch - letters[@] #get first letter in string letters - letters[1:) #remove the first letter in the string letters + ch #add the first letter to the end of the string return table Solu Eidef encode(data, key): table generateKeyTable() data-data.upper() Prop i-e result for c in data: rIndex- ord(c) - ord('A') cIndexword(key[1])- ord('A') result +- table[rIndex][index] 1-(1+1) Xlen(key) return result Final - Microsoft Visual Studio Edit View Project Build Debug Team Tools Test Analyze Window Help 02 - 2 6 Debug - Any CPU Attach, mal.py" + X generateKey Table 1 edef generateKeyTable(): table = [] letters = "ABCDEFGHIJKLMNOPQRSTUVWYZ #create the table by appending multiple lists to the original list e for i in range(26): row - [""] . 26 table.append(row) #add letters to the table for y in range(26): for x in range(26): table[x][y] - letters [x] ch - letters[@] #get first letter in string letters - letters[1:) #remove the first letter in the string letters + ch #add the first letter to the end of the string return table def encode(data, key): table generatekey Table() data-data.upper() i-e resulta for c in data: rIndex- ord() - ord('A') Index=ord(key[i])- ord('A') result +- table[rIndex][cIndex] i-(i+1) %len(key) return result In 3 C Type here to search Bt9 e 02
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
