简体   繁体   English

如何修复 ** 或 pow 不支持的操作数类型:“list”和“int”

[英]how to fix unsupported operand type(s) for ** or pow: 'list' and 'int'

I want to encrypt the decimal value of s, but i got Error unsupported operand type(s) for ** or pow: 'list' and 'int'.我想加密 s 的十进制值,但我得到错误 unsupported operand type(s) for ** or pow: 'list' and 'int'。 How to fix it to get the output in decimal?如何修复它以获取十进制的 output?

#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)

Looks like you have written decimalList instead of i in for loop:看起来您在 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)

Also, this line return ''.join(cipher) will raise an error, because cipherElement is an integer, and join method doesn't work with the list of integers, you should cast cipherElement to str .此外,这一行return ''.join(cipher)将引发错误,因为cipherElement是一个 integer,并且join方法不适用于整数列表,您应该将cipherElementstr

暂无
暂无

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

相关问题 如何修复此错误:** 或 pow() 不支持的操作数类型:'tuple' 和 'int' - How to fix this error: unsupported operand type(s) for ** or pow(): 'tuple' and 'int' ** 或 pow() 不支持的操作数类型:“list”和“int”错误 - unsupported operand type(s) for ** or pow(): 'list' and 'int' error TypeError:**或pow()不支持的操作数类型:“ list”和“ int” - TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' 类型错误:不支持 Pow 的操作数类型:第 15 行的“list”和“int” - TypeError: unsupported operand type(s) for Pow: 'list' and 'int' on line 15 **或pow()不支持的操作数类型:&#39;Entry&#39;和&#39;int&#39;? - unsupported operand type(s) for ** or pow(): 'Entry' and 'int'? **或pow()不支持的操作数类型:“函数”和“整数” - unsupported operand type(s) for ** or pow(): 'function' and 'int' “不支持 ** 或 pow() 的操作数类型:&#39;function&#39; 和 &#39;int&#39;” - "unsupported operand type(s) for ** or pow() : ' function' and 'int' " **或pow()不支持的操作数类型:&#39;method&#39;和&#39;int&#39; - unsupported operand type(s) for ** or pow(): 'method' and 'int' 如何修复TypeError:+:&#39;int&#39;和&#39;list&#39;的不支持的操作数类型 - How to fix TypeError: unsupported operand type(s) for +: 'int' and 'list' 如何在 Python 中修复“+ 不支持的操作数类型:‘int’和‘list’” - How to fix "unsupported operand type(s) for +: 'int' and 'list'" in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM