這個換位解密代碼爲什麼不能用於某些鍵?轉置解密不適用於某些密鑰?
def transencrypt(word,key):
'''Traspositon encryption function. This function is used to encrypt a line
using the transposition encryption method. To know how transpositon encryption
works you can visit here https://en.wikipedia.org/wiki/Transposition_cipher.'''
count1=0
count2=0
encrypted=''
encryptbox=['']*key
while count1<key:
count2=count1
while count2<len(word):
encryptbox[count1]+=word[count2]
count2+=key
encrypted+=encryptbox[count1]
count1+=1
return encrypted
def transdecrypt(word,key):
'''This Function is for the decrypting the encrypted strings encrypted by
transencrypt().This function only requires the encrypted string and the key
with which it has been decrypted.'''
import math
count1=0
count2=0
decrypted=''
col=int(math.ceil(len(word)/key))
decryptbox=['']*col
while count1<col:
count2=count1
while count2<len(word):
decryptbox[count1]+=word[count2]
count2+=col
decrypted+=decryptbox[count1]
count1+=1
return decrypted
print(transencrypt('hello world',5))
print(transdecrypt('h dewlolrol',5))
我試圖與鍵5加密的「hello world」,但解密的時候我得到錯誤的結果。使用其他鍵可以正常工作。
你可以在這裏發佈你的代碼而不是在pastebin上嗎?閱讀起來更容易,而且您的代碼始終與您的問題相關聯。 – MichaelDotKnox
他們編輯它我猜。你現在可以讀嗎? – Star
@Star你期望得到什麼,取而代之的是什麼?你能描述一下你的代碼應該如何運作嗎? –