所以不久前,我创建了一个有趣的python程序,将给定的消息加扰。它发送在消息中解密所需的所有信息-但我不确定如何提取该信息。 (基本上不知道我自己的注释代码如何工作) 如果有人可以执行以下任一操作: 1.重新注释显示其工作方式的代码 要么 2.找出一种方法来按照相反的步骤自行解码。
如果您喜欢挑战,我相信这会满足您的需求。 代码在下面。
import random
def create_message(txt):
###### We take the message
listed_txt = []
listed_ords = []
final = []
#Get the length of the message
num_txt = len(txt)
#create a key for the decoder to find from the length of the original
message
key = round(num_txt / 2)
print(key)
#turn the message into a list of character codes
for i in range(num_txt):
listed_txt.append(str(ord(txt[i])))
print(listed_txt)
#turn the key into a character code to be added later
encode_key = 100 + key
lenlist = len(listed_txt)
#caeser cipher shift the letters by the key
for i in range(lenlist):
part = listed_txt[i]
part = int(part)
part += key
part = chr(part)
print(part)
listed_txt[i] = part
print(listed_txt)
#create the noise added dependent on the size of the original text
for i in range(lenlist * key):
rand_ord = random.randint(-10,20) + 100
rand_ord = chr(rand_ord)
listed_ords.append(rand_ord)
print(listed_ords)
#Create a new list adding the real messages seperated by key numbers of
noise
for i in range(lenlist):
for b in range(key):
final.append(listed_ords[b * i + b])
final.append(listed_txt[i])
print(final)
lenf = len(final)
final.insert((lenf - key),chr(encode_key))
print(final)
new_message = ''.join(final)
print(new_message)
create_message(input("Enter Message to be encoded: "))
def decode_message(code):
#find the key
lencode = len(code)
codelist = []
for i in code:
codelist.append(i)
keypos = round(lencode)
firstKey = codelist[lencode]