Substitution Ciphers

Step 2 – Converting from ASCII code

We can also convert from a numerical code to a keyboard character using the command  chr() .

START A NEW PYTHON PROGRAM

Try this program:

Code image

Save the program and run it several times. Use values like 42, 87 and 126 and see what happens.

You'll notice that we need to use the int() command here to convert the numbers entered into an actual number.

Python always treats anything entered as something called a string. So it says, this is the keyboard characters "42" rather than the number 42. Which is annoying. So int() tells it to treat whatever you enter as a number.

Now try it with bigger numbers. I honestly have no idea how big it will go, so start with anything bigger than 127 and see how far you can go! (my best guess it that it will let you get into the 65,000s at least).

Then try a number between 0 and 31 and see what happens. See if you can find out why this happens.