85 min total

Information Security

Classical cryptography

Classical cryptography

Classical ciphers convert plaintext into ciphertext, but lack strength and complexity for modern-day data security, hence more modern ciphers: DES, AES, and 3DES are utilized.

We have two basic components of classical ciphers:

  • Substitution: letters are replaced by other letters e.g. Mono/Poly alphabetic ciphers
  • Transposition: letters are arranged in different order

Monoalphabetic Ciphers

each character in the plaintext is replaced by exactly one fixed character in the ciphertext. The same letter in the plaintext always maps to the same letter in the ciphertext.

e.g. Caeser cipher

Polyalphabetic Ciphers

the same letter in the plaintext can be encrypted to different letters in the ciphertext, depending on its position in the message.

e.g. Playfair cipher, Vigenere cipher, hill cipher, one time pad cipher

1. Shift cipher / Caesar cipher

each letter in the plaintext is shifted by a certain number of positions in the alphabet

Caesar cipher alphabet rotated by a fixed number of positions

2. ROT13 (rotate by 13)

Each letter of the alphabet is shifted by 13 positions.

ROT13 maps HELLO to URYYB

3. Substitution Cipher

Instead of shifting letters by a fixed amount (as in the Caesar cipher), a permutation cipher replaces each letter of the plaintext with another letter based on a random arrangement of the alphabet. You choose which letters to exchange from original alphabets.

  • Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • Permuted alphabet: QWERTYUIOPLKJHGFDSAZXCVBNM

Monoalphabetic substitution example

Plain alphabetABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher alphabetMRBGSLOAEFYWDKUQHPCJTZVXIN

4. Vigenere Cipher

uses a keyword to determine the shift applied to each letter of the plaintext.

Vigenère tableau

Key / plaintextABCDEFGHIJKLMNOPQRSTUVWXYZ
AABCDEFGHIJKLMNOPQRSTUVWXYZ
BBCDEFGHIJKLMNOPQRSTUVWXYZA
CCDEFGHIJKLMNOPQRSTUVWXYZAB
DDEFGHIJKLMNOPQRSTUVWXYZABC
EEFGHIJKLMNOPQRSTUVWXYZABCD
FFGHIJKLMNOPQRSTUVWXYZABCDE
GGHIJKLMNOPQRSTUVWXYZABCDEF
HHIJKLMNOPQRSTUVWXYZABCDEFG
IIJKLMNOPQRSTUVWXYZABCDEFGH
JJKLMNOPQRSTUVWXYZABCDEFGHI
KKLMNOPQRSTUVWXYZABCDEFGHIJ
LLMNOPQRSTUVWXYZABCDEFGHIJK
MMNOPQRSTUVWXYZABCDEFGHIJKL
NNOPQRSTUVWXYZABCDEFGHIJKLM
OOPQRSTUVWXYZABCDEFGHIJKLMN
PPQRSTUVWXYZABCDEFGHIJKLMNO
QQRSTUVWXYZABCDEFGHIJKLMNOP
RRSTUVWXYZABCDEFGHIJKLMNOPQ
SSTUVWXYZABCDEFGHIJKLMNOPQR
TTUVWXYZABCDEFGHIJKLMNOPQRS
UUVWXYZABCDEFGHIJKLMNOPQRST
VVWXYZABCDEFGHIJKLMNOPQRSTU
WWXYZABCDEFGHIJKLMNOPQRSTUV
XXYZABCDEFGHIJKLMNOPQRSTUVW
YYZABCDEFGHIJKLMNOPQRSTUVWX
ZZABCDEFGHIJKLMNOPQRSTUVWXY

FLOWER with the repeated key SUN

PlaintextFLOWER
KeySUNSUN
CiphertextXFBQYE

5. Transposition Cipher

Letters or symbols in the plaintext are rearranged according to a specific system or pattern, rather than being replaced by other characters (as in a substitution cipher)

Columnar transposition example

Key4312567
Row 1attackp
Row 2ostpone
Row 3duntilt
Row 4woamxyz

Read the columns in ascending key order: column 3, column 4, column 2, column 1, column 5, column 6, then column 7. The final X, Y, and Z are padding.

text
TTNAAPTMTSUOAODWCOIXKNLYPETZ

6. Rotor Machines (1870 - 1943)

Combines both substitution and transposition ciphers, Used by govt and army.

The machine encrypts messages by passing electrical signals through a series of rotating disks (rotors), each of which performs a letter substitution. After each letter is encrypted, the rotors advance, dynamically changing the substitution pattern for the next letter.

Enigma Machine: A well-known WWII rotor machine used by Nazi Germany, eventually decrypted by the Allies.

Breaking Monoalphabetic Ciphers

Monoalphabetic ciphers preserve frequency of alphabetic characters

frequency analysis is a powerful tool for breaking these ciphers. This technique relies on the fact that certain letters, pairs of letters (bigrams), or even groups of three letters (trigrams) appear with predictable frequency in natural languages.

common letters such as 'e', 't', 'a', 'o', 'i', and 'n' tend to appear more often.

English letter and digram frequencies

LetterProbabilityLetterProbability
a0.082n0.067
b0.015o0.075
c0.028p0.019
d0.043q0.001
e0.127r0.060
f0.022s0.063
g0.020t0.091
h0.061u0.028
i0.070v0.010
j0.002w0.023
k0.008x0.001
l0.040y0.020
m0.024z0.001
GroupLettersApproximate probability
1E0.12
2T, A, O, I, N, S, H, R0.06–0.09 each
3D, L0.04 each
4C, U, M, W, F, G, Y, P, B0.015–0.028 each
5V, K, J, X, Q, Z0.01 or less each
DigramFrequency
th0.0315
he0.0251
an0.0172
in0.0169
er0.0154
re0.0148

Breaking Vignere Ciphers

t's a combination of simple substitution ciphers where the rotations are determined by a repeating keyword.

Frequency analysis becomes possible if the length of the repeating key (period) is guessed.

Kasiski test:

Repeated sequences of letters in the ciphertext could indicate repeated use of the same key letters, revealing the key length.

Repeated-key example

KeyABCDABCDABCDABCDABCDABCDABCD
PlaintextCRYPTOISSHORTFORCRYPTOGRAPHY
CiphertextCSASTPKVSIQUTGQUCSASTPIUAQJB

The plaintext is “CRYPTO IS SHORT FOR CRYPTOGRAPHY.” Grouping into four-letter chunks exposes the period of the repeated key ABCD.

Repetitions of CSASTP is at a distance16

Assuming that the repeated segments represent the same plaintext segments,

this implies that the key is 16, 8, 4, 2, or 1 characters long

One Time Pad (OTP) with XOR

The plaintext is combined with a random key (or pad) that is the same length as the plaintext.

When used correctly, the OTP is mathematically impossible to decrypt the ciphertext without the key.

The key must be as long as the plaintext, making it impractical for large messages.

Distributing and managing the key securely can be challenging, especially for large amounts of data.

Trying all possible keys doesn't help you at all, because all possible plaintexts are equally likely decryptions of the ciphertext.

Plaintext: "WORLD"

Key: "ABCDE" (randomly generated)

Ciphertext Calculation:

W ⨁ A = V

O ⨁ B = O

R ⨁ C = O

L ⨁ D = H

D ⨁ E = A

Ciphertext: "VOOHA"

Bytewise XOR encryption example

Plaintext / ASCIIKey / ASCIIXOR result (decimal)Result (hex)
W / 87A / 6587 XOR 65 = 2216
O / 79B / 6679 XOR 66 = 130D
R / 82C / 6782 XOR 67 = 1711
L / 76D / 6876 XOR 68 = 808
D / 68E / 6968 XOR 69 = 101

These ciphertext bytes are control characters, not printable letters: SYN, CR, DC1, BS, and SOH. The original screenshot mixed ASCII and letter-based notation; the arithmetic here uses bytewise XOR consistently.

Bytewise XOR decryption example

Ciphertext byte (decimal)Key / ASCIIRecovered ASCIIPlaintext
22A / 6522 XOR 65 = 87W
13B / 6613 XOR 66 = 79O
17C / 6717 XOR 67 = 82R
8D / 688 XOR 68 = 76L
1E / 691 XOR 69 = 68D

Stream cipher

encrypts plaintext one bit or byte at a time

Each bit or byte of plaintext is combined with a corresponding bit or byte from the key stream generated by the pseudorandom number generator (PRG)

This key stream is then XOR'd with the plaintext to produce ciphertext.

If the PRG is predictable, the security of the cipher is compromised.

Encryption:

Decryption:

A pseudorandom generator expands a key into a keystream for XOR encryption

Pseudorandom generators

In one-time pad, key must be as long as plaintext, which is impractical in real life

Stream Ciphers generate a long sequence of pseudorandom bits from s shorter, secret seed/key

PRG uses a deterministic algorithm, given same set of initial seed/key it wil always product same sequence of bits

PRG must be unpredictable

PRG is predictable if given (n-1) bits it can predict n bit

LCG is a weak PRG:

X = current value

a, c, m are constants

is the initial seed

The sequence can have a very short period depending on the parameters chosen

If an attacker knows a few outputs, they can easily determine the future outputs.

Attacks on Stream Cipher

By analyzing the resulting ciphertexts, an attacker might detect correlations or patterns that could lead to guessing parts of the plaintexts, making the encryption insecure.

  • No integrity

The OTP does not provide any built-in mechanism to ensure the integrity of the ciphertext. This means that modifications to the ciphertext can go undetected. The modification will result in a predictable change in the plaintext.

Real-world Stream cipher examples

  • RC4 cipher
    RC4 was commonly used in protocols like HTTPS and WEP.

has known weaknesses, such as biases in the output (e.g., a specific probability for the second byte being zero). Attackers can exploit certain patterns in the key or output to deduce information.

  • CSS (Content Scramble System)

CSS is a cryptographic system used for DVD encryption, employing linear feedback shift registers (LFSRs) for encryption.

CSS has been broken, particularly through a cryptanalysis technique that involves brute-forcing the initial settings of the LFSRs, allowing attackers to recover the encryption key and generate the output.

  • Modern Stream Cipher: eStream
    Focuses on developing secure stream ciphers. It uses a pseudorandom generator (PRG) that incorporates a nonce (a non-repeating value) for each key to ensure security. The pair (k,r) is never used more than once.
  • Modern Stream Cipher: Salsa20

It processes data in blocks and utilizes a fast invertible function.

Salsa20's architecture involves generating output based on the key and nonce, and it is structured to be efficient on x86 architectures. there are no known attacks against Salsa20 that are more effective than exhaustive search methods.