More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Turing-Welchman Bombe Simulator

turing-welchman-bombe-4-drumsIn our Enigma – mission X challenge, we looked at how the Enigma machine was used by the Germans during WWII to encrypt radio communications and how code breakers were assigned the job to crack the code of the Enigma machine.

Considering that an Enigma M3 machine consists of three rotors (chosen from a set of five), the addition of the rotor settings with 26 positions, and the plugboard with ten pairs of letters connected means that an Enigma M3 has 158,962,555,217,826,360,000 (nearly 159 quintillion) different settings!

The break through that enabled code breakers to work out the Enigma settings came from the work of Alan Turing, Gordon Welchman and their associates at Bletchley Park who created a complex electro-mechanical device called the Bombe used to work out possible enigma settings (rotor settings & positions and plugboard connections) from a “crib”. The term crib originated at Bletchley Park and refers to a piece of plaintext with its matching ciphertext. Codebreakers noticed that the Germans were regularly sending Weather reports (in German Wetter Vorhersage) and could identify the ciphertext containing these words (based on the time of the day these reports were sent).

Another message that Germans often used was the message “Nothing to report” (in German Keine besonderen Ereignisse) which was also used to identify useful cribs.

During the war more than 200 Bombes were built to help decrypt hundreds of messages every day. All these machines were fully destroyed when the war ended. An actual reproduction of the Turing-Welchman Bombe can be found at the National Museum of Computing and additional explanations of how the Bombe worked is available at Bletchley Park.

Turing-Welchman Bombe Simulator


To gain a better understanding of how the Bombe worked, we decided to recreate an online simulator that you can use to workout Enigma settings from valid cribs.

Click on the picture below to access our online Turing-Welchman Bombe simulator and try to find the Enigma settings to decrypt the following cipher text:

SNMKG GSTZZ UGARL VYQGM YWMLU

turing-welchman-bombe

Tagged with: , ,

Enigma Daily Settings Generator

enigma-m3-ukw-bBefore attempting this challenge, you should familiarise yourself with the Enigma machine by completing the Enigma Mission X challenge.

Code Books were used by the Germans to list all the settings needed to set up the Enigma machines before starting to encrypt or decrypt messages. The Germans used to change the Enigma settings very regularly (e.g. once a day) so that if the Allies managed to break their code (find out the Enigma settings) they would only be able to use them for that day and would have to find the new settings every day. Code books were highly confidential documents as if a codebook was captured or reconstructed, messages could easily be decrypted.

An Enigma code book would have one page per month. The page would include all the settings for each day of the month with the first day of the month at the bottom of the page so that once used, a setting could be torn off the page.

The settings would indicate which rotors to use and in which order to connect them. Initially the Enigma machine came with a box of five rotors to choose from. On an Enigma M3, three out of the five rotors were connected. The M4 Enigma used four rotors chosen from a box of up to eight rotors.

The settings would also include the wheel settings (how to connect the rotors) and their initial position. Finally the settings would indicate which letters to connect by plugging cables on the plugboard.

The aim of this challenge is to write a piece of Python code to generate a full Code Book of Enigma Daily Settings for the Enigma M3 series. (which consists of 3 rotors to choose from a collection of 5 unique rotors).

The code book should include 30 or 31 set of randomly generated daily settings (one for each day of the month) displayed in a table as follows:

enigma-code-book

Each daily settings should include:

  • The date (number between 1 and 30/31, listed in reverse order)
  • The choice of three rotors (e.g. IV I III)
  • The ring settings (e.g. ABC)
  • The initial rotor positions (e.g. DEF)
  • The plugboard permutations (e.g. AF CK EW MT SV XY)

Python Code / Solution

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: ,

Enigma – Mission X Challenge

top-secret-stamp

Dear code breaker,

I am contacting you from Bletchley Park as we are intercepting an increased volume of encrypted radio signals. We are working day and night to break the enigma codes that the German Navy are updating every day. The German U-Boats are operating in the Atlantic Ocean and are causing major casualties by sinking not only military ships from the Royal Navy but also merchant ships bringing supplies from the United States and Canada to the United Kingdom.

Luckily, we have gained access to a code book which, we believe, gives us all the settings for the Enigma M3 machine, for each day of this month.

Could you help us decode the following secret messages by applying the required settings to the Enigma M3 machine. I am not sure about your understanding of the German language, so I have enclosed a German translation book including key German expressions.

We believe that the Germans are preparing a major attack on the south coast of England. We hope that the messages will help us find more information on the exact location and day of the attack.

Let us know if you can find out more useful information from these messages.

Yours sincerely,

Your friend, Alan T.

Video Tutorial

Mission Files


Click on the following folder to access Mission X top secret files.
misison-folder

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with: , ,

Enigma Machine Emulator

The enigma machine was used in World War II to encrypt secret messages.

The enigma machine was used in World War II to encrypt secret messages.

The Enigma machines are a series of electro-mechanical rotor cipher machines. The first machines were invented at the end of World War I by German engineer Arthur Scherbius and were mainly used to protect commercial, diplomatic and military communication. Enigma machines became more and more complex and were heavily used by the German army during World War II to encrypt radio signals.

One of the key objectives for the Allies during WWII was to find a way to break the code to be able to decrypt German communications. A team of Polish cryptanalysts was the first to break Enigma codes as early as 1932, however the German used more advanced Enigma machines making it virtually impossible to break the Enigma code using traditional methods. In 1939 with the prospect of war, the Poles decided to share their findings with the British. Dilly Knox, one of the former British World War I Codebreakers, set up an Enigma Research Section at Bletchley Park, England. He worked alongside Tony Kendrick, Peter Twinn, Alan Turing and Gordon Welchman. Together they developed a complex machine called the Bomb used to workout Enigma settings from intercepted German communications. The first wartime Enigma messages were broken in January 1940. Being able to decrypt German messages gave the Allies valuable information which has had a major impact on the outcomes of WWII.

To gain a better understanding of the encryption techniques used by the enigma machine we have decided to recreate a virtual Enigma machine/emulator.

You will be able to use this machine to both encrypt or decrypt enigma messages (Enigma encryption is symmetric, which means that the same settings can be used to both encrypt or decrypt a message).

Our Enigma machine emulator is replicating the encryption process of the Enigma M3 series that was used by the German Navy (Kriegsmarine). It is fitted with a UKW-B reflector. Later on through the war, it was replaced by the M4 series which included a 4throtor.

Before pressing any keys on the keyboard section of the machine you will need to apply the required settings. To do so you will need to click on the rotors to adjust the wheels initial settings and then make the required connections by clicking on the different plugs (bottom section of the machine) to connect letters from the plugboard.

Enigma Machine Emulator

Tagged with: , ,

Stopping Distance Calculator

road-sign-deerIn this challenge, we will write a Python program to estimate the total stopping distance of a vehicle based on its speed. The stopping distance consists of two components. The first component is the reaction distance covered by the vehicle due to the reaction time/delay of the driver between the moment an obstacle is spotted on the road and the moment the brakes are applied. The second component is the braking distance which is the distance a vehicle will travel from the point when its brakes are fully applied to when it comes to a complete stop. The braking distance is primarily affected by the original speed of the vehicle and the coefficient of friction between the tires and the road surface.

Based on the law of physics, we can write the stopping distance formula as follows:
stopping-distance-formula

For this challenge we will use a response time (tr) of 1.5 seconds, the average response time of a driver. In reality this response time varies depending on the age of the driver, their experience and their condition: e.g. A tired driver will have a slower response time than an alert driver.

The common baseline value for the friction coefficient µ (pronounced mu) is 0.7. In reality this coefficient varies depending on the condition of the road (e.g. dry/wet/icy) as well as the types, condition and pressure of the tyres.

Our aim is to write a Python program based on the INPUT / PROCESS / OUTPUT model that will:

  1. INPUT: Ask the user to enter the speed of a car in mph (Miles per hour)
  2. PROCESS: Convert this speed in mps (meters per second)
  3. PROCESS: Apply the stopping distance formula (using µ = 0.7 and tr = 1.5s)
  4. OUTPUT: Display the estimated stopping distance of the car in meters.

Speed Conversion Formula


To convert the speed of the vehicle from mph (miles per hour) to mps (meter per second) you will need to apply the following formula:
speed-conversion-formula

Complete the Python Code


Testing


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Actual Output
#1 50 mph 70 meters
#2 70 mph 118 meters
#3 30 mph 33 meters

Extension Task:


The value of the friction coefficient µ depends on the condition of the road.

Adapt your script to ask the user if the road is dry, wet, or icy.
Based on the user input, you will use the following friction coefficients:

Road Condition Friction Coefficient
Dry µ = 0.7
Wet µ = 0.5
Icy µ = 0.3

Testing


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values Expected Output Actual Output
#1 30 mph, Dry Road 33 meters
#2 30 mph, Wet Road 38 meters
#3 30 mph, Icy Road 51 meters
#4 70 mph, Dry Road 118 meters
#5 70 mph, Wet Road 146 meters
#6 70 mph. Icy Road 213 meters
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

Binary Permutations Challenge

binary-permutations

Did You Know?

Everything that is stored on a computer is stored as binary code. Binary code is made of bits (0 or 1). We often use Bytes to store data. A Byte is made of eight bits and can be used to store any whole number between 0 to 255. This is because with 8 bits you can generate 256 different permutations.

Check it yourself, click on the binary digits to create your own binary number:


1286432168421
11111111

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255


Python Challenge


The aim of this challenge is to write a procedure called listAllBinaryPermutations() that will take one parameter called numberOfBits and outputs all possible binary permutations depending on the number of bits.

For instance listAllBinaryPermutations(4) would output the following 16 binary permutations:

  • 0000
  • 0001
  • 0010
  • 0011
  • 0100
  • 0101
  • 0110
  • 0111
  • 1000
  • 1001
  • 1010
  • 1011
  • 1100
  • 1101
  • 1110
  • 1111

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Complementary Colours Algorithm

Complementary colours are pairs of colours which, when combined or mixed, cancel each other out by producing a grayscale colour like white or black. When placed next to each other, they create the strongest contrast for those two colours. Complementary colours may also be called “opposite colours.”.

To find out pairs of complementary colours we can use a colour wheel. Colours which are at the opposite position on the colour wheel are complementary colours:
complementary-colours

Complementary Colours Formula


When representing colours using the RGB colour code, we can use the following formula to work out the complementary RGB colour code:
complementary-colour-formula

Complementary Colours Algorithm


Our aim is to write a Python program, based on the INPUT, PROCESS and OUTPUT model in order to:

  1. INPUT: Ask the user to enter an RGB colour code
  2. PROCESS: Apply the complementary colour code formula to work out the RGB code of the complementary colour
  3. OUPUT: Display the complementary colour code on screen

Our code will be based on the following flowchart:
complementary-colours-flowchart

Casting


To complete this challenge, you will need to understand the importance of casting values from string to integer data types using the int() function and from integer to string using the str() function.

Python Code


unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

My Weekly Timetable

A school timetable is displayed as a 2D table consisting of 5 rows (for each day of the week) and 5 columns (number of lessons in a day).

Such a table can be stored in a computer program using a 2-dimensional array (2d Array). In python, this is done by creating a list of lists.

Each value of a 2D array can then be accessed by proving two indices: the row number and the column number as displayed on the picture below:
my-timetable-2d-array

Python Challenges


The following 3 tabs contain 3 different challenges, all based on accessing information from the 2D array called timetable.

What Lesson?Today's Lessons?How Many Lessons?
Write a program that:

  1. Asks the user to input a day of the week (e.g. Tuesday)
  2. Asks the user to input a period of the day (between 1 and 5) (e.g. 2)
  3. Retrieves and outputs the lesson on that day and period (e.g. Spanish)
Write a program that:

  1. Asks the user to input a day of the week (e.g. Tuesday)
  2. Displays all five lessons for that day
Write a program that:

  1. Asks the user to input a subject (e.g. Maths)
  2. Counts and outputs the number of lessons for that subject throughout the week. (e.g. “You have 3 Maths lesson this week.”)

Python Code


Use the following code to complete all three challenges mentioned above:

Help?


The following lines of code will help you solve each of the three challenges.
What Lesson?Today's Lessons?How Many Lessons?
#INPUT
day = input("Day of the week?").title()
period = int(input("Lesson number (1 to 5):"))
while period<1 or period>5:
  period = int(input("Lesson number (1 to 5):"))

#PROCESS
lesson=""
if day=="Monday":
  lesson = timetable[0][period-1]
elif day=="Tuesday":
  lesson = timetable[1][period-1]
elif day=="Wednesday":
  lesson = timetable[2][period-1]
elif day=="Thursday":
  lesson = timetable[3][period-1]
elif day=="Friday":
  lesson = timetable[4][period-1]
else:
  print("Not a valid week day!")
  
#OUTPUT
if lesson!="":
  print("On " + day + ", lesson " + str(period) + " you have " + lesson + ".")

#INPUT
day = input("Day of the week?").title()

#PROCESS
lessons=[]
if day=="Monday":
  lessons = timetable[0]
elif day=="Tuesday":
  lessons = timetable[1]
elif day=="Wednesday":
  lessons = timetable[2]
elif day=="Thursday":
  lessons = timetable[3]
elif day=="Friday":
  lessons = timetable[4]
else:
  print("Not a valid week day!")
  
#OUTPUT
print("Your lessons on this day:")
for lesson in lessons:
  print(lesson)
#INPUT
subject= input("Enter Subject:")

#PROCESS
count=0
for day in range(0,5):
  for period in range(0,5):
    if timetable[day][period] == subject:
      count+=1
      
#OUTPUT
if count>1:
  print("You have " + str(count) + " " + subject + " lessons per week.")  
else:
  print("You have " + str(count) + " " + subject + " lesson per week.") 

Extension Task


Create three different functions for each of the three challenges and add a menu structure to your code to let the user decide what information to retrieve from their timetable.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

Colour Difference Formula

color-wheel-12-colors

RGB Colour Codes

Did you know that every colour on the screen can be represented using an RGB code (Red, Green, Blue) code. This code consists of three numbers between 0 and 255, indicating how much red, green and blue are used to recreate the colour. For instance the RGB code for:

  • Red is (255,0,0)
  • Green is (0,255,0)
  • Blue is (0,0,255)
  • Yellow is (255,255,0)
  • Orange is (255,165,0)

Graphic designer and software programmer sometimes prefer to use another notation based on hexadecimal RGB code where each of the three decimal values are converted into a two-digit hexadecimal code, resulting in a 6-digit (3×2) hexadecimal code. For instance:

  • Red is #FF000
  • Green is #00FF00
  • Blue is #0000FF
  • Yellow is #FFFF00
  • Orange is #FFA500

Check the following RGB Color picker to see how RGB codes work:

Using the RGB colour code we can represent 2563 = 16,777,216 colours.

Colour Wheel


A colour wheel is used to represent some of the most distinct colours. For instance the picture above represents a colour wheel that includes 12 colours:

RED (Hex: #FF0000 – RGB: 255, 0, 0)
ORANGE (Hex: #FF7F00 – RGB: 255, 127, 0)
YELLOW (Hex: #FFFF00 – RGB: 255, 255, 0)
CHARTREUSE GREEN (Hex: #7FFF00 – RGB: 127, 255, 0)
GREEN (Hex: #00FF00 – RGB: 0, 255, 0)
SPRING GREEN (Hex: #00FF7F – RGB: 0, 255, 127)
CYAN (Hex: #00FFFF – RGB: 0, 255, 255)
AZURE (Hex: #007FFF – RGB: 0, 127, 255)
BLUE (Hex: #0000FF – RGB: 0, 0, 255)
VIOLET (Hex: #7F00FF – RGB: 127, 0, 255)
MAGENTA (Hex: #FF00FF – RGB: 255, 0, 255)
ROSE (Hex: #FF007F – RGB: 255, 0, 127)

Colour Difference Formula


The colour difference formula is used to find out the “distance” between two colours:
color-difference-formula

We can use this formula to find out if two colours are very close (small difference).

Python Challenge


For this challenge, your task is to write a Python script that will:

  1. ask the user to input an RGB colour code,
  2. calculate the differences between this colour and each of the 12 colours of the above colour wheel,
  3. output the name of the closest colour from the colour wheel. (The colour with the smallest difference)

Test Plan


Once your code is done, complete the following tests to check that your code is working as it should:

Test # Input Values /Colour Code Expected Output Actual Output
#1 (222, 215, 21) Yellow
#2 (201, 45, 139) Rose
#3 (124, 180, 48) Charteuse Green
#4 (36, 180, 225) Azure
#5 (100, 50, 150) Violet
#6 (200, 100, 50) Orange
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Cell Phone Trilateration Algorithm

Mobile phone tracking is a process for identifying the location of a mobile phone, whether stationary or moving. Localisation may occur either via multilateration of radio signals between several cell towers and the phone, or simply via GPS.

Mobile positioning is used by telecommunications companies to approximate the location of a mobile phone and enables to offer location-based services and/or information to the mobile user.

Cell Phone Trilateration / Multilateration


Cell tower trilateration (sometimes referred as triangulation) is used to identify the location of the phone. A cell phone constantly emits roaming radio signals that may be picked up by three or more cell towers enabling the triangulation to work. Trilateration calculations estimate the coordinates of a mobile device using the coordinates (longitude,latitude) of nearby cell towers as well as the estimated distance of the device from the cell towers (e.g. either based on signal strength or by measuring the time delay that a signal takes to return back to the towers from the phone).

In this challenge we will investigate the math equations used in trilateration calculations. We will simplify the process by using a 2D model of the problem based on (x,y) coordinates (as an alternative to longitude/latitude coordinates).

trilateration-diagram

On the diagram above, each circle represents all the possible locations of a mobile phone at a given distance (radius) of a cell tower. The aim of a trilateration algorithm is to calculate the (x,y) coordinates of the intersection point of the three circles. Each circle is defined by the coordinates of its center e.g. (x1,y1) and its radius e.g. r1.

The following steps will help us calculate these (x,y) coordinates:

Step 1
The three equations for the three circles are as follows:
trilateration-formula-1

Step 2:
We can expand out the squares in each of these three equations:
trilateration-formula-2

Step 3:
Now let’s subtract the second equation from the first:
trilateration-formula-3a

Likewise, we can now subtract the third equation from the second:
trilateration-formula-3b

Step 4:
Let’s rewrite these two equations using A, B, C, D, E, F values. This would result in the following system of 2 equations:
trilateration-formula-4

Step 5:
The solution of this system is:
trilateration-formula-5

Python Implementation


Now that we understand the math needed in a trilateration calculation, let’s implement these equations in a Python algorithm using a function that will take 9 parameters (x1,y1r1,x2,y2r2,x3,y3r3) and return the (x,y) coordinates of the intersection point of the three circles.

Your task is to complete the code of the trackPhone() function that we have started for you:

GPS Positioning


Note that GPS satnav systems use a similar approach but need to be more accurate by:

  • Estimating the distance between a GPS satnav device and at least three GPS satellites. This is done by measuring the time delay that a signal takes to be sent from the satellite to the GPS satnav, and converting this time delay into a distance,
  • Using more advanced multilateration formulas based on a 3D model rather than a 2D model.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area