如果我有兩個字符串,如:對齊兩個不同長度的不同字符串?
plaintext = "hello"
key = "hi"
我如何排列的字母(或其他字符,如空格和標點符號)一起足不出戶的範圍是多少?到目前爲止,我正在這樣做,但我一直跑到索引錯誤的字符串。
encryption = ""
for index in range(len(plaintext)):
if plaintext[index] in alphabet:
encryption += vigenere_encrypt(plaintext[index], key[index])
if plaintext[index] not in alphabet:
encryption += plaintext[index]
return encryption
我基本上是試圖讓我的鑰匙匹配了明文的長度,使"hi" --> "hihih"
是相同的長度,「你好」,所以能都在同一時間循環而不運行到離範圍錯誤
你究竟想要達到什麼目的?這兩個字符串的預期輸出是什麼? – Mureinik
你爲什麼在所有索引和什麼是vigenere_encrypt? –
我基本上試圖讓我的關鍵匹配與明文的長度,所以「嗨」應該成爲「hihih」,這是「你好」相同的長度 –