Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to Cryptography: Mathematical Foundations and Classical Ciphers, Study notes of Cryptography and System Security

This document offers a foundational introduction to cryptography, exploring its core principles and applications. it covers essential concepts such as encryption, decryption, modular arithmetic, prime numbers, and classical ciphers like substitution and transposition ciphers. well-structured and provides clear explanations, making it suitable for introductory-level learning in mathematics or computer science.

Typology: Study notes

2024/2025

Available from 04/23/2025

peter-5u4
peter-5u4 ๐Ÿ‡ฌ๐Ÿ‡ง

5 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Cryptography in Mathematics:
Unlocking the Secrets ๐Ÿ”
Introduction
Hey there, future cryptographers! ๐Ÿ‘‹ This classwork is your mission briefing to the fascinating
world of cryptography, where mathematics meets mystery. We'll explore how numbers,
equations, and clever logic are used to create secret codes and secure information in our
digital world. Get ready to dive into a world of ciphers, keys, and mind-bending concepts!
What is Cryptography?
Imagine you have a secret message for your friend, but you don't want anyone else to read it.
Cryptography is the art and science of transforming your message into an unreadable format,
called ciphertext, and then back again. It's like having a secret language that only you and
your friend understand! The process of transforming the message into ciphertext is called
encryption, and the reverse process, turning ciphertext back into the original message, is
called decryption.
Why is Cryptography Important?
In today's digital age, cryptography is super important for:
โ—Secure communication: Protecting emails, texts, and online chats.
โ—Online banking and shopping: Keeping your transactions safe from hackers.
โ—Data security: Securing sensitive information like passwords, medical records, and
government secrets.
โ—Digital signatures: Verifying the authenticity of documents and software.
โ—Network Security: Ensuring that data transmitted over computer networks is
protected from eavesdropping and tampering.
โ—Software Security: Protecting software code from unauthorized modification and
reverse engineering.
Chapter 1: The Building Blocks - Mathematics
Before we dive into secret codes, let's review the math concepts that make it all possible.
1.1 Modular Arithmetic: The Clockwork World of Numbers ๐Ÿ”
Imagine a clock. When you add hours, you don't keep counting forever; you cycle back to 12
(or 24, depending on the clock). Modular arithmetic is similar, but with different "clocks." It's a
system of arithmetic for integers, where numbers "wrap around" upon reaching a certain
value, called the modulus.
Definition: Let a, b, and m be integers. We say that "a is congruent to b modulo m" if m
divides the difference (a - b). In other words, a and b have the same remainder when divided
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Introduction to Cryptography: Mathematical Foundations and Classical Ciphers and more Study notes Cryptography and System Security in PDF only on Docsity!

Cryptography in Mathematics:

Unlocking the Secrets ๐Ÿ”

Introduction

Hey there, future cryptographers! ๐Ÿ‘‹ This classwork is your mission briefing to the fascinating world of cryptography, where mathematics meets mystery. We'll explore how numbers, equations, and clever logic are used to create secret codes and secure information in our digital world. Get ready to dive into a world of ciphers, keys, and mind-bending concepts! What is Cryptography? Imagine you have a secret message for your friend, but you don't want anyone else to read it. Cryptography is the art and science of transforming your message into an unreadable format, called ciphertext , and then back again. It's like having a secret language that only you and your friend understand! The process of transforming the message into ciphertext is called encryption , and the reverse process, turning ciphertext back into the original message, is called decryption. Why is Cryptography Important? In today's digital age, cryptography is super important for: โ— Secure communication: Protecting emails, texts, and online chats. โ— Online banking and shopping: Keeping your transactions safe from hackers. โ— Data security: Securing sensitive information like passwords, medical records, and government secrets. โ— Digital signatures: Verifying the authenticity of documents and software. โ— Network Security: Ensuring that data transmitted over computer networks is protected from eavesdropping and tampering. โ— Software Security: Protecting software code from unauthorized modification and reverse engineering.

Chapter 1: The Building Blocks - Mathematics

Before we dive into secret codes, let's review the math concepts that make it all possible.

1.1 Modular Arithmetic: The Clockwork World of Numbers ๐Ÿ”

Imagine a clock. When you add hours, you don't keep counting forever; you cycle back to 12 (or 24, depending on the clock). Modular arithmetic is similar, but with different "clocks." It's a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value, called the modulus. Definition: Let a, b, and m be integers. We say that "a is congruent to b modulo m" if m divides the difference (a - b). In other words, a and b have the same remainder when divided

by m. We write this as: a โ‰กb (mod m) โ— m is called the modulus. โ— The remainder is always between 0 and m-1. Example 1: โ— 17 โ‰ก2 (mod 5) because 5 divides (17 - 2 = 15). When you divide 17 by 5, you get a remainder of 2. Similarly, when you divide 2 by 5, you also get a remainder of 2. โ— 25 โ‰ก1 (mod 8) because 8 divides (25 - 1 = 24). 25 divided by 8 is 3 with a remainder of 1. 1 divided by 8 is 0 with a remainder of 1. โ— 12 โ‰ก0 (mod 3) because 3 divides (12 - 0 = 12). 12 divided by 3 is 4 with a remainder of

  1. 0 divided by 3 is 0 with a remainder of 0. โ— -8 โ‰ก4 (mod 6) because 6 divides (-8 - 4 = -12). -8 divided by 6 is -2 with a remainder of
  2. 4 divided by 6 is 0 with a remainder of 4. Fun Fact: Modular arithmetic is used in many aspects of cryptography, including key exchange, encryption algorithms, and digital signatures. It simplifies complex calculations and provides the foundation for secure communication protocols. 1.1.1 Modular Arithmetic Operations You can perform addition, subtraction, and multiplication in modular arithmetic, just like regular arithmetic, but with a twist! After each operation, you take the remainder when divided by the modulus. This ensures that the result always falls within the range of 0 to m-1. Example 2: Let's work in modulo 7. โ— (5 + 4) mod 7 = 9 mod 7 = 2 (5 + 4 = 9. 9 divided by 7 is 1 with a remainder of 2) โ— (10 - 3) mod 7 = 7 mod 7 = 0 (10 - 3 = 7. 7 divided by 7 is 1 with a remainder of 0) โ— (3 * 6) mod 7 = 18 mod 7 = 4 (3 * 6 = 18. 18 divided by 7 is 2 with a remainder of 4) โ— (2 + 5 + 6) mod 7 = 13 mod 7 = 6 (2 + 5 + 6 = 13. 13 divided by 7 is 1 with a remainder of

โ— ((4 * 3) - 1) mod 7 = (12 - 1) mod 7 = 11 mod 7 = 4 โ— (5^2) mod 7 = 25 mod 7 = 4 1.1.2 Modular Inverses In regular arithmetic, the inverse of a number 'a' is a number 'b' such that a * b = 1. For example, the inverse of 2 is 1/2, because 2 * (1/2) = 1. In modular arithmetic, we look for an integer 'b' that, when multiplied by 'a', leaves a remainder of 1 when divided by the modulus 'm'. The modular inverse of 'a' modulo 'm' is an integer 'b' such that: a * b โ‰ก1 (mod m) The modular inverse exists if and only if a and m are relatively prime (i.e., their greatest common divisor is 1). This is a crucial condition. Example 3: Find the modular inverse of 3 modulo 7. We need to find a number 'b' such that 3 * b โ‰ก1 (mod 7). By trying out numbers (or using the

square root of N, if they haven't been crossed out, must be prime.

  1. The remaining uncrossed numbers are prime. Example 4: Find all prime numbers less than 30 using the Sieve of Eratosthenes. Solution:
  2. Write numbers from 2 to 30: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  3. Cross out multiples of 2: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  4. Cross out multiples of 3: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  5. Cross out multiples of 5: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 The prime numbers less than 30 are: 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29. 1.2.2 Primality Testing For very large numbers, the Sieve of Eratosthenes is inefficient. More sophisticated primality tests exist, such as the Miller-Rabin test, which is a probabilistic test used in cryptography. These tests quickly determine if a large number is likely to be prime, with a very small chance of error.

1.3 Greatest Common Divisor (GCD)

The greatest common divisor (GCD) of two integers 'a' and 'b' is the largest positive integer that divides both 'a' and 'b' without leaving a remainder. It's also known as the highest common factor (HCF). Example 5: Find the GCD of 24 and 36. The divisors of 24 are: 1, 2, 3, 4, 6, 8, 12, and 24. The divisors of 36 are: 1, 2, 3, 4, 6, 9, 12, 18, and 36. The common divisors are: 1, 2, 3, 4, 6, and 12. The greatest common divisor is 12. Example 6: Find the GCD of 15 and 25. The divisors of 15 are 1, 3, 5, and 15. The divisors of 25 are 1, 5, and 25. The greatest common divisor is 5. 1.3.1 Euclidean Algorithm The Euclidean algorithm is an efficient method for finding the GCD of two integers. It avoids the need to list all the divisors. Steps:

  1. Let a and b be the two integers.
  2. If b = 0, then GCD(a, b) = a.
  3. Otherwise, replace a with b and b with the remainder of a divided by b.
  1. Repeat steps 2 and 3 until b = 0. Example 7: Find the GCD of 56 and 98 using the Euclidean algorithm.
  2. a = 56, b = 98
  3. a = 98, b = 56 (98 = 1 * 56 + 42) The remainder when 98 is divided by 56 is 42.
  4. a = 56, b = 42 (56 = 1 * 42 + 14) The remainder when 56 is divided by 42 is 14.
  5. a = 42, b = 14 (42 = 3 * 14 + 0) The remainder when 42 is divided by 14 is 0.
  6. a = 14, b = 0 Therefore, GCD(56, 98) = 14. Example 8: Find the GCD of 1071 and 462 using the Euclidean Algorithm:
  7. a = 1071, b = 462
  8. a = 462, b = 147 (1071 = 2 * 462 + 147)
  9. a = 147, b = 21 (462 = 3 * 147 + 21)
  10. a = 21, b = 0 (147 = 7 * 21 + 0) Therefore, the GCD(1071, 462) = 21 1.3.2 Extended Euclidean Algorithm The Extended Euclidean Algorithm not only finds the GCD of two integers a and b, but also finds integers x and y such that: ax + by = GCD(a, b) This is very useful for finding modular inverses. Chapter 2: Classical Cryptography - Secret Codes of the Past ๐Ÿ”

2.1 Substitution Ciphers: Swapping Letters

Substitution ciphers replace letters in the plaintext with other letters, numbers, or symbols to create the ciphertext. They are among the earliest and simplest forms of encryption. 2.1.1 Caesar Cipher The Caesar cipher is one of the simplest and earliest known encryption techniques. It involves shifting each letter in the plaintext by a fixed number of positions down the alphabet. The shift value is the "key." Julius Caesar used this cipher to communicate with his generals. Example 7: Encrypt the message "HELLO" using a Caesar cipher with a key of 3. Plaintext: HELLO Shift each letter by 3 positions: โ— H becomes K โ— E becomes H โ— L becomes O โ— L becomes O โ— O becomes R Ciphertext: KHOOR Decryption: To decrypt, shift each letter in the ciphertext back by the same key value.

Encrypt "SECRET": โ— S becomes L โ— E becomes E โ— C becomes C โ— R becomes R โ— E becomes E โ— T becomes T Ciphertext: LECRET Example 9: Plaintext Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ Ciphertext Alphabet: ZEBRASCDFGHIJKLMNOPQTUVWXY Encrypt the message "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" T becomes H H becomes I E becomes D becomes Q becomes O U becomes P I becomes A C becomes B K becomes C becomes B becomes R R becomes O O becomes N W becomes W N becomes S becomes F becomes J O becomes U X becomes M becomes J becomes K U becomes U M becomes P S becomes S becomes O becomes U V becomes V E becomes E R becomes R

becomes T becomes H H becomes I E becomes D becomes L becomes N A becomes Z Z becomes A Y becomes Y becomes D becomes X O becomes O G becomes G Ciphertext: HID OPA BCROWS JUMOS UVIR HID SNAY XOG

2.2 Transposition Ciphers: Rearranging Letters

Transposition ciphers do not replace letters but rearrange them to create the ciphertext. The letters of the plaintext are scrambled according to some rule. 2.2.1 Rail Fence Cipher The rail fence cipher writes the plaintext in a zigzag pattern on imaginary "rails" and then reads the ciphertext row by row. Example 9: Encrypt the message "ATTACK AT DAWN" using a rail fence cipher with 2 rails. Plaintext: ATTACK AT DAWN Rails: A T A K A D A N T C T W Ciphertext: ATAKADANTCTW Example 10: Encrypt the message ""SEND HELP IMMEDIATELY"" using a rail fence cipher with 3 rails. Plaintext: SEND HELP IMMEDIATELY Rails: S N H L M E I T E D E P E A E L H I D Y Ciphertext: SNHLMEITED EPEAEL HIDY 2.2.2 Columnar Transposition Cipher In the columnar transposition cipher, the plaintext is written in rows of a fixed length, and then the columns are read out in a specific order. The order of the columns becomes the key for decryption.

integers less than n that are relatively prime to n.

  1. Choose an integer e such that 1 < e < ฯ†(n) and gcd(e, ฯ†(n)) = 1. 'e' is the public exponent. It must be relatively prime to ฯ†(n).
  2. Compute the modular inverse of e modulo ฯ†(n), called d. d is the private key. It satisfies the equation d * e โ‰ก1 (mod ฯ†(n)).
  3. The public key is (n, e), and the private key is (n, d). RSA Encryption: To encrypt a message M, where M is an integer such that 0 โ‰ค M < n, compute the ciphertext C: C โ‰กM^e (mod n) RSA Decryption: To decrypt the ciphertext C, compute the plaintext M: M โ‰กC^d (mod n) Example 10: RSA Encryption Let's use small numbers for illustration (in practice, much larger numbers are used).
  4. Choose primes: p = 5, q = 11
  5. Compute n = 5 * 11 = 55
  6. Compute ฯ†(n) = (5 - 1) * (11 - 1) = 4 * 10 = 40
  7. Choose e = 7 (gcd(7, 40) = 1)
  8. Compute d: We need to find d such that 7 * d โ‰ก1 (mod 40). Using the Extended Euclidean Algorithm (or by trial and error), we find that d = 23 works (7 * 23 = 161 โ‰ก 1 (mod 40)).
  9. Public key: (55, 7), Private key: (55, 23) Encrypt the message M = 2: C โ‰ก2^7(mod 55) C55) C = 18 De Cpt the ciphertext C = 18: M โ‰ก18^23 (mod 55) M โ‰ก2 (mod 55) M = 2 Chapter 4: Cryptographic Hash Functions - Fingerprints for Data เธฒเธขเธ™เธดเน‰ (^) เธง A hash function is a one-way function that takes an input (message) and produces a fixed- size output (hash or digest). Properties of a good cryptographic hash function:

โ— Deterministic: The same input always produces the same output. โ— Quick to compute: It should be easy to calculate the hash of any input. โ— Preimage resistant: It should be computationally infeasible to find the input given its hash. โ— Second preimage resistant: It should be computationally infeasible to find a different input with the same hash as a given input. โ— Collision resistant: It should be computationally infeasible to find two different inputs that produce the same hash. Applications of hash functions: โ— Password storage: Hashing passwords instead of storing them in plaintext. โ— Data integrity: Verifying that a file has not been tampered with. โ— Digital signatures: Creating a unique fingerprint of a document. โ— Cryptocurrency: Ensuring the integrity of blockchain transactions. Example 11: SHA- SHA-256 (Secure Hash Algorithm 256) is a widely used cryptographic hash function that produces a 256-bit hash value. import hashlib message = "Hello, world!" hash_object = hashlib.sha256(message.encode()) hash_hex = hash_object.hexdigest() print(hash_hex) # Output: b7f7e09c4d17b1f54017d2685511121905753599a9c68e16359f4c12ef2a4d Conclusion Congratulations, you've completed your cryptography 101 mission! ๐Ÿ‘‹ You've learned the basic math behind cryptography, explored classical ciphers, and discovered the magic of modern encryption techniques. Cryptography is a constantly evolving field, with new challenges and discoveries every day. So, keep exploring, keep questioning, and keep cracking those codes! Further Exploration โ— Books: โ—‹ "The Code Book" by Simon Singh โ—‹ "An Introduction to Mathematical Cryptography" by Jeffrey Hoffstein, Jill Pipher, and Joseph H. Silverman โ— Online Resources: โ—‹ Khan Academy: Cryptography โ—‹ Coursera: Cryptography courses โ—‹ YouTube: Cryptography tutorials