[英]unsupported operand type(s) for +: 'int' and 'function'
Ok so I need to encrypt or decrypt a message given a list of integers, a message, and a keystream value.好的,所以我需要加密或解密给定整数列表、消息和密钥流值的消息。 Whenever I run my function I get this error:
每当我运行我的函数时,我都会收到此错误:
File "C:\Users\v\Desktop\Assignment 1\cipher_functions.py", line 152, in <module>
result += decrypt_letter(i, get_next_keystream_value)
File "C:\Users\v\Desktop\Assignment 1\cipher_functions.py", line 51, in <module>
key_stream = (ord_char - key_value) builtins.TypeError: unsupported operand type(s) for -: 'int' and 'function'
These are the 2 functions which I believe are involved:这些是我认为涉及的两个功能:
def encrypt_letter(my_char, key_value):
'''(str, int) -> str
'''
my_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
ord_char = (ord(my_char.upper()) - 65)
key_stream = (ord_char + key_value)
if key_stream > 25:
result = (key_stream - 26)
elif key_stream <= 25:
result = key_stream
key_streamed_value = my_list[result]
return key_streamed_value
def decrypt_letter(my_upper_char, key_value):
'''(str, int) -> str
'''
my_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
ord_char = (ord(my_upper_char) - 65)
key_stream = (ord_char - key_value)
if key_stream < 0:
result = (key_stream + 26)
elif key_stream >= 0:
result = key_stream
key_streamed_value = my_list[result]
return key_streamed_value
def process_message(deck_cards, my_message, convert):
'''(list of int, str, str) -> str
'''
result = ""
new_message = clean_message(my_message)
for i in new_message:
if convert == 'e':
result += encrypt_letter(i, get_next_keystream_value)
elif convert == "d":
result += decrypt_letter(i, get_next_keystream_value)
return result
Does anyone know why this problem is occurring?有谁知道为什么会出现这个问题?
It looks like the problem is that get_next_keystream_value
is not defined anywhere.看起来问题是
get_next_keystream_value
没有在任何地方定义。
It is unclear if it is meant to be a variable which you have not initialized, or if it should be a function call for a function that has not been coded yet, in which case it should be get_next_keystream_value()
.目前尚不清楚它是否意味着您尚未初始化的变量,或者它是否应该是尚未编码的函数的函数调用,在这种情况下它应该是
get_next_keystream_value()
。 Given the structure of your code, it looks like you are trying to pass it as the key_value
, in which case you need to initialize it to an integer first.鉴于您的代码结构,您似乎试图将其作为
key_value
,在这种情况下,您需要key_value
其初始化为整数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.