对于Caesar Cipher程序,如何仅用ASCII表中的字母表加密/解密?

时间:2015-01-25 21:29:06

标签: python encryption

#Encryption and Decryption Program
offset_1 = ''
 # A = 1
 # B = 2
 # C = 3
 # D = 4
 # E = 5
 # F = 6
 # G = 7
 # H = 8
 # I = 9
 # J = 10
 # K = 11
 # L = 12
 # M = 13
 # N = 14
 # O = 15
 # P = 16
 # Q = 17
 # R = 18
 # S = 19
 # T = 20
 # U = 21
 # V = 22
 # W = 23
 # X = 24
 # Y = 25
 # Z = 26

#Encryption/Decryption Choice
choice = input("Please select encryption or decryption.")
if choice == "e" or choice == "E" or choice == "encrypt" or choice == "Encrypt":
    print ("Your choice is encryption.")

 elif choice == "d" or choice == "D" or choice == "decrypt" or choice == "Decrypt":
    print ("Your choice is decryption.")

# Offset Choice
offset_1 = input("Please select an offset.")
print ("Your offset is " + offset_1)

# Message Choice
message_1 = input("Please input your message")
print ("Your message is " + message_1)
# Code for encryption
for counter in range(len(message_1)):
    print (chr(ord(message_1[counter])+int(offset_1)))
# Code for decryption
for counter in range(len(message_1)):
    print (chr(ord(message_1[counter])-int(offset_1)))

由于我在这个Caesar Cipher程序中使用ASCII表,有人可能会解释我如何只使用字母表中的字母加密/解密,而不需要特殊字符,如£$%^。

我知道这个程序是不完整的,但是一旦完成了这个目的的基础,我将重新调整它。

这适用于Python 3.0并使用Caesar Cipher进行练习。

感谢。

1 个答案:

答案 0 :(得分:1)

你遗漏的关键是Caesar cypher 包裹,所以如果你经过'Z',你应该回到'A'。你的代码没有这样做。