Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行python def和密码文本_Python_Encryption - Fatal编程技术网

运行python def和密码文本

运行python def和密码文本,python,encryption,Python,Encryption,所以我有一个函数,假设它可以对密码文本进行解密,但我不知道如何运行这个函数,我几乎不使用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: per

所以我有一个函数,假设它可以对密码文本进行解密,但我不知道如何运行这个函数,我几乎不使用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
这是密文

这是一个非常重要的问题 eelo v aesnothmte phssoot oa FTERG i-terasea lghta s ep oifotraht n tt w aacomt eeks;这是一份完整的图表 胶质细胞。一号码头,一号码头 铜。如有必要,请与我联系 是的,我的朋友,我的朋友 伊尔莫阿图;这是一个很好的例子吗 在奥尤尔州的一家医院里,一名医生帮助一家美国医院 你好;请看下一页 奥帕-拉;nbodi f ortb sdi aanibs使用estoeht dtwi ets iasr gmhaontev ewasehfso t saaie,b dtisaoyi f uotu pt o tr GEAO o 奥吉乌拉诺西北部和krhbeatel eax,运营成本仅为美元。 学生:我是一名学生

参考文献:

请根据您的实际情况,将密文作为第一个参数,将密钥作为函数decrypt1的第二个参数。

要运行do
decrypt1(“您的文本”,“您的密钥”)
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))
ctext = "your ciphertext"
result = decrypt1(ctext, key)
print(result)