Lab 3 - Classical Cryptography
Lab 3 - Classical Cryptography
3
Lab
FOR EDUCATIONAL PURPOSE ONLY
Classical Cryptography
Introduction to Information Assurance and Security
March 2023
Internal circulation only
<Strictly prohibited from posting on the internet in any form>
2
A. OVERVIEW
1. Introduction and learning objectives
▪ Cryptography plays a vital role in modern digital communication systems. The
Oxford Dictionary1 defines cryptography as "the art of writing or solving codes" with
"codes" elsewhere defined as "a system of pre-arranged signals, especially used to
ensure secrecy in transmitting messages". Historically, cryptography focused
exclusively on ensuring private communication between two parties sharing secret
information in advance using "code". It was used primarily for military, government
applications, plus a few niche applications in industry for centuries.
But cryptography nowadays is much more of a science. We would say that modern
cryptography involved “the study of mathematical techniques for securing
information, systems, and distributed computations against adversarial attack".
Cryptography has gone from "an art form that dealt with secret communication for
the military" to "a science to secure systems for ordinary people all across the globe".
It deals with mechanisms for ensuring integrity, techniques for exchanging secret
keys, protocols for authenticating users, electronic auctions and elections, digital
currency, and more.
▪ The learning objective of this lab is for students to get familiar with the concepts
in secret-key encryption, particularly in classical cryptography. After finishing the
lab, students should gain first-hand experience with encryption algorithms.
Moreover, students may use crypto tools and write simple programs to
encrypt/decrypt messages. This lab will cover the following topics regarding
classical ciphers:
o Monoalphabetic substitution ciphers - Frequency analysis.
o Polyalphabetic ciphers.
o Permutation ciphers.
1
https://www.oxfordlearnersdictionaries.com/
3
▪ The following section summarizes some of the key aspects to help you review the
knowledge that you may already have obtained before getting started. You can also
read the textbooks and related references that I listed in section 1.4 for more details.
Concept
Before beginning, we define some terms. When we’re encrypting a message,
▪ The plaintext (p) refers to the original or unencrypted message.
▪ The ciphertext (C) refers to the coded or encrypted message.
A cipher is therefore composed of two functions:
▪ Encryption or Enciphering (E) turns plaintext into ciphertext.
▪ Decryption or Deciphering (D) turns a ciphertext back into plaintext.
Written as functions:
▪ C = E(Ke,p)
▪ p = D(Kd, C)
where Ke and Kd are encryption key and decryption key, respectively
Taxonomy
4
Concerning encryption methodologies, there are two types of ciphers:
1. Symmetric ciphers (or Secret-key ciphers): Using single key for encryption and
decryption. It was the only type of encryption in use prior to the development of
public-key encryption in the 1970s (Figure 2).
2. Asymmetric ciphers (or Public-key ciphers): Use 2 related keys, a public key and
a private key, which are used to perform complementary operations, such as
encryption and decryption or signature generation and signature verification.
Classical ciphers are ciphers that predate computers, therefore work on letters rather
than on bits and almost are symmetric ciphers.
The two basic building blocks of all encryption techniques are substitution and
transposition (Figure 3).
B. LAB TASKS
1. Kickoff: Crack the code
Task 1: Let’s begin with a straightforward task that does not use any cipher algorithm.
Try to solve the following codes:
1. We need to find the code to open the lock in figure 4. The lock has 3 digit pin which
satisfies 5 conditions (hints) that are given . Can you crack this code? If it’s possible,
explain how.
2. Find the corresponding encoding for the numbers 1 to 9 according to the clues
provided in table 1.2.1
- Each symbol in the set (△◁ ▷◯ ♡ ♠ ♢ ♣ ●) unique encoding for one of the number
from 1 to 9.
- The rightmost column is the sum of the numbers in each row.
- The bottom row is the sum of the numbers in each column.
5
- Each ? can represent any one-digit or two-digit number and could be same or different
from each other.
2. Caesar cipher
Task 2: In this task, you must create an application in your chosen programming
language that performs encryption and decryption using the Caesar cipher. The
application should meet the following criteria:
- Enable user input for a key and either plaintext for encryption or ciphertext for
decryption.
Provide the ability to perform a brute-force attack by trying all possible keys to decrypt
a given ciphertext without knowing the key.
6
- To validate your program, test it with a message of at least 100 words and compare
the results with other cryptography online tool, such as dcode (https://www.dcode.fr),
CrypTool 2 online. Additionally, use your program to crack the following ciphertext:
Mfwzpn Rzwfpfrn bfx gtws ns Pdtyt ns 1949 fsi stb qnajx sjfw Ytpdt. Mj nx ymj
fzymtw tk rfsd stajqx fx bjqq fx xmtwy xytwnjx fsi sts-knhynts. Mnx btwpx nshqzij
Stwbjlnfs Btti, Ymj Bnsi-Zu Gnwi Hmwtsnhqj, Pfkpf ts ymj Xmtwj, Fkyjw Ifwp fsi Bmfy N
Yfqp Fgtzy Bmjs N Yfqp Fgtzy Wzssnsl. Mnx btwp mfx gjjs ywfsxqfyji nsyt rtwj ymfs
ktwyd qfslzfljx, fsi ymj rtxy wjhjsy tk mnx rfsd nsyjwsfyntsfq mtstzwx nx ymj Ojwzxfqjr
Uwnej, bmtxj uwjantzx wjhnunjsyx nshqzij O.R. Htjyejj, Rnqfs Pzsijwf, fsi A.X. Sfnufzq.
Do you find any special concerning the key used to encrypt this ciphertext?
Tips: Using the Caesar algorithm
Encryption : C = E(k, p) = (p + k) mod 26
Decryption : p = D(k,C) = (C- k) mod 26
where C = Ciphertext, p = plaintext, k is key
2
https://seedsecuritylabs.org/Labs_16.04/Crypto/Crypto_Encryption/files/ciphertext.txt
7
You can also use Cryptool or dCode to decrypt it manually by analyzing and replacing
letters. There are many online resources that you can use. Two valuable links as the
following:
▪ Cryptool Online N-gram analysis: This website can produce the statistics from
sequence), trigram frequencies (3-letter sequence), etc.
▪ http://norvig.com/mayzner.html: This web page provides frequencies for a
typical English plaintext, including unigram, bigram, and trigram frequency.
Advanced Task 3.1: Decrypt a cipher-text from Edgar Allan Poe’s - The Gold-Bug and
explain how to do:
53‡‡†305))6*;4826)4‡.)4‡);806*;48†8¶60))85;;]8*;:‡*8†83(88)5*†;46(;88*96
*?;8)*‡(;485);5*†2:*‡(;4956*2(5*—4)8¶8*;4069285);)6†8)4‡‡;1(‡9;48081;8:8‡
1;48†85;4)485†528806*81(‡9;48;(88;4(‡?34;48)4‡;161;:188;‡?;
It is known that:
• The original text is an English article.
• The cipher-text does not include punctuation and spaces.
• Each symbol corresponds to a letter in the English alphabet.
4. Playfair cipher
Task 4: Write an application with your own programming language to encrypt and
decrypt a message using Playfair cipher. Your application should satisfy the following
requirements:
- Allow you to input a key and a plain-text to encrypt or a cipher-text to decrypt using
the given key.
- Display the Playfair matrix (5x5) corresponding with the given key.
1. Test your program with an message of at least 100 words and compare the result
with other cryptography tools (like Cryptool 2) to verify.
2. Using the Playfair matrix below (Table 1.2) to encrypt the following message.
Message: I only regret that I have but one life to give for my country.
This message is by Nathan Hale, a soldier in the American Revolutionary War.
Table 2. Playfair Grid for Task 4 - Part 2.
8
5. Polyalphabetic cipher – Vigenère
Task 5: Write an application using your chosen programming language to encrypt and
decrypt a message using Vigenère cipher.
Test your application by a message with at least 100 words and a key of about 10-20
letters. Then verify the result with other cryptography tools (e.g., Cryptool 2, dCode,
etc.)
Task 7: The file crypto01.jpg can be downloaded from here, and it contains a flag.
Knowing that this image was encrypted with XOR cipher by a 6-letter key. Let’s find the
flag and describe how to do
Tips: You can refer to https://www.dcode.fr/xor-cipher to learn how XOR cipher work.
Advanced Task 7.1: Describe another classical cipher that was not mentioned in this
lab. Write an application and and give an demonstration to illustrate how it work.
9
Instances of plagiarism, delays, etc., will be handled based on the severity of the
violation.
D. REFERENCES
[1] William Stallings, Cryptography and network security: Principles and practice, 7 th
ed, Pearson Education, 2017. Chapter 3. Classical Encryption Techniques
[2] Wenliang Du (Syracuse University), SEED Cryptography Labs
https://seedsecuritylabs.org/Labs_16.04/Crypto/
[3] Bernhard Esslinger et al., The CrypTool Book: Learning and Experiencing
Cryptography with CrypTool and SageMath, 12th ed, 2018. Available:
https://www.cryptool.org/en/ctp-documentation
Training platforms and related materials:
• ASecuritySite - https://asecuritysite.com/
• Cryptopals - https://cryptopals.com/
THE END
Wishing you all the best in successfully completing the tasks!