我在 python3 中使用 break 指令时遇到问题

I have a problem when I use the break instruction in python3

我正在尝试解决密码学挑战,在我的脚本中我不明白为什么在我的代码中添加一个中断有效,当我删除它时我收到以下错误:

Traceback (most recent call last):
  File "c:\Users\achla95\Documents\learn_crypto\favourite_byte.py", line 11, in <module>
    if  'crypto' in cypher_plaintext:
TypeError: a bytes-like object is required, not 'str'

代码:

cypher = bytes.fromhex("73626960647f6b206821204f21254f7d694f7624662065622127234f726927756d")

for i in range(256):
    cypher_plaintext = xor(cypher,i).decode()
    if  'crypto' in cypher_plaintext:
        print(cypher_plaintext)
        break

感谢您的宝贵时间。

很高兴您找到了解决方案,但最好将其写在答案框中以供将来查看。

变化:

for i in range(256):
    cypher_plaintext = xor(cypher, i).decode()
    if 'crypto' in cypher_plaintext:
        print(cypher_plaintext)
        break

收件人:

for i in range(256):
    cypher_plaintext = xor(cypher, i)
    if b'crypto' in cypher_plaintext:
        print(cypher_plaintext)
        break