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