Computer Science
5.5 Representing Data
Encryption
Computer Science
Learning objectives
In this chapter you will learn:
• what encryption is and why it is important
• the basics of encryption techniques
• how to encrypt a message using the Caesar cipher
• how to encrypt a message using a transposition cipher
• how to encrypt a message using the Vernam cipher
• how to use frequency analysis to help decrypt ciphers
• what computational security is.
Computer Science
Overview
• Encryption is the process of scrambling data so that it
cannot be understood by another person unless they
know the encryption method and key used.
• Decryption is the process of turning the scrambled
data back into data that can be understood.
• Data is encrypted before it is transmitted and
decrypted when it is received.
• Therefore encryption keeps data secure during
transmission.
Computer Science
Encryption basics
• All encryption
works on the basis
of turning plaintext
into ciphertext
Computer Science
The Caesar Cipher
• Named after the Roman Emperor who used it for all of his
personal correspondence, the Caesar Cipher is an example of
a shift or substitution cipher.
• This method substitutes each letter of the alphabet for
another character by simply shifting the letters forwards or
backwards.
• A variation on this would be to shift letters on a random basis.
• A random substitution might look like this:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
O Z P C Y D B Q X K L A V W R I S M J E G N F T U H
The message: ‘BROADSWORD CALLING DANNY BOY’ becomes
‘ZMROCJFRMC POAAXWB COWWU ZAU’
Computer Science
Adding a keyword
• This method would be fairly easy to work out.
• It could be made more secure by adding a keyword,
for example, you might select the word ‘BEESWAX’.
• First, you need to delete any repeated letters in the
word, leaving you with ‘BESWAX’.
• Then add this word to the start of the alphabet.
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
B E S W A X C D F G H I J K L M N O P Q R T U V Y Z
Computer Science
Frequency analysis
• The Caesar cipher is one of the easiest to crack
because of the nature of language.
• In English, for example, there are certain letters
that are used more frequently than others and
certain combinations of letters that are also
common.
• By examining ciphertext for frequently used
letters and patterns of letters it is possible to
work out what letter has been substituted for
which other letter.
Computer Science
Transposition cipher
• With a transposition cipher, the letters of the message are
transposed, or re-arranged to form an anagram.
• You must re-arrange the letters according to a set pattern
to make it possible to decrypt the message.
• One way of doing this is called the railfence method where
the message is split across several lines.
• For example:
B O D W R C L I G
R A S O D A L N
If you now read the message off line by line it becomes:
‘BODWRCLIGRASODALN’.
• If you were decrypting this message you
would need to know the key is that it
has been split over two lines.
Computer Science
Vernam cipher
• Gilbert Vernam invented the Vernam cipher around 100
years ago as a means of keeping data secure while it was
being transmitted using telex machines.
• The Vernam cipher is an example of a class of encryption
techniques known as one-time pad techniques.
• The key that is used is a sequence of letters that should be
as long as the plaintext that is being encoded.
• The key can be recorded on a pad, although in the Vernam
case the key was written on a punched taped for input into
the telex device.
• For maximum security, a particular key should only be used
to encrypt one message, hence the name
one-time pad.
Computer Science
Creating a Vernam cipher
• To encrypt a message, each character in the
plaintext is combined with the character at the
corresponding position in the key.
• Convert the corresponding plaintext and key
characters into a binary code (originally a 5-bit
Baudot code).
• Use a logical XOR on these binary representations
to produce a new binary code, which in turn
maps back to a character.
Computer Science
Computational security
• The Vernam or one-time pad cipher is the only cipher
that is considered to be 100% mathematically secure.
• All other ciphers can be cracked given enough time and
enough ciphertext to work on.
• This leads to the concept of computational security or
computational hardness.
• A cipher that is computationally secure is theoretically
breakable but not using current technology in a
timeframe that would be useful.
• This recognises the fact that although most encryption
can theoretically be cracked, in practice it will be
secure enough to withstand most
threats.
Computer Science
Code cracking techniques
• Identifying commonly used techniques: Many
ciphers are based on substitution or transposition.
• Reverse engineering: This is the process of going back
step by step until you work out how something has
been put together.
• Dictionary attacks: This is the process of using a
dictionary that contains common words and phrases.
• Brute-force: This is similar to a dictionary attack but
takes much longer as, rather than looking at common
words and phrases, it looks at every single permutation
of characters that can be created.