message = "hi my name is caesar"
alphabet = ' abcdefghijklmnopqrstuvwxyz'
positions = {' ': 0,'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}
# STEP ONE is to make an empty list to add your characters to. (Lists work well with dictionaries)
encryptlist = []
# STEP TWO locate the value of the 'r' in caesar.
for chars in message:
Num = positions[chars]
Num возвращается: 18
#STEP THREE encrypt by one step (+1). You can keep the result within 0-26 using result % 27
encoded_Num = (Num + 1) % 27
#STEP 4 encrypt as a list
encryptlist.append(alphabet[encoded_Num])
encryptlist теперь возвращается
['i', 'j', 'a', 'n', 'z', 'a', 'o', 'b', 'n', 'f', 'a', 'j', ' t ',' a ',' d ',' b ',' f ',' t ',' b ',' s ']
# convert the list to a string
encoded_message = "".join(encryptlist)
encoded_message
возвращает: 'ijanzaobnfajtadbftbs', что является ожидаемым результатом