Substitution Ciphers

Step 3 – Full ASCII messages

We can use ord() and chr() to convert whole messages rather than just deal with single characters one at a time.

This is a bit more complex, but it will work.

Convert text to ASCII

This is quite easy to do.

  1. Start a new Python program
  2. Use an input statement to get the user to enter a word or phrase
  3. Then create a blank variable called cipherText. We need a blank variable so that we can add to it
  4. Use a For loop to look at each letter of the user's word or phrase in turn
  5. Use the same code as you did in Step 1 to convert theLetter to it's ASCII code
  6. Now add this to what you already have in the variable cipherText. This builds up the converted code one letter at a time
  7. Outside the loop, print the cipherText

Code image

Save your program and run it.

Start with a short message like "hello" and then try and make the message a bit more complex. Does it deal with symbols like & and spaces? What about a long message?