Lab01 - Classical Cryptography
Lab01 - Classical Cryptography
Classical Cryptography
PHỤC VỤ MỤC ĐÍCH GIÁO DỤC
FOR EDUCATIONAL PURPOSE ONLY
A. OVERVIEW
A. OVERVIEW
1. Introduction and learning objective.
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 prearranged 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,
and a few niche industry applications for centuries.
But cryptography nowadays is much more of a science. We would say that modern
cryptography involves studying mathematical techniques for securing information,
systems, and distributed computations against adversarial attacks. 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.
1
https://www.oxfordlearnersdictionaries.com
Lab: Classical Crytography
2
The learning objective of this lab is for students to get familiar with the concepts in
secret-key encryption, particularly in classical cryptography and block ciphers. 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:
1. Monoalphabetic substitution ciphers - Frequency analysis
2. Polyalphabetic ciphers
3. Permutation ciphers
3
Figure 1: Basic encryption and decryption
Techniques used for deciphering a message without any knowledge of the enciphering
details fall into the area of cryptanalysis (breaking the code). The areas of
cryptography and cryptanalysis together are called cryptology.
Taxonomy
Concerning encryption methodologies, there are two types of ciphers:
1. Symmetric ciphers (or Secret-key ciphers): Using a single key for encryption and
decryption. It was the only type of encryption in use before the development of
public-key encryption in the 1970s (Figure 2).
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)
2. Asymmetric ciphers (or Public-key ciphers): Use two related keys, a public key
and a private key, to perform complementary operations, such as encryption and
decryption or signature generation and signature verification.
4
B. LAB TASKS
1. Kickoff: Crack the code
Task 1.1
Let’s begin with a straightforward task that does not use any cipher algorithm. Try
to solve the following codes:
a. We need to find the code to open the lock in Figure 4. The lock has a three-digit
pin that satisfies five conditions (hints). Can you crack this code? If it’s
possible, explain how.
b. Find the corresponding encoding for the numbers 1 to 9 according to the clues
provided in Table 1:
▪ Each symbol in the set () unique encoding for one of the
numbers from 1 to 9.
▪ The rightmost column is the sum of the numbers in each row.
▪ The bottom row is the sum of the number in each column.
▪ Each symbol “?” can represent either a one-digit number or a two-digit
number. Thay can be different from each other.
5
?
? ?
?
Table 1: Find the corresponding encoding for each number
2. Caesar cipher
Task 2.1
In this task, you must write an application using your chosen programming language
to encrypt and decrypt a message using Caesar cipher. Your application should
satisfy the following requirements:
Test your program with a message of at least 100 words and compare the result with
other cryptography tools (like Cryptool 2) to verify. Then use your program to crack
the following ciphertext:
Max NBM bl t extwbgz bglmbmnmbhg ngwxk OGN-AVF, lixvbtebsbgz bg max
ybxew hy bgyhkftmbhg mxvaghehzr. Xlmtueblaxw pbma t fbllbhg mh yhlmxk
bgghotmbhg tgw xqvxeexgvx bg BM xwnvtmbhg tgw kxlxtkva, NBM hyyxkl t
pbwx ktgzx hy ngwxkzktwntmx tgw ihlmzktwntmx ikhzktfl tbfxw tm ikhwnvbgz
abzaer ldbeexw ikhyxllbhgtel. Max ngboxklbmr bl kxvhzgbsxw yhk bml
vnmmbgz-xwzx kxlxtkva bg tkxtl ebdx vruxklxvnkbmr, tkmbybvbte
bgmxeebzxgvx, tgw lhymptkx xgzbgxxkbgz. Pbma lmtmx-hy-max-tkm
ytvbebmbxl tgw t lmkhgz xfiatlbl hg vheetuhktmbhg pbma bgwnlmkr, NBM
xjnbil lmnwxgml pbma uhma maxhkxmbvte dghpexwzx tgw iktvmbvte ldbeel mh
makbox bg max ktibwer xoheobgz mxva bgwnlmkr.
Do you find any special concerning the key used to encrypt this ciphertext?
6
3. Mono-alphabetic substitution cipher and frequency analysis
(This task is based on a lab in SEED Labs materials by Wenliang Du, Syracuse University.)
It is well-known that monoalphabetic substitution cipher (also known as the
monoalphabetic cipher) is not secure because it can be subjected to frequency analysis.
You are given a ciphertext encrypted using a monoalphabetic cipher in this lab. Each
letter in the original text is replaced by another letter, where the replacement does not
vary (i.e., a letter is always replaced by the same letter during the encryption.
Task 3.1
See the attached file “3_1_cipher_text” in the Courses for cypher text.
Your job is to find out the original text using the frequency analysis technique. It is
known that the original text is an English article. Describe how to find the plaintext
in detail (step-by-step).
Please note that you are not allowed to use the automatic mode of any tools (like
CrypTool, dCode, quipqiup,…) to decrypt.
Tips: Using the frequency analysis, you can easily find the plaintext for some of the
characters. For those characters, you may want to change them back to their plaintext,
as you may be able to get more clues. It’s better to use capital letters for plaintext, so for
the same letter, we know which is plaintext and which is ciphertext.
If you use Linux or macOS, you can use the tr command. For example, in the following,
we replace letters a, e and t in in.txt with letters X, G, E, respectively; the results are saved
in out.txt.
$ tr ‘aet’ ‘XGE’ < in.txt > out.txt
You can also use public tools to support 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.
▪ Mayzner: This web page provides frequencies for a typical English plaintext,
including unigram, bigram, and trigram frequency.
7
See the attached file “3_2_cipher_text” in the Courses for cypher text.
It is known that:
4. Playfair cipher
Task 4.1
Encrypt and decrypt using Playfair cipher. You are able to use public tools or your
own tool that was developed in the advanced task 4.2.
The key used was Harry Potter. Let’s decrypt the message.
• Allow you to input a key and the plain text to encrypt or a cypher text to
decrypt.
• Display the Playfair matrix (5x5) corresponding with the given key
Test your program with a message of at least 100 words and compare the result with
other cryptography tools (like Cryptool 2) to verify.
8
5. Polyalphabetic ciphers – Vigenère
Task 5.1
In this task, your job is to write an application using your chosen programming
language to encrypt and decrypt a message using Vigenère cipher.
Test your program with a message of at least 100 words and compare the result with
other cryptography tools (like Cryptool 2) to verify.
Tips: Using Vigenère algorithm:
Encrypt ith letter in plain-text:
Ci = (pi +ki mod m) mod 26
Decrypt ith letter in cipher-text:
pi = (Ci ki mod m) mod 26
where C = Ciphertext, p = plaintext, k = key, m is key length
6. Advanced Task
9
C. REQUIREMENTS
You are expected to complete all tasks in section B (Lab tasks). Advanced tasks are
optional, and you could get bonus points for completing those tasks. We prefer you
work in a team of two or three for the highest efficiency.
Your submission must meet the following requirements:
▪ You need to submit a detailed lab report in .pdf format using the report
template provided on the UIT Courses website.
▪ Your report presents what you have done, so carefully prepare the
report.
▪ Either a Vietnamese or English report is accepted; that’s up to you. The report
written in the mixing of multiple languages is not allowed (except for the
untranslatable keywords).
▪ When it comes to programming tasks (require you to write an application or
script), please attach all source code and executable files (if any) in your
submission. Please also list the important code snippets followed by
explanations and screenshots when running your application in your
report. Simply attaching code without any explanation will not receive
points.
▪ Your submissions must be your own. You are free to discuss with other
classmates to find the solution. However, copying reports is prohibited, even
if only a part of your report. Both reports of the owner and the copier will be
rejected. Please remember to cite any source of the material (website,
book,…) that influences your solution.
Notice: Combine your lab report and all related files into a single ZIP file (.zip), and
name it as follows:
StudentID1_StudentID2_ReportLabX.zip
D. REFERENCES
[1] William Stallings, Cryptography and network security: Principles and practice, 7th ed,
Pearson Education, 2017. Chapter 3, chapter 4, chapter 6, chapter 7
10
Training platforms and related materials
▪ ASecuritySite-https://asecuritysite.com
▪ Cryptopals-https://cryptopals.com
Attention: Don’t share any materials (slides, readings, assignments, labs, etc..) out of our
class without my permission!