0
我想在python中實現列換位算法。所以我需要將輸入字符串轉換爲2d字符數組。我怎麼做?如何在Python中將字符串轉換爲2d數組?
我想在python中實現列換位算法。所以我需要將輸入字符串轉換爲2d字符數組。我怎麼做?如何在Python中將字符串轉換爲2d數組?
從Encrypting a columnar transposition cipher:看split_len功能
def split_len(seq, length):
return [seq[i:i + length] for i in range(0, len(seq), length)]
def encode(key, plaintext):
order = {
int(val): num for num, val in enumerate(key)
}
ciphertext = ''
for index in sorted(order.keys()):
for part in split_len(plaintext, len(key)):
try:
ciphertext += part[order[index]]
except IndexError:
continue
return ciphertext
print(encode('3214', 'IHAVETWOCATS'))
#>>> HTAAWTIECVOS
怎樣詞典理解力工作?它如何存儲每個密鑰的索引?我沒有得到它 – roshanthejoker