繁体   English   中英

如何使解密代码正常工作?

[英]How do I make my decrypt code work?

我创建了此代码来加密文本,但是当它尝试解密时,我得到了:

Builtins.ValueError:chr()arg不在范围内(0x110000)

任何使解密代码正常工作的帮助将不胜感激!

input1 = input("enter key word: ")
input2 = input1[:1]
key = ord(input2)

num_count = 32
dic= {}

while num_count <= 126:
    resultant = float(num_count*key*565)
    dic[num_count] = resultant
    num_count += 1

string = input("Please enter text: ")
num_list = ""

for i in (string):
    number = int(ord(i))
    value = (dic[number])
    number_value = str(value)
    final_value = number_value+" "
    num_list += final_value
print("Encrypted text is", num_list)

num_count3 = 0
decrypt_text = ""
string_len = len(num_list)

characters = []
localChar = ""
for i in num_list:
    if i != " ":
        localChar = localChar + i
    elif i == " ":
        characters.append(localChar)
        localChar = ""

num_count3 = 0
list_len = len(characters)

while num_count3 < list_len:
    value = float(characters[num_count3])
    valuel = int(value/key/54734)
    value2 = round(value)
    de_char = chr(value2)
    decrypt_text += de_char
    num_count3 += 1

print(decrypt_text)

老实说,代码已经结束了。 但我希望这会有所帮助。

问题: num_count3 = 0第一个实例未使用string_len = len(num_list)未使用int(value/key/54734)应该是round(value/key/565) <您的问题+ value2 = round(value)应该是value2 = int(valuel)

许多清理工作+功能很棒!

 def encrypt(key, input1): num_count = 32 dic = {i:float(i*key*565) for i in range(num_count,127)} string = input("Please enter text: ") num_list = ' '.join([str(dic[ord(i)]) for i in string]) print("Encrypted text is", num_list) return num_list def decrypt(key, num_list): characters = num_list.split() decrypt_text = "" num_count3 = 0 list_len = len(characters) while num_count3 < list_len: value = float(characters[num_count3]) valuel = (value/key/565) value2 = int(round(valuel)) de_char = chr(value2) decrypt_text += de_char num_count3 += 1 print(decrypt_text) if __name__ == "__main__": input1 = input("enter key word: ") key = ord(str(input1[:1])) print key result = encrypt(key, input1) decrypt(key, result) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM