Project 1 - Cryptography

(This project is based on an exercise from Thomas Robitaille)

About the Projects

  • You will get one project all two weeks
  • You need to solve the projects in order to pass the course. You do not pass the course if you fail to solve or do not hand in more than one project. However, you must hand in and solve the final project (advanced science project); see also below.
  • The course will not give you any credit points. However, you need to pass this course in order to attend an advanced course which I will offer next summer term!
  • Please send your solutions (Python script or Jupyter notebook) via mail to Joseph.
  • In contrast to the homework exercises, each student must hand in an own solution for the projects! Of course you can and should discuss problems with each other!

To solve a project means:

  • You need to hand in a program (script or Notebook) that solves the task given. Note that there is nothing like half the points or half a solution!. Either you solve a project or you do not!
  • Your program needs to be well written (meaningful variable names, good program structure, good documentation).

Note: Joseph and I are very happy to help you out with difficulties you might have with the project tasks! You can ask questions any time!

Simple cryptography: The Cesar cipher

(The project is due on 29/05/2017 before the lecture at 2pm)

Cryptography is the study of how to make messages secret or how to read secret messages. A very simple encryption technique is called the Caesar cipher, which you can read up more about here. The basic idea is that each letter is replaced by a letter that is a certain number of letters away, so for example if the shift was 2, then A would become C, B would become D, etc. (and Z will become B).

Write a python-function cesar_crypt that given a string and a shift (required arguments), will produce the encrypted string for that shift (return-value of the function). Note that the same function can be used to decrypt a message, by passing it a negative shift.

The rules are: you should only accept and return lowercase letters, and spaces should not be changed. You can assume that the input string of your function obeys these rules and you do not need to verify the input.

  • Decrypt with your function the following message, which was encrypted with a shift of 13:

    pbatenghyngvbaf lbh unir fhpprrqrq va qrpelcgvat gur fgevat

  • Decrypt the following message and find the shift:

    gwc uivioml bw nqvl bpm zqopb apqnb

If you hand in a script for this project, then please name it cesar.py.

Hints: (1) Find below a construct that allows you to acess all letters of a string one after the other; (2) To solve the task you need to convert letters to numbers and vice versa. There are several ways to do this. One is to use the built-in functions chr and ord (and remember you can find out more about a function by using ? or the Internet).

Accessing individual letters of a string


In [ ]:
# the follwing construct allows you to access all characters
# within a string one after the other:
name = "Thomas"

for letter in name:
    # Within this 'for'-loop (you will learn more about it in later
    # lectures) the variable 'letter' contains consecutively all
    # individual letters of the string 'name'
    print(letter)