2015-07-03 87 views

回答

0

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 
+0

怎样词典理解力工作?它如何存储每个密钥的索引?我没有得到它 – roshanthejoker

相关问题