我想製作一個playfair密碼,但我無法將我的變量放到正確的位置。追加到python中的嵌套列表中
我有一個函數,它一次編碼2個純文本字母並返回編碼的等價物,但它只接受單個字母的2個參數(在字符串中)。我需要幫助讓我的列表分開,然後編碼這對。
這是我
def function(plaintext):
temp_hold = ''
encode_out = ''
sendout = ''
#breaks into pairs of 2 (list within a list)
temp_hold = [plaintext[i:i+2] for i in range(0, len(plaintext), 2)]
for i in range(len(temp_hold)):
for j in range(len(temp_hold)):
encode_out = encode_pair(temp_hold[i][j], temp_hold[i][j])
print encode_out
# encode pair takes (a,b) and returns its encoded value
print function("abcd") # should print HSCI
[在python中附加到嵌套列表](http://stackoverflow.com/questions/13763157/appending-to-a-nested-list-in -python) – lurker 2014-10-31 13:03:05