Cryptography Unit 3b - Comprehensive Study Notes

Encryption concepts

  • Cipher is a method for encrypting messages.
  • Encryption algorithms are standardized & published.
  • The key, which is an input to the algorithm, is secret.
    • Key is a string of numbers or characters.
  • If the same key is used for encryption & decryption, the algorithm is called symmetric.
  • If different keys are used for encryption & decryption, the algorithm is called asymmetric.
  • Encryption flow (as summarized from the transcript):
    • Plain Text --(Encryption Algorithm, Key A)--> Cipher Text
    • Decryption uses an algorithm with Key B to recover the Plain Text.
  • Diagrammatic idea (from the transcript): Encryption - Cipher - Plain Text - Encryption Algorithm - Key A - Key B - Cipher Text - Decryption - Plain Text - Algorithm.

Symmetric vs Asymmetric Encryption

  • Algorithms where the key for encryption and decryption are the same are called symmetric.
  • Types of symmetric ciphers:
    • 1. Stream Ciphers – Encrypt data one bit or one byte at a time.
    • Used if data is a constant stream of information.
    • Example: Caesar Cipher.
    • 2. Block Ciphers – Encrypt data one block at a time (typically 64 bits, or 128 bits).
    • Used for a single message.
    • Examples: Advanced Encryption Standard (AES), Data Encryption Standard (DES).
  • Note: The Caesar Cipher is listed as an example of a stream cipher in the transcript.

Key strength and key space

  • Strength of an algorithm is determined by the size of the key; the longer the key, the more difficult it is to crack.
  • Key length is expressed in bits.
  • Typical key sizes vary between 48 bits and 448 bits.
  • The set of possible keys for a cipher is called the key space.
  • Examples:
    • For a 40-bit key there are 2402^{40} possible keys.
    • For a 128-bit key there are 21282^{128} possible keys.
  • Each additional bit added to the key length doubles the security.
  • To crack the key, a hacker can use brute-force (try all possible keys until one works).
  • Transcript claim: a Super Computer can crack a 56-bit key in 24 hours.
  • Transcript claim (note): it will take 272 times longer to crack a 128-bit key (Longer than the age of the universe!!!). The "272" appears to be a typographical error in the transcript and is commonly interpreted as a much larger factor such as 2722^{72}.

The Caesar Cipher: history and basics

  • Caesar Cipher, also known as the "Caesar Box," is one of the earliest known cryptographic systems.
  • It was developed around 100 BC and used by Julius Caesar to send encrypted messages to his generals during military campaigns.
  • Mechanism: shifts all letters of the plaintext by a fixed number of letters; this fixed number is the private key.
  • It is a symmetric algorithm because encryption and decryption use the same key (the shift).
  • Alphabet rotation example (rotation by 3):
    • 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
    • D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
    • (Rotated by three letters as shown)

Caesar Cipher: Encryption and decryption examples

  • Encryption example (Shift by 3):
    • Plain Text: Attack at Dawn
    • Cipher Text: Dwwdfn Dw Gdyq
    • Key: 3
  • Decryption example (Shift by 3):
    • Cipher Text: Dwwdfn Dw Gdyq
    • Plain Text: Attack at Dawn
    • Key: 3
  • These examples illustrate the symmetric nature and the fixed shift mechanism.

Assignment 1: Practice problems

  • Q1: Encrypt the following message by right-shifting 5 letters: "ATTACK AT DAWN".
    • (Student task: submit the encrypted message to Blackboard in Unit 3 folder.)
  • Q2: Encrypt the message, "THIS IS A MESSAGE," with En(x), n = 3.
    • (Submit to Blackboard.)
  • Q3: Decrypt the message, "WKLV LV D PHVVDJH," with En(x), n = 3.
    • (Submit to Blackboard.)

Caesar cipher mathematics and modular arithmetic

  • Encryption function: if we encode a letter x as an index 0-25, then the encrypted index is:
    • E(x)=(x+n)mod26E(x) = (x + n) \bmod 26
    • where n is the key (the shift), and mod 26 keeps the result within the alphabet.
  • Decryption function: to decrypt, shift back by n:
    • D(x)=(xn)mod26D(x) = (x - n) \bmod 26
  • Notes:
    • The right shift corresponds to adding n; the left shift corresponds to subtracting n.
    • We have to consider all characters in the plaintext/ciphertext.
    • The size of the English alphabet is 26, hence the mod 26 operation.
    • The modulo ensures the result stays within the valid index range [0, 25].

Why modulo 26?

  • This guarantees valid indexes and valid letters after encryption.
  • It enforces wrap-around when a shift moves past 'Z' back to the start of the alphabet.

Size of the search space in Caesar cryptosystem

  • The size of the key space is not infinite; it is proportional to the number of possible shifts (i.e., the number of letters in the alphabet).
  • Transcript answer: It is proportional to the number of letters in the alphabet.

Multiple encryptions in Caesar cipher

  • Statement: If we make multiple Caesar encryptions after each other, we can make the cryptosystem more secure.
  • Transcript answer: False.
  • Explanation: Multiple sequential Caesar encryptions with fixed shifts effectively combine into a single net shift (the sum of shifts modulo 26). Hence security does not necessarily increase.

Lab: Caesar Cipher implementation with Python (summary)

  • Code snippet defines a string of letters:
    • letters = ' ABCDEFGHIGKLMNOPQRSTUVWXYZ'
    • Note: This string contains a leading space and a likely typo (missing J), which affects indexing and behavior.
  • KEY = 3
  • caesarencrypt(plaintext):
    • Converts plain_text to uppercase.
    • For each character l in plain_text, finds its index in letters via letters.find(l).
    • Computes new index: index = (index + KEY) % len(letters).
    • Builds cipher_text by appending letters[index].
  • caesardecrypt(ciphertext):
    • For each character l in cipher_text, finds its index in letters.
    • Computes index: (index - KEY) % len(letters).
    • Builds plain_text by appending letters[index].
  • Main block example:
    • message = 'Welcome to my Cryptography class'
    • encryptedmessage = caesarencrypt(message)
    • print(encrypted_message)
    • print(caesardecrypt(encryptedmessage))
  • Teaching point: The code uses a fixed alphabet and uppercases input; only characters found in the alphabet are transformed.

Lab: Extending to handle any characters (ASCII)

  • The next page explains modifying the code to allow any characters in the plain text and cipher text.
  • Hint: Use ASCII index to represent a character with ord().
  • Idea: Instead of a fixed alphabet, map characters to their ASCII codes, apply the shift modulo a chosen range, and map back with chr().
  • Goal: Create a version that can encrypt/decrypt any text, not just letters from A-Z.
  • Submission: Submit your solution (Python code) to Lab 2 in Unit 3 on Blackboard.

Practical and broader implications

  • Practical relevance: Understanding core encryption concepts, key management, and simple ciphers builds intuition for more complex modern cryptography.
  • Ethical considerations: Use cryptographic techniques responsibly to protect privacy and data; avoid illegal or unethical use (e.g., unauthorized decryption).
  • Real-world relevance: Recognition that key length and algorithm choice impact security; awareness of brute-force limits and the importance of using sufficiently large keys in practice.