0
私は2つのリストを実行するwhileループを持っています。リストインデックスが範囲外のときは、whileループから抜け出して終了します。whileループは例外が発生しても継続します(Python 3)
cipher = string_toList(cipher)
plain = string_toList(plain)
i = 0 ## holds value for first two letter block
j = 2 ## holds value for next two letter block and is updated to find invertable matrix
p1 = val(plain[i]); p2 = val(plain[i+1])
c1 = val(cipher[i]); c2 = val(cipher[i+1])
try:
while True:
p3 = val(plain[j]); p4 = val(plain[j+1])
c3 = val(cipher[j]); c4 = val(cipher[j+1])
b = [p1, p2, p3, p4]
c = [c1, c2, c3, c4]
det = det_matrix(b)
if gcd(det, 26) == 1:
break
j += 2 ## incrimented by two in order to hold consistent blocks of letters
except:
print ("plaintext input is not sufficient enough to find key matrix")
return b,c,det
代わりに、このプログラムはexceptの後にメッセージを出力し、端末で閉じずにwhileループを続行します。私は何が間違っているのかわからない、どんな助けも大歓迎です。