我正在为我的学校加密一个字,并且无法弄清楚如何将它从单个数字加密变成一个完整的单词。我希望能够一次完整的单词,而不是一个字母。如果有人能帮我解决这个问题,我将非常感激
while True:
print("Input letters you would like to encrypt")
IN= input()
if IN=="a":
print("BCDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="A":
print("BCDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="b":
print("ACDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="B":
print("ACDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="c":
print("ABDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="C":
print("ABDEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="d":
print("ABCEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="D":
print("ABCEFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="e":
print("ABCDFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="E":
print("ABCDFGHIJKLMNOPQRSTUVWXYZ")
elif IN=="f":
print("ABCDEGHIJKLMNOPQRSTUVWXYZ")
elif IN=="F":
print("ABCDEGHIJKLMNOPQRSTUVWXYZ")
elif IN=="g":
print("ABCDEFHIJKLMNOPQRSTUVWXYZ")
elif IN=="G":
print("ABCDEFHIJKLMNOPQRSTUVWXYZ")
elif IN=="h":
print("ABCDEFGIJKLMNOPQRSTUVWXYZ")
elif IN=="H":
print("ABCDEFGIJKLMNOPQRSTUVWXYZ")
elif IN=="i":
print("ABCDEFGHJKLMNOPQRSTUVWXYZ")
elif IN=="I":
print("ABCDEFGHJKLMNOPQRSTUVWXYZ")
elif IN=="j":
print("ABCDEFGHIKLMNOPQRSTUVWXYZ")
elif IN=="J":
print("ABCDEFGHIKLMNOPQRSTUVWXYZ")
elif IN=="k":
print("ABCDEFGHIJLMNOPQRSTUVWXYZ")
elif IN=="K":
print("ABCDEFGHIJLMNOPQRSTUVWXYZ")
elif IN=="l":
print("ABCDEFGHIJKMNOPQRSTUVWXYZ")
elif IN=="L":
print("ABCDEFGHIJKMNOPQRSTUVWXYZ")
elif IN=="m":
print("ABCDEFGHIJKLNOPQRSTUVWXYZ")
elif IN=="M":
print("ABCDEFGHIJKLNOPQRSTUVWXYZ")
elif IN=="n":
print("ABCDEFGHIJKLMOPQRSTUVWXYZ")
elif IN=="N":
print("ABCDEFGHIJKLMOPQRSTUVWXYZ")
elif IN=="o":
print("ABCDEFGHIJKLMNPQRSTUVWXYZ")
elif IN=="O":
print("ABCDEFGHIJKLMNPQRSTUVWXYZ")
elif IN=="p":
print("ABCDEFGHIJKLMNOQRSTUVWXYZ")
elif IN=="P":
print("ABCDEFGHIJKLMNOQRSTUVWXYZ")
elif IN=="q":
print("ABCDEFGHIJKLMNOPRSTUVWXYZ")
elif IN=="Q":
print("ABCDEFGHIJKLMNOPRSTUVWXYZ")
elif IN=="r":
print("ABCDEFGHIJKLMNOPQSTUVWXYZ")
elif IN=="R":
print("ABCDEFGHIJKLMNOPQSTUVWXYZ")
elif IN=="s":
print("ABCDEFGHIJKLMNOPQRTUVWXYZ")
elif IN=="S":
print("ABCDEFGHIJKLMNOPQRTUVWXYZ")
elif IN=="t":
print("ABCDEFGHIJKLMNOPQRSUVWXYZ")
elif IN=="T":
print("ABCDEFGHIJKLMNOPQRSUVWXYZ")
elif IN=="u":
print("ABCDEFGHIJKLMNOPQRSTVWXYZ")
elif IN=="U":
print("ABCDEFGHIJKLMNOPQRSTVWXYZ")
elif IN=="v":
print("ABCDEFGHIJKLMNOPQRSTUWXYZ")
elif IN=="V":
print("ABCDEFGHIJKLMNOPQRSTUWXYZ")
elif IN=="w":
print("ABCDEFGHIJKLMNOPQRSTUVXYZ")
elif IN=="W":
print("ABCDEFGHIJKLMNOPQRSTUVXYZ")
elif IN=="x":
print("ABCDEFGHIJKLMNOPQRSTUVWYZ")
elif IN=="X":
print("ABCDEFGHIJKLMNOPQRSTUVWYZ")
elif IN=="y":
print("ABCDEFGHIJKLMNOPQRSTUVWXZ")
elif IN=="Y":
print("ABCDEFGHIJKLMNOPQRSTUVWXZ")
elif IN=="z":
print("ABCDEFGHIJKLMNOPQRSTUVWXY")
elif IN=="Z":
print("ABCDEFGHIJKLMNOPQRSTUVWXY")
else:
print("One number at a time bud")
通
答案 0 :(得分:0)
我知道你可能在你的项目上努力工作但遗憾的是我认为能够生成加密文本可能有点过于简约。 正如你所说,你的代码目前所做的只是打印1位数加密。
可悲的是,我对python的了解已经减少,但是一个简单的谷歌可能能够帮助你,我快速查看了所以我希望这会有所帮助! http://www.dlitz.net/software/pycrypto/ 这应该有希望帮助你,它还为你提供了一个解密器。如果需要,
我是从他们的文件中得到的,
>>> from Crypto.Cipher import DES
>>> obj=DES.new('abcdefgh', DES.MODE_ECB)
>>> plain="Guido van Rossum is a space alien."
>>> len(plain)
34
>>> obj.encrypt(plain)
Traceback (innermost last):
File "<stdin>", line 1, in ?
ValueError: Strings for DES must be a multiple of 8 in length
>>> ciph=obj.encrypt(plain+'XXXXXX')
>>> ciph
'\021,\343Nq\214DY\337T\342pA\372\255\311s\210\363,\300j\330\250\312\347\342I\3215w\03561\303dgb/\006'
>>> obj.decrypt(ciph)
'Guido van Rossum is a space alien.XXXXXX'
答案 1 :(得分:0)
只是为了好玩:
from string import ascii_uppercase
while True:
print("Input letters you would like to encrypt")
IN= input().upper()
if IN.upper() in ascii_uppercase:
print(ascii_uppercase.replace(IN, ''))
答案 2 :(得分:0)
看起来你正试图返回罗马字母的补充与所提供的字母有关。
有几种方法可以做到这一点:
from string import ascii_uppercase
def reduce_complement_alpha(letters):
res = reduce(lambda letter: alphabet.replace(letter, ''), letters.upper(), ascii_uppercase)
return res
def set_complement_letters(letters):
res = ''.join(sorted(set(ascii_upper) - set(letters.upper())))
return res
def filter_complement_letters(letters):
res = ''.join(filter(lambda l: l not in letters.upper(), ascii_uppercase))
return res
这些仅仅是几个例子:)第一个特征O(n log n)时间复杂度但实际上因为你的n非常小并不重要,而最后一个具有线性O(n)时间复杂度。