[英]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
方法不适用于整数列表,您应该将cipherElement
为str
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.