我一直在玩Python和對面麻省理工學院,這一任務是創建編碼消息(凱撒代碼中,例如,你的消息改變ABCD字母CDEF)來了。這是我想出了:選擇從列表中選擇特定int類型,並改變它們
Phrase = input('Type message to encrypt: ')
shiftValue = int(input('Enter shift value: '))
listPhrase = list(Phrase)
listLenght = len(listPhrase)
ascii = []
for ch in listPhrase:
ascii.append(ord(ch))
print (ascii)
asciiCoded = []
for i in ascii:
asciiCoded.append(i+shiftValue)
print (asciiCoded)
phraseCoded = []
for i in asciiCoded:
phraseCoded.append(chr(i))
print (phraseCoded)
stringCoded = ''.join(phraseCoded)
print (stringCoded)
代碼工作,但我要實現不轉移的空間和消息特殊標誌的ASCII值。
所以我的想法是在範圍(65,90)和量程(97122)範圍內選擇列表值和改變他們,而我不會改變任何人。但我該怎麼做?
你可以使用'isalpha()'方法http://stackoverflow.com/questions/15558392/how-to-check-if-character-in-string-is-a-word-character-python – RinaLiu