试图在python中解释viginere密码中的空格/空白。这是单字母加密。你知道吗
请注意,我对python非常陌生!你知道吗
def encrypt(message, key):
'''Vigenere encryption of message using key.'''
# Converted to uppercase.
# Non-alpha characters stripped out.
message = filter(str.isalpha, message.upper())
def enc(c, k):
'''Single letter encryption.'''
return chr(((ord(k) + ord(c) - 2 * ord('A')) % 26) + ord('A'))
return ''.join(starmap(enc, zip(message, cycle(key))))
def decrypt(message, key):
'''Vigenere decryption of message using key.'''
def dec(c, k):
'''Single letter decryption.'''
return chr(((ord(c) - ord(k) - 2 * ord('A')) % 26) + ord('A'))
return ''.join(starmap(dec, zip(message, cycle(key))))
我已经试过了,但不起作用
def enc(c, k):
'''Single letter encryption.'''
if ord(c) == 32:
return chr(ord(c))
else:
return chr(((ord(k) + ord(c) - 2 * ord('A')) % 26) + ord('A'))
我现在的代码是这样的:
"Hello World" --> "JKJLJYUPLY" key = "wasup"
我想要:
"Hello world" --> "JKJLJ YUPLY" key "wasup"
我并没有真正记录自己的加密方法本身,但我测试它逐字逐句,它工作得很好:
打印
JKJLJ YUPLY
如果viginere密码应该是逐字应用的,那么这就是使用它的方法。你知道吗
相关问题 更多 >
编程相关推荐