【发布时间】:2019-04-13 10:46:27
【问题描述】:
在我的这个任务中,我需要根据给定的密钥加密消息。面临的挑战是索引字母表的键,并使更改替换消息中的字母。我到目前为止的代码是:
def encode(key,plaintext):
for i in key:
key.index(i)
for i in plaintext:
print(plaintext.index(i))
alpha = ["abcdefghijklmnopqrstuvwxyz"]
def main():
plaintextMessages = [
["This is the plaintext message.",
"bcdefghijklmnopqrstuvwxyza"],
["Let the Wookiee win!",
"epqomxuagrdwkhnftjizlcbvys"],
["Baseball is 90% mental. The other half is physical.\n\t\t- Yogi Berra",
"hnftjizlcbvysepqomxuagrdwk"],
["I used to think I was indecisive, but now I'm not too sure.",
"mqncdaigyhkxflujzervptobws"],
["Einstein's equation 'e = mc squared' shows that mass and\n\t\tenergy are interchangeable.",
"bludcmhojaifxrkzenpsgqtywv"] ]
codedMessages = [
["Uijt jt uif dpefe nfttbhf.",
"bcdefghijklmnopqrstuvwxyza"],
["Qnhxgomhqm gi 10% bnjd eho 90% omwlignh. - Zghe Xmy",
"epqomxuagrdwkhnftjizlcbvys"],
["Ulj njxu htgcfj C'gj jgjm mjfjcgjt cx, 'Ep pej jyxj veprx rlhu\n\t\t uljw'mj tpcez jculjm'. - Mcfvw Zjmghcx",
"hnftjizlcbvysepqomxuagrdwk"],
["M 2-wdme uxc yr kylc ua xykd m qxdlcde, qpv wup cul'v gmtd mlw\n\t\t vuj aue yv. - Hdeew Rdyladxc",
"mqncdaigyhkxflujzervptobws"] ]
for i in plaintextMessages:
encode(i[1],i[0])
main()
我可以获得密钥的索引和消息,但我不知道如何让这些东西相互作用或相互影响。
【问题讨论】:
标签: python string list indexing cryptography