Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.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中使用mod 37的Vigenere密码程序_Python_Encryption_Vigenere - Fatal编程技术网

Python中使用mod 37的Vigenere密码程序

Python中使用mod 37的Vigenere密码程序,python,encryption,vigenere,Python,Encryption,Vigenere,我正在尝试使用mod 37用Python编写一个Vigenere密码程序。我需要帮助找出问题所在 alphabet= "abcdefghijklmnopqrstuvwxyz0123456789 " def Let2Ind(x): return(ord(x)-ord("a")) def Ind2Let(n): return(alphabet[n]) def encVigenere(key, plaintext): ciphertext="" L=len

我正在尝试使用mod 37用Python编写一个Vigenere密码程序。我需要帮助找出问题所在

alphabet= "abcdefghijklmnopqrstuvwxyz0123456789 "

def Let2Ind(x):
        return(ord(x)-ord("a"))

def Ind2Let(n):
    return(alphabet[n])

def encVigenere(key, plaintext):
    ciphertext=""
    L=len(key)
    for i in range(len(plaintext)):
        A=Let2Ind(key[i%L])
        B=Let2Ind(plaintext[i])
        C=(A+B)%37
        D=Ind2Let(C)
        ciphertext= ciphertext+D
    return(ciphertext)

def decVigenere(key, ciphertext):
    plaintext=""
    L=len(key)
    for i in range(len(ciphertext)):
        E=Let2Ind(key[i%L])
        F=Let2Ind(ciphertext[i])
        G=(F-E)%37
        H=Ind2Let(G)
        plaintext= plaintext+H
    return(plaintext)

一个问题是
Let2Ind()
代码不能正确处理数字或空格。它将为数字返回一个负数(-49或左右,表示
0
),为空格返回一个负数(-65)

您可能需要以下内容:

def Let2Ind(x):
    return alphabet.index(x)

欢迎来到堆栈溢出。请尽快阅读这一页。如果您向我们展示一些示例输入(密钥和纯文本)和预期(加密)输出,这将是明智的。我们假设解密应该与原始文本一起显示。你也应该展示你得到了什么,并解释为什么它是错误的。