2
這裏加密的消息是一個例子:使用循環暗號
- 平原:ABCDEFGHIJKLMNOPQRSTUVWXYZ
- 移= 4
- 密碼:DEFGHIJKLMNOPQRSTUVWXYZABC
這裏是代碼:
print ("This is a cyclic cipher program that will encrypt messages.")
#phrase = input("Please enter a phrase to encrypt.")
phrase = "ABCDEFG"
#shift_value = int(input ("Please enter a shift value between 1 - 5."))
shift_value = 1
encoded_phrase = ""
ascii_codes = 0
x = ""
#accepted_ascii_codes = range(65,90) and range(97,122)
for c in phrase:
ascii_codes = ord(c) # find ascii codes for each charcter in phrase
ascii_codes = ascii_codes + shift_value # add an integer (shift value) to ascii codes
phrase_rest = chr(ascii_codes) # convert ascii codes back to characters
encoded_phrase = encoded_phrase + C# stores the phrase character in a new variable
encoded_phrase = encoded_phrase.replace(c,phrase_rest) # replace original character
print (phrase) # prints "ABCDEFG"
print (encoded_phrase) # prints "HHHHHHH"
謝謝FMC!我對字典不熟悉,但我會嘗試一下。 – Mavvy1981 2012-03-02 15:15:56