如何修复'ValueError:Chr()arg not in range(0x110000)'Python中的错误

时间:2019-05-26 09:05:56

标签: python algorithm encryption brute-force

我正在编写一个程序来解密用Python中的蛮力加密的句子。但是,当我编译代码时,有时效果很好,但通常我会得到

ValueError: chr() arg not in range(0x110000)

以及许多奇怪的字母。我该如何解决这个问题?

这是我的代码:

//brute-force
m=int(input("turn:"))
encrypted_text = input("Please enter characters to decrypt.: ")
plain_text = ""
for i in range(m):
    for a in range(250):
        for b in range(250):
            for c in encrypted_text:
                x = ord(c)
                if((a+b)/2 == 0):
                    x = x - a*b
                else:
                    x = x - a -b
                    cc = chr(x)
                    plain_text = cc+plain_text

                print(plain_text,a,b)

我用来加密的内容

m=int(input("turn:"))
for i in range(m):
    plain_text = input("Please enter a character to be encrypted.: ")
    a = int(input("Key a ="))
    b = int(input("key b ="))
    encrypted_text = ""

    for c in plain_text:
        x = ord(c)
        if((a+b)/2 == 0):
            x = x + (a*b)

        else:
            x= x + (a+b)

        cc = chr(x)
        encrypted_text = encrypted_text + cc

    print(encrypted_text)

打印错误:

 !"#  $!!%""&##'$$ (%%!)&&"*'' #+((!$,))"%-**#&.++$'/,,%(0--&)1..'*2//(+300),411*-522+.633,/744-0855.1966/2:7703;8814<9925=::36>;;47?<<58@==69A>>7:B??8;C@@9<DAA:=EBB;>FCC<?GDD=@HEE>AIFF?BJGG@CKHHADLIIBEMJJCFNKKDGOLLEHPMMFIQNNGJROOHKSPPILTQQJMURRKNVSSLOWTTMPXUUNQYVVORZWWPS[XXQT\YYRU]ZZSV^[[TW_\\UX`]]VYa^^WZb__X[c``Y\daaZ]ebb[^fcc\_gdd]`hee^aiff_bjgg`ckhhadliibemjjcfnkkdgollehpmmfiqnngjroohksppiltqqjm 0 106

Traceback (most recent call last):
  File "C:/Users/Mr.Shin/Desktop/Python/복호화.py", line 16, in <module>
    cc = chr(x)
ValueError: chr() arg not in range(0x110000)

Process finished with exit code 1

如果您知道该问题的任何解决方案,请告诉我。

0 个答案:

没有答案