Let's go ahead and open the Terminal and follow these steps to implement Caesar cipher in Python:
- We will use Python in interactive mode first and then make a string that just has some letters in order to test this method:
>>> str = "ABCDE">>> str.find("A")0>>> str.find("B")1>>> exit()
- Because we understand how the string methods work, we'll exit and go into the nano text editor to look at the first version of our script:
$ nano caesar1.py
- When you run the command, you will get the following code:
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"str_in = raw_input("Enter message, like HELLO: ")n = len(str_in)str_out = ""for i in range(n): c = str_in[i] loc = alpha.find(c) print i, c, loc, newloc = loc + ...