所以我有这个函数,假设解密密文,但我不知道如何运行这个函数,我几乎不使用python任何帮助将是必须赞赏。
def decrypt1(ctext, key):
if key % 4 == 0:
perm = [4, 1, 3, 6, 7, 5, 2, 0]
elif key % 4 == 1:
perm = [2, 4, 0, 5, 7, 6, 3, 1]
elif key % 4 == 2:
perm = [1, 7, 0, 2, 6, 5, 3, 4]
else:
perm = [5, 4, 1, 7, 0, 2, 3, 6]
rev_perm = [perm.index(i) for i in range(len(perm))]
ptext = ""
for j in range(0, len(ctext), 8):
block = ctext[j: j+8]
ptext += ''.join(block[p] for p in rev_perm)
return ptext
这是密文
ehn Aotrf irtmeot m enoiaoig sl sgnn iinis prga hmwen rinta fs sse eelo v aesnothmte phssoot oa ftof erg i-terasea lghta s ep-oifotraht 不知不觉中的讽刺意味着什么,而是痴迷于世界各地 gliiintoFe m。 rray m ptn tIdoosip raeoft i,raeytm hr sdo oenek itli 立方米。 t Shli nasais agisn,dcathe uodwn y ahldil rovydl aihcme isite.if Y ie nthrargcinon n oemed neh vetofs i,rhtemwal l afensip oetootr lrmoatu; is b f atiset f rulomainde o agthwB etvs.udiIy b nouio cslae dr l ehhtesti n igsnh oayure st r aID a sy.oupo nt toylral usdgi oo ll wnhaosps hi; eehlavtae eegrttr brpa,dhaein tudtn p seeeh lstr orpa ra; nbodi f ortb sdi aanibs usem estoeht dtwi ets iasr gmhaontev ewasehfso t saaie,b dtisaoyi f uotu pt o tr geaao o ladnw ogyuranao gn d krhbeatel eax,oynrad usdga oo opelr sibOdee。 sudv re erue:masep ao ndroio prtnses i btllnti a .si hng
答案 0 :(得分:1)
参考文献:
ctext = "your ciphertext"
result = decrypt1(ctext, key)
print(result)
请将您的密文作为您的第一个参数,并根据您的实际情况将密钥作为您的函数的第二个参数decrypt1。
答案 1 :(得分:0)
data = '''ehn Aotrf irtmeot m enoiaoig sl sgnn iinis prga hmwen rinta fs sse
eelo v aesnothmte phssoot oa ftof erg i-terasea lghta s ep-oifotraht
n tt w aacomt eeks;h e enthsp saisa,eaasbl ihd n tsehssi t grapins
gliiintoFe m. rray m ptn tIdoosip raeoft i, raeytm hr sdo oenek itli
cu. t Shli nasais agisn,dcathe uodwn y ahldil rovydl aihcme isite.if
Y ie nthrargcinon n oemed neh vetofs i, rhtemwal l afensip oetootr
lrmoatu;is b f atiset f rulomainde o e agthwB etvs.udiIy b nouio
cslae dr l ehhtesti n igsnh oayure st r aID a sy.oupo nt toylral usdgi
oo ll wnhaosps hi; eehlavtae eegrttr brpa ,dhaein tudtn p seeeh lstr
orpa ra ;nbodi f ortb sdi aanibs usem estoeht dtwi ets iasr
gmhaontev ewasehfso t saaie, b dtisaoyi f uotu pt o tr geaao o
ladnw ogyuranao gn d krhbeatel eax,oynrad usdga oo opelr sibOdee.
sudv re erue:masep ao ndroio prtnses i btllnti a .si hng
'''
print(decrypt1(data, 3))