
The following “code spotlight” activity will test your knowledge of some of the key programming techniques using in procedural programming.
You might find out more about procedural programming concepts using the following online activities:
The following “code spotlight” activity will test your knowledge of some of the key programming techniques using in procedural programming.
You might find out more about procedural programming concepts using the following online activities:
Are you confident with your knowledge of key procedural programming concepts, including sequencing, selection, iteration and the use of subroutines?
You can find out more about the key programming constructs using in procedural programming on the following page.
Procedural Programming ConceptsOpen Crossword Puzzle in a New Window
Are you confident with your knowledge of key Relational Databases concepts?
You can find our more about Relational Databases on the following page.
Relational Databases ConceptsOpen Crossword Puzzle in a New Window
Are you confident with your knowledge of key Object-Oriented Programming concepts: Classes & Objects, Inheritance, Encapsulation, Polymorphism and Abstract Classes?
You can find our more about OOP concepts on the following page.
Object-Oriented Programming ConceptsOpen Crossword Puzzle in a New Window
Click on the picture below to check your knowledge of key Object-Oriented Programming concepts: Classes & Objects, Inheritance, Encapsulation, Polymorphism and Abstract Classes.
Object-Oriented Programming ConceptsOpen Domino ActivityBefore taking this quiz, make sure you are confident with your understanding of key Object-Oriented Programming concepts.
Object-Oriented Programming (OOP) is a programming approach based on objects and classes. The object-oriented paradigm allows us to organise software as a collection of objects that consist of both data/attributes and behaviours.
This programming concept appeared in the 1980s and most modern high level programming languages have object-oriented features. Python, Java, C++, Ruby, PHP, Javascript are all OOP programming languages. Sometimes OOP features have been retro-fitted to an existing procedural language: This is the case for C++ which is a fully OOP language based on the procedural language C. Nowadays most advanced pieces of software or video games are built using object-oriented programming concepts.
Object-Oriented Programming makes it easier to design and structure code because:
A class consists of a collection of states (a.k.a. attributes or properties) and behaviours (a.k.a. methods).
An object is an instance of a class. The attributes of an object are stored using variables for storing data and the behaviour/methods of an object are implemented as functions or procedures and can be used to perform operations on the data.
Superhero Class
Some of the methods of a superhero are:
The diagram on the right represents the Superhero Class with its attributes and its methods. Note that we do not need to represent the constructor on this diagram as it is assumed that all classes have a constructor. (In Python the constructor of a class is the __init__() function.)
spiderman = new Superhero("Spiderman","Wrist web-shooters to shoot spider web material",10) batman = new Superhero("Batman","Night vision",10) superman = new Superhero("Superman","Can fly",20)
For instance, let’s consider an online shop that sells different types of products (items) such as DVDs, Books, and Mp3s.
Item Class
Sub-classes can then be defined with additional attributes and methods which are more specific. For instance:
DVD Class:
Book Class:
The MP3, DVD and Book sub-classes will inherit the properties and methods of the parent class (Item) as represented in green below.
DVD Class:
Book Class:
For example we could have a class representing hybrid cars, that would inherit the properties and method of both electric cars and petrol cars.
A private attribute or a private method can only be accessed from methods of the class. They cannot be directly accessed from outside the class.
A public attribute or a public method can be accessed from anywhere (other methods of the class or from outside the class).
For instance, let’s consider a Car class with the following attributes and methods:
In our car racing game, we would instantiate an object called playerCar from this Car class.
playerCar = new Car("Mini","Cooper")
If all methods and properties are declared as public, then we would be able to access them from anywhere in the code. e.g.
playerCar.speed = 70 playerCar.fuelLevel = 45 playerCar.accelerate(5) # increase speed by 5mph playerCar.drive(10) # drive 10 miles PRINT("Your current fuel level is:" PRINT playerCar.fuelLevel
However, it is considered good practice to “hide” some properties or methods from the “outside world” by making these private. In this case these private properties and methods cannot be accessed from outside the class.
For instance, in the example above, we may decide that both attributes speed and fuelLevel should be set at private. In this case none of the following three lines would compile and hence these would have to be removed:
playerCar.speed = 70 playerCar.fuelLevel = 45 PRINT playerCar.fuelLevel
We could still alter the content of the fuelLevel and the speed of the car in the code of the fillUp(), accelerate(), slowDown() and drive() methods of the car.
playerCar.fillUp(45) # Add 45 litres of petrol in the tank playerCar.accelerate(50) # increase speed by 50mph playerCar.drive(10) # drive 10 miles
For instance, to retrieve the fuelLevel of the player car we could have a new public method called getFuelLevel() and use it to inform the user of how much petrol they have left in their tank.
PRINT "Your current fuel level is:" PRINT player.getFuelLevel()
We may also define a setter for this property in case we want to give an option for the player to reset their tank to a specific value or to empty it. e.g.
player.setFuelLevel(0) # Emptying the fuel tank
Note that using setters is also useful to prevent direct access to a property and implement validation checks within the setter methods.
For instance if the fuelLevel was a public property then the following code would be accepted even though a car cannot have 999 litres of petrol (999 > tankCapacity)!
playerCar.fuelLevel = 999
By making the fuelLevel property private and forcing the use of a setFuelLevel() public method (setter), we can implement in the code of the setFuelLevel() method a validatiom check that cannot be bypassed to ensure that the parameter given is a positive number, lower or equal to the tankCapacity. e.g.
FUNCTION setFuelLevel(quantity) IF quantity<0 THEN fuelLevel = 0 ELSE IF quantity > tankCapacity THEN fuelLevel = tankCapacity ELSE fuelLevel = quantity END IF END FUNCTION
The setter could then be used in our code as follows:
playerCar.setFuelLevel(45) # reset fuel level to 45 litres
On occasions, as this is the case in our example, the drive() method of the Car class is only defined but not implemented at all (an empty function, without code) in the Car class. It will be overwritten and properly implemented in the sub classes instead.
For instance, let’s consider our Superhero class to which we would like to add a method to set the Date of Birth (DoB) of a superhero. We could write this same method several times to accept different parameters such as:
The method could accept a date parameter as a string in the “DD/MM/YYYY” format.
PROCEDURE setDoB(string:date) # date in DD/MM/YYYY format
e.g.
spiderman.setDob("15/08/1962")
The same method can be implemented a second time, taking three parameters as follows:
PROCEDURE setDoB(integer:day, integer:month, integer:year)
e.g.
spiderman.setDob(15,08,1962)
Having multiple implementations of the same method to accept different parameters (different number of parameters or parameter of different data types) is called over-loading polymorphism.
For instance, let’s revisit the online shopping system where we are selling three types of items: MP3s, DVDs and Books. The MP3 class, DVD class and Book class inherit from the parent Item class. Objects will be instantiated from the MP3 class, DVD class or Book class. We will never instantiate an object directly from the Item class. This is why the Item class is called an abstract class.
So to sum up, an abstract class:
These tools are still very relevant when designing OOP programs. However additional tools can be used to identify the various classes/objects needed, their attributes and behaviours, the relationships between classes (inheritance) and how the various objects will interact with each other. One of the most widely used tool is UML, a standard used to draw a range of diagrams to visualise and design a system based on an OOP approach.
Click on the following banner to learn more about UML:
Cryptography is the art of encoding and decoding secret messages. Cryptographic techniques have been used for thousands of years, well before the introduction of computers, and the techniques have evolved since. (e.g. See how the Caesar Cipher was used by the roman empire 2000 years ago).
More recently, with the introduction of electronics and later on computer science, it has been possible to implement more advanced encryption techniques based on complex mathematical calculations. (e.g. See Alan Turing’s work on breaking codes encrypted by the Germans using the Enigma Machine during World War 2).
Symmetric Encryption: The same cryptographic key is used both to encrypt and decrypt messages.
The following algorithms use Symmetric Encryption: RC4, AES, DES, 3DES, QUA.
Symmetric keys are usually 128 or 256 bits long. The larger the key size, the harder the key is to crack. For example, a 128-bit key has around 340,000,000,000,000,000,000,000,000,000,000,000,000 encryption code possibilities. This means that a brute force attack (trying every possible key until you find the right one) is no longer a realistic approach to crack such a key.
Asymmetric Encryption: A public key is used to encrypt plaintext into ciphertext whereas a private key is used to decrypt a ciphertext.
As they involve a pair of keys, asymmetric algorithms tend to be more complex to implement (and slightly slower to execute) than symmetric algorithms. The following algorithms use Asymmetric Encryption: RSA, Diffie-Hellman, ECC, El Gamal, DSA.
Asymmetric keys are typically 1024 or 2048 bits long which leads to 21024 or 22048 encryption codes. (We did not even try to write these numbers down as they would contain several hundreds digits!)
The HTPPS protocol uses SSL (Secure Sockets Layer), a standard security technology to create an encrypted link between a server and a client.
The following steps describe the process of creating a secure connection between a web browser and a web server. It is called the SSL handshake and uses both symmetric encryption and asymmetric encryption:
To recap, the 5 steps of a SSL handshake are:
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight GMT).
This explains how date & time values are actually stored on computers: using an integer value representing the number of seconds since 01/01/1970 00:00:00 GMT. Note that a negative value would represent a date prior to 01/01/1970.
For instance, the current date & time is:
To do so you will need to calculate the number of seconds elapsed between the date given and 01/01/1970 00:00:00.
To simplify your calculations you can make the following assumptions:
You can test you script with today’s date and compare the output of your program with the Epoch date that appears at the top of this blog post.
Epoch/Unix Timestamp | Date | Event |
410270400 | 1 January 1983 | ARPANET adopted TCP/IP on January 1, 1983, and from there researchers began to assemble the “network of networks” that became the modern Internet. The online world then took on a more recognizable form in 1990, when computer scientist Tim Berners-Lee invented the World Wide Web. |
479736000 | 15 March 1985 | The first domain name registered was Symbolics.com. It was registered March 15, 1985, to Symbolics Inc., a computer systems company in Cambridge, Massachussetts. |
773409600 | 05 July 1994 | Amazon was founded in the garage of Bezos’ rented home in Bellevue, Washington. In July 1995, the company began service as an online bookstore. |
904910400 | 4 September 1998 | The search engine Google was invented by computer scientists Larry Page and Sergey Brin. It was named after a googol (the name for the number 1 followed by 100 zeros) found in the book “Mathematics and the Imagination” by Edward Kasner and James Newman. |
1075896000 | 4 February 2004 | The social network Facebook was launched on February 4, 2004, by Mark Zuckerberg, along with fellow Harvard College students and roommates Eduardo Saverin, Andrew McCollum, Dustin Moskovitz and Chris Hughes |
The enigma machine was used during World War II to encrypt secret messages.
Your messages would most likely be encrypted using various encryption techniques.
The issue is that, occasionally, you may receive messages but may not be 100% sure that these messages are genuine messages or not. It could be that your enemies are sending messages pretending to be one of your allies. They may use the same encryption techniques to lure you. Also, your enemies may have intercepted some of your messages and altered them to confuse you.
This is the reason why secret services had to come with a solution when sending and receiving messages to validate the integrity of a message: So, when a message is received, the recipient should be 100% confident that:
In the 1950’s the first hashing algorithms used to validate the integrity of a message were introduced. They were using the idea of using a complex mathematical calculations on the content of a message (the key) to generate a hash called a checksum that would be appended at the end of the message to be sent.
Let’s consider the following secret message:
Let’s consider a very basic hashing algorithm that takes this message as an input and returns the hash as being the number of characters of this message.
When applying our hashing algorithm to our secret message we get a checksum of 23.
We will now append this checksum at the end of the message before sending it. Our new message is now:
The recipient of this message will run the same hashing algorithm with the content of the message. They will then compare the resulting checksum with the checksum that has been received. If the two checksums are equal, they can be fairly confident that the message is genuine.
If an enemy intercepts the message and tries to alter it, they will not know how the checksum was calculated. Hence they may change the content of the message but will not be able to recalculate the right checksum. (Provided that your hashing algorithm is not as obvious as calculating the number of characters in the message: This would be a very easy algorithm to guess and recreate).
A message which has been tampered with by an enemy may look like this:
A message which has been tampered with.
When the recipient receives this message, they will apply the same hashing algorithm and get a checksum of 24. When comparing this with the checksum of the received message they will realise that both checksums do not match and hence will be able to identify that the message is invalid: It has either been produced by someone who does not know the hashing algorithm in use, or it has been tampered with before reaching its recipient. In both case the recipient will have to discard this message as it is not reliable.
Note that alterations can be caused intentionally by a third party (e.g. a hacker) or can be the consequence of an unintentional “glitch” in the communication. (e.g. poor quality of communication link such as wifi interference, collisons of data packets on a TCP/IP network, human or sensor error when inputting a message or scanning a barcode, etc.)
Nowadays hashing algorithms used for integrity validation are widely used in a range of contexts such as:
The hash of a hashing algorithm used for integrity validation is often called a checksum and is appended at the end of the data to be transferred.
Sometimes the hash is called a check digit if it only consists of one digit. This is the case for barcodes, ISBN numbers and credit card numbers where the last digit of the code is a check digit, the result of a complex calculation using all the other digits of the code.
You can check the following links to investigate the use of check digits on a barcode or on a credit card (using the Luhn Algorithm to validate a credit card number).