Python 如何修复**或pow:'不支持的操作数类型;列表';和';int';

Python 如何修复**或pow:'不支持的操作数类型;列表';和';int';,python,list,integer,Python,List,Integer,我想加密s的十进制值,但我得到了**或pow不支持的错误操作数类型:'list'和'int'。如何修复它以获得十进制输出 #Hexadecimal to decimal def hex_to_decimal(hex_str): decimal_number = int(hex_str, 16) return decimal_number s = "66a9b2d0b1baf7932416c65a28af3c89"

我想加密s的十进制值,但我得到了**或pow不支持的错误操作数类型:'list'和'int'。如何修复它以获得十进制输出

#Hexadecimal to decimal
def hex_to_decimal(hex_str):
    decimal_number = int(hex_str, 16)
    return decimal_number
                 
s = "66a9b2d0b1baf7932416c65a28af3c89"    

decimal = hex_to_decimal(s)
print("s in decimal: ", decimal)


#Encryption
e = 79
n = 3220

def mod(x,y):
        if (x<y):
            return x
        else:
            c = x%y
            return c
    
def enk_blok(m):
    decimalList = [int(i) for i in str(m)]
    cipher = []
    for i in decimalList:
        cipherElement = mod(decimalList**e, n)
        cipher.append(cipherElement)
    return ''.join(cipher)

c = enk_blok(decimal)
print("The result: ", c)
#十六进制到十进制
定义十六进制到十进制(十六进制):
十进制数=整数(十六进制数,16)
返回十进制数
s=“66a9b2d0b1baf7932416c65a28af3c89”
十进制=十六进制到十进制
打印(“十进制中的s:,十进制)
#加密
e=79
n=3220
def模块(x,y):

如果(x看起来像是您在for循环中编写了
decimalList
而不是
i

def enk_blok(m):
    decimalList = [int(i) for i in str(m)]
    cipher = []
    for i in decimalList:
        cipherElement = mod(decimalList**e, n) # replace decimalList with i
        cipher.append(cipherElement) 
    return ''.join(cipher)

此外,此行
返回“”。连接(密码)
将引发错误,因为
ciphereElement
是一个整数,并且
join
方法不适用于整数列表,您应该将
ciphereElement
强制转换为
str

小数点列表**e
未定义。甚至将列表提高到幂次方意味着什么?错误消息通知您,在Pyt中亲爱的,这只是个未定义的问题。也许你想要
[x**e代表十进制列表中的x]
也可能想要
return'。加入(map(str,cipher))