2016-11-18 43 views
-2

所以我有這個功能,這是假設解密密文,但我不知道如何運行此功能,我幾乎不使用python任何幫助將不得不感謝。運行py def和密文

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米enoiaoig SL SGNN iinis PRGA hmwen rinta FS SSE eelo v aesnothmte phssoot OA ftof爾格的i-terasea lghta小號EP-oifotraht ÑTT瓦特aacomt eeks;他enthsp saisa,eaasbl ihd n tsehssi t grapins gliiintoFe m。 rray m ptn tIdoosip raeoft i,raeytm hr sdo oenek itli cu。噸雙黃連注射劑nasais agisn,dcathe uodwnÿahldil rovydl aihcme isite.if ý即nthrargcinonÑoemed尼vetofs I,rhtemwal升afensip oetootr lrmoatu;是BF atiset˚Frulomainde OE agthwB etvs.udiIy b nouio cslae博士升ehhtestiÑigsnh oayure st aid sy.oupo nt tontral usdgi oo ll wnhaosps hi; eehlavtae eegrttr brpa,dhaein tudtn p seeeh LSTR ORPA RA; nbodi˚Fortb SDI aanibs usem estoeht dtwi ETS IASR gmhaontev ewasehfso噸saaie,B dtisaoyi˚Fuotu PTöTR geaaoö ladnw ogyuranao GN d krhbeatel EAX,oynrad usdga OO opelr sibOdee。 sudv重新erue:masep AO ndroio prtnses我btllnti一個.si HNG

+0

要運行'decrypt1(「你的文本」,「你的密鑰」)' – furas

回答

1

參考文獻:

ctext = "your ciphertext" 
result = decrypt1(ctext, key) 
print(result) 

請讓你的密文作爲第一個參數,並在關鍵的第二個參數你的功能根據你的實際情況解密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))