練習問題/解答例/Caesar暗号解読/Python
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[練習問題]]
a = 'abcdefghijklmnopqrstuvwxyz .,-'
s = 'qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqrcxi.qbub...
for i in range(len(a)):
candidate = ''.join(';' if e==';' else a[(a.find(e) ...
if 'person' in candidate:
print(candidate)
break
#初心者用
table_str = "abcdefghijklmnopqrstuvwxyz .,-abcdefghijklm...
encrypted = "qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqr...
table = []
for c in table_str:
table.append(c)
# table は ['a', 'b', ...] になった
needle_chars = ["p", "e", "r", "s", "o", "n"]
for stride in range(1, len(table)//2):
# "person"をstride幅で暗号化
needle_enc = ""
for c1 in needle_chars:
idx = table.index(c1)
needle_enc += table[idx + stride]
# 問題の暗号文が暗号化済"person"を含んでいれば勝ち
if needle_enc in encrypted:
decrypted = ""
for c2 in encrypted:
if c2 == ";":
decrypted += ";"
else:
idx2 = table.index(c2)
decrypted += table[idx2 - stride] # pyth...
print(decrypted)
break
終了行:
[[練習問題]]
a = 'abcdefghijklmnopqrstuvwxyz .,-'
s = 'qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqrcxi.qbub...
for i in range(len(a)):
candidate = ''.join(';' if e==';' else a[(a.find(e) ...
if 'person' in candidate:
print(candidate)
break
#初心者用
table_str = "abcdefghijklmnopqrstuvwxyz .,-abcdefghijklm...
encrypted = "qdq-gi.q-a ziatmxxitmdqibtqi-ustbi ri.qmoqr...
table = []
for c in table_str:
table.append(c)
# table は ['a', 'b', ...] になった
needle_chars = ["p", "e", "r", "s", "o", "n"]
for stride in range(1, len(table)//2):
# "person"をstride幅で暗号化
needle_enc = ""
for c1 in needle_chars:
idx = table.index(c1)
needle_enc += table[idx + stride]
# 問題の暗号文が暗号化済"person"を含んでいれば勝ち
if needle_enc in encrypted:
decrypted = ""
for c2 in encrypted:
if c2 == ";":
decrypted += ";"
else:
idx2 = table.index(c2)
decrypted += table[idx2 - stride] # pyth...
print(decrypted)
break
ページ名: