u1-1
u1-1
!!!UNIT1st!!!
History of cryptography
Cryptography began in ancient civilizations, such as Egypt, where hieroglyphics were sometimes
encoded. The Greeks created early cryptographic tools like the scytale, while the Romans used
ciphers like Julius Caesar's shift cipher for secure communication. During the Middle Ages, more
sophisticated techniques emerged, including the polyalphabetic Vigenère cipher, which resisted
frequency analysis.
In the 20th century, cryptography became crucial in wars, most notably with the German Enigma
machine during World War II. Today, modern cryptography relies on complex mathematical
algorithms like RSA and AES, essential for securing digital communications and data privacy.
Basics of Cryptography
Cryptography is the practice of encoding and decoding information in a way that only authorized
parties can read it. It involves the use of algorithms and techniques to transform plaintext (readable
data) into ciphertext (encrypted data) and vice versa.
Key Concepts:
1. Plaintext: The original, readable data that needs to be encrypted.
2. Ciphertext: The encrypted data that is unintelligible to unauthorized parties.
3. Encryption: The process of transforming plaintext into ciphertext using an algorithm.
4. Decryption: The process of transforming ciphertext back into plaintext using the correct
algorithm and key.
5. Algorithm: The mathematical procedure or set of rules used for encryption and decryption.
Types of Cryptography
A. Symmetric-Key Cryptography:
Uses the same key for both encryption and decryption.
Examples: AES (Advanced Encryption Standard), DES (Data Encryption Standard), 3DES.
B. Asymmetric-Key Cryptography:
Uses a pair of keys: a public key and a private key.
Data encrypted with the public key can only be decrypted with the corresponding private key.
Examples: RSA (Rivest-Shamir-Adleman), Diffie-Hellman key exchange.
C. Hash Functions:
Creates a fixed-size output (hash value) from an input of any size.
Used for data integrity, password storage, and digital signatures.
Examples: SHA-1, SHA-256, MD5
Security implications of cryptography.
Cryptography is essential for securing data, but several security implications must be
considered. Poor key management, such as insecure storage, weak key lengths, can expose
sensitive information. Using outdated algorithms like DES or MD5, can make systems
vulnerable. Weak implementations of cryptographic systems, poor algorithm choices, and
human factors like phishing or weak passwords can also compromise security.
To mitigate these risks, it's crucial to use modern algorithms, implement strong key
management practices, regularly update systems, and educate users on security best
practices.
How it Works:
1. Encryption: Each letter in the plaintext is replaced by a letter some fixed number of positions
(the shift) down the alphabet.
• A becomes D
• B becomes E
• C becomes F
If the end of the alphabet is reached, the cipher wraps around (i.e., Z becomes C with a shift of 3)
2. Decryption: To decrypt the ciphertext, the process is reversed by shifting letters in the opposite
direction.
Example:
• Plaintext: "HELLO"
• Shift: 3
• Ciphertext: "KHOOR"
Mono-alphabetic cipher
A mono-alphabetic cipher is a type of substitution cipher where each letter in the plaintext is
replaced with a corresponding letter in the ciphertext using a fixed substitution throughout the
message. Unlike the Caesar cipher, which shifts letters by a fixed amount, a mono-alphabetic cipher
allows any arbitrary substitution, making it more versatile.
How it Works:
1. Encryption: Each letter of the plaintext is replaced by a unique letter from a shuffled or random
alphabet.
For example, if A is substituted with M, B with Q, C with X, and so on, this pattern is followed
consistently for the entire message.
2. Decryption: The receiver, knowing the substitution scheme, reverses the process to retrieve
the original message.
Example:
Plaintext: "HELLO"
Ciphertext: "XMZZP"
Hill cipher
The Hill cipher is a polygraphic substitution cipher that encrypts blocks of text rather than individual
letters. It is based on linear algebra, using matrix multiplication to encrypt and decrypt messages.
Named after its inventor, Lester S. Hill, the cipher was introduced in 1929 and is one of the first
ciphers to use matrix algebra in cryptography.
Vigenère cipher
The Vigenère cipher is a polyalphabetic substitution cipher that improves upon the Caesar cipher by
using multiple shifts based on a keyword. It was named after the French diplomat Blaise de Vigenère,
though it was actually first described by Giovan Battista Bellaso.
How it Works:
1. Key (Keyword): The Vigenère cipher uses a keyword to determine the shifts for each letter in
the plaintext. The keyword is repeated until it matches the length of the plaintext. Each letter of
the keyword represents a shift value based on its position in the alphabet (A=0, B=1, ..., Z=25).
2. Encryption: Each letter in the plaintext is shifted by a number of positions determined by the
corresponding letter in the keyword.
• If the letter is "A", no shift is applied (A=0).
• If the letter is "B", the shift is by 1, and so on.
For example:
Plaintext: "HELLO"
Keyword: "KEY"
Decryption:
To decrypt, the same keyword is used, but the shifts are applied in the opposite direction (i.e.,
subtract the shift instead of adding).
How it works:
1. Random Key: A random key is generated that is the same length as the plaintext.
2. XOR Operation: Each bit of the plaintext is XORed (exclusive or) with the corresponding bit of
the key to produce the ciphertext.
3. Key Disposal: The key is used only once and then discarded.
How it works:
1. Number of Rails: A number of "rails" is chosen.
2. Zig-zag Pattern: The plaintext is written in a zigzag pattern, going up and down between the
rails.
3. Read Out: The ciphertext is read out in a linear fashion, following the zigzag pattern.
Example:
• Number of Rails: 3
• Plaintext: "HELLO WORLD"
• Zigzag Pattern:
H W O
ELRL
L O D
Ciphertext: "HLWORELD"
4. Decryption: To decrypt the ciphertext, the same number of rails and zigzag pattern are used,
but the ciphertext is written in the zigzag pattern and then read out in a linear fashion.
Introduction to Number Theory
Number theory is a branch of mathematics that deals with the properties of integers. One of the
fundamental concepts in number theory is the notion of prime numbers.
1. Trial Division: This is the simplest method. To check if a number n is prime, divide it by all
integers from 2 to √n. If none of these divisions result in a remainder of 0, then n is prime.
2. Sieve of Eratosthenes: This is an efficient algorithm to find all prime numbers up to a given
limit. It works by iteratively marking multiples of prime numbers as composite.
3. Random Prime Generation: To generate a large prime number, a random number is
chosen and then tested for primality using probabilistic algorithms.
Primality Testing:
Determining whether a given number is prime is a fundamental problem in number theory. There are
various algorithms for primality testing:
ap-1=1(mod p)
This means that for any integer a that is not divisible by p, raising a to the power of p−1p-1p−1, and
then taking the remainder when divided by p, will always give 1.
Euler's Theorem
Euler's Theorem is a generalization of Fermat's Little Theorem. It states that if n is a positive integer
and a is an integer relatively prime to n (i.e., their greatest common divisor is 1), then:
a^(φ(n)) ≡ 1 (mod n)
Here, φ(n) is the Euler's totient function, which gives the number of positive integers less than or
equal to n that are relatively prime to n.
Symmetric Key Cryptography
Symmetric key cryptography, also known as secret-key cryptography, is a type of encryption
where the same key is used for both encryption and decryption. This key must be shared
securely between the sender and receiver.
Key Principles:
1. Shared Secret: The key is kept secret and shared only between the authorized parties.
2. Encryption and Decryption: The same key is used to encrypt the plaintext and decrypt
the ciphertext.
3. Algorithm: A mathematical function or algorithm is used to transform the plaintext into
ciphertext and vice versa.
4. Key Length: The length of the key determines the security of the encryption. Longer
keys are generally more secure.
Types of Algorithms:
Symmetric Key Algorithms:
1. DES (Data Encryption Standard): A 56-bit block cipher widely used in the past but now
considered insecure due to its relatively short key length.
2. 3DES (Triple DES): A variant of DES that uses three keys to enhance security.
3. AES (Advanced Encryption Standard): A modern block cipher that supports key lengths
of 128, 192, and 256 bits, making it more secure than DES.
Diffusion:
Diffusion refers to the process of spreading out the influence of a single plaintext symbol over many
ciphertext symbols. The goal is to ensure that changing a single bit of the plaintext affects many bits
of the ciphertext, making it more difficult for an attacker to identify patterns. Diffusion is achieved
through permutations or transformations that mix the data.
Confusion:
Confusion refers to making the relationship between the ciphertext and the encryption key as
complex and unintelligible as possible. The goal is to ensure that the key does not correlate directly
to the ciphertext, making it difficult for an attacker to reverse-engineer the key even if they have
access to the ciphertext.
Avalanche Effect
The Avalanche Effect is a critical property of cryptographic algorithms, particularly in block ciphers
and hash functions. It refers to the phenomenon where a small change in the input (such as flipping
a single bit) produces a significantly different output, such that even minor modifications lead to
unpredictable and widespread changes.
Feistel Cipher
The Feistel Cipher structure is a symmetric structure used in the design of block ciphers. Named
after Horst Feistel, it forms the basis for many well-known encryption algorithms, such as DES (Data
Encryption Standard). The Feistel structure splits the plaintext block into two halves and processes
them over multiple rounds using a series of mathematical functions and the encryption key.