More results...

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

TCP/IP Protocols and Packet Switching

The TCP/IP protocols are a suite of protocols used to support different types of communication between devices over an IP network such as the Internet.

These protocols resulted from research and development conducted by the US Defense Advanced Research Projects Agency (DARPA). After initiating the pioneering ARPANET in 1969, DARPA started work on a number of other data transmission technologies which relied on packet switching: when sending data across two devices/computers, data is packetized, addressed, transmitted, routed, and received.

This research lead to the definition of the TCP/IP Protocols which are the underlying protocols for all Internet communication. They rely on packet switching and the use if IP addresses to locate devices on an IP network or on the Internet .

Packet Switching:

Let’s investigate how packet switching is used to transfer data (in the example below, a picture file) between two devices.

Step 1: Data packetsStep 2: AddressingStep 3: RoutingStep 4: Error DetectionStep 5: Re-ordering
Packet-Switching-1
Packet-Switching-2
Packet-Switching-3
Packet-Switching-4
Packet-Switching-5

Packet Switching: Quiz!

Packet Switching – Quiz!Open in New Window

The 4 Layers of the TCP Stack

Internet communications do not rely only on the TCP/IP protocol. Every communication will use a range of protocols depending on the type of data link used (Ethernet cable, Wi-Fi, Optic Fibre, etc.) as well as the type of application being used (E-Mail Client, Web Browser, FTP Client, etc.)

All the protocols used on a TCP/IP network have been categorised/grouped into 4 abstract layers called the TCP Stack.

A layer can hence be defined as being a sub-group of protocols needed in a network communication.

The four layers to the TCP stack are:

  • The Application Layer: This layer regroups a range of application protocols such as:
    • HTTP & HTTPS protocols for accessing web pages from a web server. When using the HTTPS protocol, all data being transferred is encrypted,
    • FTP protocol for transferring (downloading & uploading) files between two computers,
    • SMTP protocol for sending/transferring e-mails to an e-mail server,
    • IMAP and POP3 for retrieving e-mails from an e-mail server.

  • The Transport Layer: The main protocol of this layer is the TCP protocol used to communicate using packet switching.
  • The Internet Layer: This layer regroups routing protocols using the IP addressing system. This layer regroups the IP protocols such as IPv4 protocol and more recently the IPv6 protocol for uniquely addressing devices on the Internet.
  • The Link Layer (aka Physical Layer): This layer regroups various protocols used to transfer data across a data link. This includes the Ethernet protocol used to transfer data over an Ethernet cable and various wireless communication protocols (Wi-Fi, Bluetooth, etc.). The protocols used depend on the type of hardware, network topologies and communication links being used to transfer data across the network.

IP Addresses vs. Domain Names

When we use our web browser to access a web page, it is very unlikely that we know the IP address of the web-server hosting the required web page. We may however enter a web address / URL using a domain name such as 101computing.net.

Domain Name Servers (DNS) are the Internet’s equivalent of a phone book. They maintain a directory of domain names and translate them to numerical IP addresses. These IP addresses are used to identify and locate the web-servers on the Internet.

Domain names such 101computing.net are easy for people to remember. Computers however access websites based on IP addresses, hence the needs for domain name servers: when typing a website address in your web browser such as http://www.101computing.net, your request will reach a domain name server that will convert the domain name part of the address (101computing.net) into its matching IP address.

DNS-Domain-Name-Server


Did you know?


Currently most IP addresses are using the IPv4 format, based on 4 numbers between 0 and 255 sepearated by a dot.
ipv4

The IPv4 protocol however will soon be upgraded to the IP version 6 (IPv6) internet protocol. The reason for this upgrade is that there is need to generate more IP addresses to allow more devices (webservers, desktops, laptops, smartphones, smartwatches and other connected objects) to have a unique IP address on the network. An IPv6 address is based on 128 bits (instead of 32 bits for an IPv4 address).
ipv6

MI6: Mission Alpha

cyber-securityThis is a confidential mission with the highest level of priority. The MI6 needs your skill to complete a very confidential mission:

Mission Code: Alpha-01

Mission Priority: Critical

Mission Context:
The MI6 network has been hacked! As a result, all of our secret agents’ smartphones have been locked and so has the main MI6 Server. All Mi6 operations are currently on pause as it is impossible for us to communicate effectively with our secret agents.

A network forensic team has been dispatched at the Mi6 headquarters. They are currently reviewing all the log files for the past 12 hours to see if the hacker has left any “footprints” when hacking into the network. The MI6 firewall has not detected any suspicious activity and we hence believe the hack was the result of an insider attack. While scanning the main servers for malware, the network forensic team identified twelve suspicious files containing computer code.

We believe these 12 extracts of code have been used to lock the smartphones of our 12 secret agents (001 to 012).

To unlock the main server, we need an activation code. This activation code consists of 12 short codes of 3 characters each. We believe each agent was sent one of these short codes.

Mission Code: Alpha-01

Your Task:
Study the 12 code extracts to unlock the phones of our twelve secret agents. If you manage to unlock a phone, check if a message was sent to this phone to retrieve the 3-character long activation code. Repeat this process for each phone to retrieve the 12 activation codes. Enter these codes in the corresponding input boxes to check them one at a time. Then enter them on the tablet below to regain full access to the MI6 server.

MI6: Mission Alpha-01Open in New Window


Mission Code: Alpha-02

Mission Code: Alpha-02

Mission Priority: Critical

Mission Context:
Following this recent hacking attack on the MI6 central server and on all our secret agents’ smartphones, a Network Forensics Team from the MI6 Cyber Security Division has been tasked to:

  1. Conduct a Network Forensics Analysis of the recent hacking attack.
  2. Perform a full review of the current network security measures in place at the MI6 to protect the network against a wide range of potential threats.
MI6: Mission Alpha-02: Network Forensics ReportOpen in New Window

Your Task:
The Network Forensics Team needs your help to complete the full review of the Network Security measures in place at the MI6. Your task is to complete the table in the report to describe the potential Network Security threats and use the information given in the Network Forensic Report to identify the measures currently in place to minimise/prevent these threats.


Mission Code: Alpha-03

Mission Code: Alpha-03

Mission Priority: High

Mission Context:
Now that you have completed a full review of the Network Security measures used to protect the MI6 network from various threats we would like you to you to make additional recommendations on how the MI6 could make sure their network is even more secure. To do so we would like you to create a presentation to describe how the following strategies could be used to protect the network further and, for each of them, identify the threat(s) that they would address:

  1. Penetration testing,
  2. 2-Step Authentication,
  3. Additional Authentication Methods using Biometrics,
  4. CAPTCHA,
  5. SPAM filters,
  6. Account Lockout Threshold,
  7. Proxy Servers,
  8. VPNs.

Dice Score Frequency Analysis

two-diceIn this challenge we will use a Python algorithm to perform a frequency analysis of the score obtained when throwing a set of two dice.

Frequency analysis using 1 dice


Let’s consider a single 6-sided dice.

When using single dice, the score of the dice can be any of the 6 values/sides (1 to 6). Each value has an equal probability of 1/6.

The dice experiment can be simulated using a computer algorithm to simulate throwing a dice a 1,000 times and keeping a record of the number of times each of the 6 values appeared. We can then calculate the frequency of each value as a percentage. In theory, each value should have a very similar frequency of around 16.67% (matching the 1/6 probability).

When completing such an experiment in real life, we would mot likely use a tally chart to record the number of occurrences for each of the 6 possible values.
dice-tally-chart

To record our “tallies” in a Python program we will use a dictionary with 6 keys (the 6 values of a dice, from 1 to 6) and for each key, the associated value will be the number of occurrences of when the value appeared.

Here is the Python implementation of our dice experiment (frequency analysis).

Run the above code several times.

  • Do you notice the frequencies changing slightly every time you run this code?
  • Does the experiment confirm the theory: each side having an equal probability, the percentage for each value should be 16.67%?
  • What do you think will happen if, instead of 1,000 iterations you were completing 1,000,000 iterations?
  • Change the value of n in the above code from 1,000 to 1,000,000 and run the code. Does the outcome confirm your prediction?

Using two dice


We are now going to simulate the same experiment, this time using two dice, and recording the total score (by adding the value of both dice). The dice score will be as follows:

Total Score Possible Combinations Probability
2 1+1 1/36 = 2.78%
3 1+2 or 2+1 2/36 = 5.56%
4 1+3 or 2+2 or 3+1 3/36 = 8.33%
5 1+4 or 2+3 or 3+2 or 4+1 4/36 = 11.11%
6 1+5 or 2+4 or 3+3 or 4+2 or 5+1 5/36 = 13.89%
7 1+6 or 2+5 or 3+4 or 4+3 or 5+2 or 6+1 6/36 = 16.67%
8 2+6 or 3+5 or 4+4 or 5+3 or 6+2 5/36 = 13.89%
9 3+6 or 4+5 or 5+4 or 6+3 4/36 = 11.11%
10 4+6 or 5+5 or 6+4 3/36 = 8.33%
11 5+6 or 6+5 2/36 = 5.56%
12 6+6 1/36 = 2.78%

Your Task:


Your task consists of adapting the Python program given above (1 dice experiment) to implement the experiment with two dice and see whether your program produces the expected probabilities for all possible scores from 1 to 12.
unlock-access

Solution...

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

Random Odd and Even Numbers

random-numbersIn this challenge we will focus on using the random library to generate random numbers in Python.

The randint() function is used to generate a random integer (whole number) within a given range.

import random
number = randint(1,100)

The above code would generate a random number between 1 and 100.

The aim of this challenge is to write our own function called randomOddNumber() to generate a random odd number within a given range and a another function called randomEvenNumber() to generate a random even number. Both functions will take two parameters, the lower and higher values of the range.

Random Odd Number Functions


We will investigate three different algorithms to implement the randomOddNumber() function:
Method #1: SequencingMethod #2: IterationMethod #3: Selection
The first method is based on a sequencing algorithm.
sequencing-label
Here is the approach we will use:
To generate an odd number, let’s say between 0 and 100, we will first generate a random number between 0 and 49, then multiply this number by 2 (this will hence become an even number between 0 and 98) and finally we will add 1 to make it an odd number (between 1 and 99).

Python Code:

The second algorithm is based on a while loop (a form of iteration).
iteration-label
With this approach we are generating a random number between 1 and 100. We will repeat this process as long as the number generated is even (not odd). A number is even if the remainder of dividing this number by two is zero.

Python Code:

Our third approach will be based on using an IF statement, a form of selection.
selection-label
We will generate a random number, check if this number is odd or even by checking whether the remainder of dividing this number by two is zero (for an even number) or 1 (for an odd number). If the number is even, we will add 1 to this number to change it to an odd number.

Python Code:

Random Even Number Functions


Your task consists of adapting the above three functions to create three additional functions, this time to generate random even numbers using all three methods/programming constructs: sequencing, selection and iteration.

Extension Task: Random Prime Number Function


For this more complex extension task, you will need to write a function called randomPrimeNumber() to generate a random prime number within a given range. This function will take two parameters: the lower and higher values of the range.

unlock-access

Solution...

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

Multi-threading in Python

multi-threadingIn this blog post we will investigate how to implement concurrent processing in a Python program to allow multiple processes to be executed concurrently.

To do so will create and run multiple threads in our program and will need to use Python 3 and the threading library.

So what’s a thread and what is multi-threading?
In Python, a thread is a sperate process / flow of execution. Running multiple threads in a program allows multiple tasks to progress concurrently.

Let’s investigate one application of multi-threading using a basic computer program used to find very large prime numbers.

Prime Number Finder

In this example, we will create a class called PrimeNumberThread that derives from the Thread class of the threading library.

This class/thread will be used to find very large prime numbers from any given starting position (e.g. Checking any number greater than 100,000,000,000,000 one by one to see if they are a prime number or not).

We will then run three threads concurrently, each thread starting with a different starting position .e.g.

  • Thread 1 will look up for prime numbers, starting from number 100,000,000,000,000
  • Thread 2 will look up for prime numbers, starting from number 300,000,000,000,000
  • Thread 3 will look up for prime numbers, starting from number 500,000,000,000,000

As soon as a thread finds a prime number, it will display it on screen. All three threads will be working concurrently. You can run the following code to see the output generated by all three threads…

The above program is a very brief introduction to what is meant by running multiple threads in a computer program. There are a lot more concepts linked to multi-threading and you can find out more about these concepts by reading through this tutorial on multi-threading with Python.

The Legend of Pachacuti’s Golden Shield

golden-shieldA few weeks ago, a group of British trekkers stumbled upon the remains of what is believed to be an undiscovered Inca temple in the middle of the Peruvian rainforest. One of their most unexplained discoveries is a collection of 12 engraved slates and a parchment representing a map of the newly discovered site. The slates are engraved with some sort of code. We believe these 12 slates could help locate the 12 pieces of Pachacuti’s Golden Shield.

Pachacuti’s was a famous Inca ruler in the 15th century who transformed the kingdom of Cusco in the Inca empire. For many decades archaeologists from around the world have been excavating many sites in the Urubamba Valley hoping to locate the Pachacuti’s Golden Shield, a uniquely carved shield of inestimable value.

It would appear that the shield may have been smashed into 12 pieces and each of these may have been hidden on the site of this newly discovered temple. We are asking for your help to see if you can work out the exact location of the 12 pieces of Pachacuti’s Golden Shield using the code from the 12 slates and the parchment/map found alongside these slates. We are counting on you! Good luck!

Pachacuti’s Golden ShieldOpen in New Window
Pachacuti’s Golden ShieldOpen in New Window
unlock-access

Solution...

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

The School Lockers Puzzle

On the first day of school, the principal of Locker High school decides to conduct an experiment. The school has exactly 1,000 students and 1,000 lockers all lined up alongside the main corridor of the school.
school-lockers-puzzle

  1. The principal asks the first student to walk down the main corridor of the school to close all the lockers.
  2. The principal then asks the second student to walk down the main corridor and open every other locker.
  3. The principal then asks the third student to walk down the main corridor and either open every third locker if it is closed, or close it if it is open.
  4. The fourth student will then repeat the same process for every fourth locker.
  5. And so on, till the last of the 1,000 students repeats this process for every 1,000th locker, so in fact, just opening the 1,000th locker if it is closed, or closing it if it is already open.

At the end of this experiment the principal decides to count the number of lockers which are closed.

It is possible to solve this puzzle using your mathematical skills, however in this challenge, your task is to implement a computer program (using Python) to simulate this experiment and at the end, count and output the total number of lockers which are closed.


We have started the code and completed three sections of the code as follows:

Step 1:
We start by initialising an array/list of 1,000 values representing the 1,000 lockers:

  • 0 will represent an open locker,
  • 1 will represent a closed locker.

“To start with all the lockers a open!”

lockers = [0] * 1000

Step 2:

“The first student walks down the corridor to close all the lockers!”

for i in range(0,1000):
  lockers[i] = 1

A similar approach will need to be implemented to reproduce the actions of the remaining 999 students! This will be your task!

Step 3:

“At the end, the principal of the school counts how many lockers are closed!”

total = 0 
for i in range(0,1000):
   total = total + lockers[i]
   
print("Total number of lockers closed: " + str(total))

Python Code

You will need to complete the following code to solve this challenge:

The Principal’s padlock

The solution to the above challenge is the combination of the principal’s padlock. Use the output of your code to see if you can unlock this padlock!

unlock-access

Solution...

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

2D Dice Grid Scoring Algorithm

This challenge is based on a 4×4 grid of dice (16 dice in total). Each game starts by shaking the grid to generate a new grid of 16 values.
2D-dice-grid

All dice are 6-sided dice, generating random values between 1 and 6 when the grid is shaken. The grid can be simplified by showing the actual dice values:
2D-dice-grid-values

Once the new grid is set, its score can be calculated by identifying specific patterns as follows:

  1. Start with a score of 0,
  2. If all four corners are even numbers, add 20 pts to the score,
  3. If all four corners are odd numbers, add 20 pts to the score,
  4. If all four dice on a diagonal are even numbers, add 20 pts to the score,
  5. If all four dice on a diagonal are odd numbers, add 20 pts to the score,
  6. If all four dice on on any row are even numbers, add 20 pts to the score,
  7. If all four dice on on any row are odd numbers, add 20 pts to the score,
  8. If all four dice on on any column are even numbers, add 20 pts to the score,
  9. If all four dice on on any column are odd numbers, add 20 pts to the score,
  10. Add to the score the total value (sum) of all 16 dice.

So for example, with the above grid, we can calculate the score of the grid as follows:
2D-dice-grid-score

Python Implementation

To help you with this challenge we have started the code for you by creating 4 functions to:

  • Generate/shake the grid of 16 dice.
  • Display the 4×4 grid on screen.
  • Check if a number is even.
  • Check if a number is odd.

We have also implemented the first section of the scoring algorithm, by initialising the grid score to 0 and by checking if all four corners are even. If so the score is increased by 20pts.

Your task is to complete the following code to implement the full scoring algorithm using the 10 rules mentioned above.

unlock-access

Solution...

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

Tagged with:

Diagonal Difference Calculator

Let’s consider a square matrix of n x n. (n columns and n rows). The diagonal difference of a square matrix is the absolute difference between the sums of its diagonal.

Let’s look at an example based on the following 3 x 3 square matrix:
sqaure-matrix
Here is how we would calculate the diagonal difference for this matrix:
diagonal-difference

Python Challenge

We have created a Python script that asks the user to input the dimension n of a square matrix (any positive integer value). Our python scripts generates a n x n matrix using random values and displays it on screen as a 2D grid.

Your task is to complete this script to automatically calculate the diagonal difference of the given matrix. (Make sure this value is always a positive value!)

Python Code

Extension Task #1

Your first extension task is to create an additional function to calculate the sum of the 4 corner values of the square matrix:
square-matrix-four-corners

Extension Task #2

Your second extension task is create an additional function to calculate the average value of all values stored in the matrix.
square-matrix-average-value

unlock-access

Solution...

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

Wind Speed Conversions and the Beaufort Scale

weather-vaneBefore going to sea, any sailor should check the marine weather forecast to check on different aspects of the weather including the direction and strength of the wind (wind speed).

The wind speed can be measured using different units such as mph (miles per hour), km/h (km per hour) but sailors tend to prefer to use knots. A knot represents a speed of 1 nautical mile per hour, and a nautical mile is exactly 1,852 meters!

The Beaufort wind force scale was introduced in 1805 by a Royal Navy officer, Francis Beaufort. It relates wind speeds to observed conditions at sea or on land. Nowadays, the scale contains thirteen values (from zero to twelve): A force 0 wind represents very calm wind conditions whereas a force 12 wind represents a Hurricane-force wind!

Here is the full Beaufort scale:

Beaufort Wind Force Scale
Force Description Wind speed Wave height Sea conditions Land conditions
0 Calm < 1 knot 0 ft (0 m) Sea like a mirror Smoke rises vertically.
1 Light air 1–3 knots 0–1 ft Ripples with appearance of scales are formed, without foam crests Direction shown by smoke drift but not by wind vanes.
2 Light breeze 4–6 knots 1–2 ft Small wavelets still short but more pronounced; crests have a glassy appearance but do not break Wind felt on face; leaves rustle; wind vane moved by wind.
3 Gentle breeze 7–10 knots 2–4 ft Large wavelets; crests begin to break; foam of glassy appearance; perhaps scattered white horses Leaves and small twigs in constant motion; light flags extended.
4 Moderate breeze 11–16 knots 3.5–6 ft Small waves becoming longer; fairly frequent white horses Raises dust and loose paper; small branches moved.
5 Fresh breeze 17–21 knots 6–10 ft Moderate waves taking a more pronounced long form; many white horses are formed; chance of some spray Small trees in leaf begin to sway; crested wavelets form on inland waters.
6 Strong breeze 22–27 knots 9–13 ft Large waves begin to form; the white foam crests are more extensive everywhere; probably some spray Large branches in motion; whistling heard in telegraph wires; umbrellas used with difficulty.
7 High wind,
moderate gale,
near gale
28–33 knots 13–19 ft Sea heaps up and white foam from breaking waves begins to be blown in streaks along the direction of the wind; spindrift begins to be seen Whole trees in motion; inconvenience felt when walking against the wind.
8 Gale,
fresh gale
34–40 knots 18–25 ft Moderately high waves of greater length; edges of crests break into spindrift; foam is blown in well-marked streaks along the direction of the wind Twigs break off trees; generally impedes progress.
9 Strong/severe gale 41–47 knots 23–32 ft High waves; dense streaks of foam along the direction of the wind; sea begins to roll; spray affects visibility Slight structural damage (chimney pots and slates removed).
10 Storm,
whole gale
48–55 knots 29–41 ft Very high waves with long overhanging crests; resulting foam in great patches is blown in dense white streaks along the direction of the wind; on the whole the surface of the sea takes on a white appearance; rolling of the sea becomes heavy; visibility affected Seldom experienced inland; trees uprooted; considerable structural damage.
11 Violent storm 56–63 knots 37–52 ft Exceptionally high waves; small- and medium-sized ships might be for a long time lost to view behind the waves; sea is covered with long white patches of foam; everywhere the edges of the wave crests are blown into foam; visibility affected Very rarely experienced; accompanied by widespread damage.
12 Hurricane force ≥ 64 knots ≥ 46 ft The air is filled with foam and spray; sea is completely white with driving spray; visibility very seriously affected Devastation.

Python Challenge

In this challenge we will write a python script that:

  1. lets the user enter a wind speed in the unit of their choice (mph, km/h, knot)
  2. converts this wind speed in knots and lookup the matching find force,
  3. looks up for the matching wind force from the Beaufort scale,
  4. outputs the wind force and both the matching sea and land conditions

Python Code

You can complete the python code using the following trinket:

unlock-access

Solution...

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