I have following python code
# helper function to simulate brute force attack on low entropy randomness
def simulate_brute_force_attk_key(message:str, cipher:str)->bytes:
for k in range(2**31):
bf_key = KeyStream(k)
for i in range(len(message)):
xor_value = message[i] ^ cipher[i]
if xor_value != bf_key.get_key_byte():
break
else:
return k
return False
Above code is exectued with out error. My question how it is working when we have else part of working if corresponing if statement inside for loop where as else part is outside of inner for loop. My understanding is that both if and corresponing else part should be inside for loop. I think my understanding is wrong. Request your help in understanding this. Thanks