08 - Tutorial #6 - Caesar Cipher Tutorial & QA

 1. In cryptography, a Caesar cipher, also known as shift cipher, is one of the simplest and most widely known encryption techniques.
Work through the following optional tutorial (program the cipher yourself)



 2. The Caesar cipher is named after Julius Caesar, who used it, more than 2000 years ago, to protect messages of military significance



 3. It is a type of ___________ cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.





 4. For example, with a left shift of four, E would be replaced by A, F would become _______, and so on.





 5. The cipher illustrated below uses a left shift of _____, so that each occurrence of E in the plaintext becomes B in the ciphertext.





 6. When encrypting, a person looks up each letter of the message in the "plain" line and writes down the ____________________.

  last and second last letter in the

  next letter in the alphabet

  first and last letter in the corresponding sequence

  corresponding letter in the "cipher" line.

 7. What would the result of deciphering the following ciphertext be, assuming a right shift of 3.
Ciphertext: QEB NRFZH





 8. The encryption can also be represented using ________________ by first transforming the letters into numbers.

  iteration and selection

  programming techniques like iteration

  Modular Arithmetic (MOD or % in Python)

  General Anaesthetic

 9. To cipher a given text we need an integer value, known as a ____ which indicates the number of position each letter of the text has been moved down





 10. The following code shows the start of an attempt to code a caeser cipher. If 'A' (capital A) is entered, what would the output be?
def convert():
  word=input("Enter word:")
  for i in range(len(word)):





 11. Below, an attempt has been made to extend the program to print out a letter. Assuming 'c' is entered into the program, and we wish 'b' to be output, what needs to be entered instead of 'x' on line 7?
def convert():
  word=input("Enter word:")
  for i in range(len(word)):





 12. What is line 6 of this code doing?
def convert():
  word=input("Enter word:")
  for i in range(len(word)):

  It is converting the letter into the letter before it using direct Modular arithmetic

  It is converting the character (e.g. c) into the corresponding ASCII value.

  It is converting a letter into a random number

  It is converting the ASCII value back to a char value (e.g. enter c and it will output b)

 13. One python code snippet uses modular arithmetic in the following way. Why is it necessary to % by 26 to arrive at the correct answer?
crypting = (index + step) % 26

  Because there are 26 numbers in hexadecimal

  There is no reason - 26 is just chosen randomly to shift the numbers

  The MOD operation ensures that the encryption formula evaluates to a number that never exceeds the upper bound of 25

  Because all ASCII numbers can modulated by 26

 14. What line needs to be changed (and to what) in order for the input "BCD" to result in "ABC". (currently it results in "CDE")
word = input("Please Input a word")
lis = []
for i in range(len(word)):
    newletter = ord(word[i])+1
    if newletter < 65:
        newletter = newletter + 26
    if newletter == 96:
        newletter = newletter + 26

  Line 5 - changed to: if newletter < 63:

  Line 3 - changed to: for i+1 in range(len(word)):

  Line 4 - changed to newletter = ord(word[i])-1

  Line 5 - changed to: if newletter < 67:

 15. On line 21 of the following code, what would the output be, if the Shift was changed to '5' instead of '1'?