Preview

19 - Tutorial #5 + Caesar Cipher with 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)

  TRUE

  FALSE

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

  TRUE

  FALSE

 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.

  bitcoin

  division

  substitution

  subtraction

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

  D

  A

  B

  C

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

  four

  two

  five

  three

 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

  corresponding letter in the "cipher" line.

  first and last letter in the corresponding sequence

  next letter in the alphabet

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

  THE QUICK

  HET UICKQ

  ONE TRACK

  TES TRACK

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

  General Anaesthetic

  iteration and selection

  Modular Arithmetic (MOD or % in Python)

  programming techniques like iteration

 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

  mift

  sift

  shift

  lift

 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)):
    values=ord(word[i])
    print(values)
convert()

  65

  Y

  C

  97

 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)):
    values=ord(word[i])
    values=values-1
    encrypted_letter=chr(values)
    print(x)
convert()

  letter

  values

  values-1

  encrypted_letter

 12. What is line 6 of this code doing?
def convert():
  word=input("Enter word:")
  for i in range(len(word)):
    values=ord(word[i])
    values=values-1
    print(chr(values))
convert()

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

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

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

  It is converting a letter into a random number

 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

  Because all ASCII numbers can modulated by 26

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

 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
    lis.append(chr(newletter))
    print(lis)

  Line 5 - changed to: if newletter < 67:

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

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

  Line 5 - changed to: if newletter < 63:

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

  FABFHPFYXSHJ

  FYYFHPFYTSHJ

  DABFHPFYTSHJ

  DWWDFNDWRQFH