ファイルを受け取り、Viginère 暗号を使用してエンコードするプログラムを作成しようとしています。インデックスで少し問題が発生しました。私は自分の文字列を定義text
し、次のalphabet
ようにしました:
import string
alphabet = string.ascii_lowercase
ciphertext = open("black_hole.txt","r")
ciphertext = ciphertext.read()
text = ""
for i in range(len(ciphertext)):
if ciphertext[i].isalpha() == True:
text = text + ciphertext[i]
これを for ループに書き込もうとすると、問題が発生します。
for i in range(len(text)):
print(alphabet.index(text[i]))
ValueError「部分文字列が見つかりません」が表示されます。text[i] は常に文字と文字列であるため、これは奇妙です。
この質問を十分に明確に提示していない場合はお知らせください。