Download presentation
Presentation is loading. Please wait.
1
Five-minute starter task
Write a function that takes a string argument and returns a spaced out version of the string E.g. spaceOut("Hello") H e l l o
2
The spaceOut task You can iterate over a string, like you can a list:
for x in myString: do something You cannot change the letters of a string one by one like this: for x in myString x = x + ' ' You have to build up a NEW STRING and then RETURN IT newStr = "" newStr = ….
3
Examples of string functions in Python
Find full documentation here:
4
Caesar Ciphers
5
Examples Plain text: The quick brown fox jumps over the lazy dog
Cipher text: uif rvjdl cspxo gpy kvnqt pwfs uif mbaz eph
6
y = string.ascii_lowercase.find(x) + 1
Clues: You may find these lines of code useful (they are not in order!) for x in plainText: # do something with each letter y = string.ascii_lowercase.find(x) + 1 cipherText = cipherText + string.ascii_lowercase[y] plainText = plainText.lower() You may also find the % operator useful…
7
More clues for every character in plain text:
index = number of the character in the alphabet index = index + 1 cipher character = index'th letter of alphabet add cipher character to cipher text This will work in most cases, but you will have a problem when you come across a 'z' and when you come across an upper case letter, and when you come across a space or some punctuation character.
8
Extension tasks My example only returns cipher text in lower case. Can you write a function that returns mixed cases? My example will raise an error if the plain text contains punctuation. Can you make your function cope with it? Write a function that will encrypt txt using ANY rotation. Write a function that will decrypt anything encrypted using a Caesar cipher.
9
Transposition Ciphers
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.