this function ciphers a string using the caesar's cipher method string: the message to cipher key: the number of times to shift the letters in the alphabet it returns the ciphered string
(string, key)
| 15 | |
| 16 | |
| 17 | def cipher(string, key): |
| 18 | """ |
| 19 | this function ciphers a string using the caesar's cipher method |
| 20 | string: the message to cipher |
| 21 | key: the number of times to shift the letters in the alphabet |
| 22 | it returns the ciphered string""" |
| 23 | |
| 24 | nletters = shift(letters, key) |
| 25 | |
| 26 | def cipher_word(string): |
| 27 | msg = [] |
| 28 | |
| 29 | for i in string: |
| 30 | index = letters.index(i) |
| 31 | i = nletters[index] |
| 32 | msg.append(i) |
| 33 | |
| 34 | return "".join(msg) |
| 35 | |
| 36 | sentence = string.split(" ") |
| 37 | nsentence = list(map(cipher_word, sentence)) |
| 38 | |
| 39 | return " ".join(nsentence) |
| 40 | |
| 41 | |
| 42 | if __name__ == "__main__": |