Basic Concepts of Cryptography
Cryptography is the science of protecting information by converting readable data
(plaintext) into an unreadable form (ciphertext).
Main Components
Encryption – Converting plaintext into ciphertext.
Decryption – Converting ciphertext back into plaintext.
Features of Cryptography
Cryptography provides several important security services that protect information from
unauthorized access and misuse.
1. Confidentiality
Confidentiality ensures that information is accessible only to authorized users. Unauthorized
persons cannot read or understand the data.
Example: Encrypting a bank transaction so that only the intended recipient can view it.
2. Integrity
Integrity ensures that data is not altered, modified, or deleted during storage or transmission
without detection.
Example: A hash value is used to verify that a file has not been changed.
3. Non-Repudiation
Non-repudiation prevents the sender from denying that they sent a message or performed a
transaction.
Example: Digital signatures provide proof of the sender's identity and action.
4. Authentication
Authentication verifies the identity of users, devices, or systems involved in communication.
Example: Digital certificates are used to authenticate websites.
5. Interoperability
Cryptography enables secure communication between different systems, applications, and
platforms using standard protocols.
Example: SSL/TLS allows secure communication between different web browsers and
servers.
6. Adaptability
Cryptographic techniques continuously evolve to address new security threats and
technological advancements.
Types of Cryptography
There are three types of cryptography,
1. Symmetric Key Cryptography
2. Asymmetric Key Cryptography
Symmetric Cryptography
Symmetric cryptography (also known as secret-key cryptography) is a type of encryption
where the same key is used for both encryption and decryption. It is faster and more efficient
for encrypting large amounts of data but requires a secure way to share the secret key
between parties.
Components of Symmetric Cryptography:
Plaintext – The original data that needs to be encrypted.
Encryption Algorithm – The algorithm that transforms plaintext into ciphertext
using the secret key.
Secret Key – A shared key that both sender and receiver use for encryption and
decryption.
Ciphertext – The encrypted output of the plaintext.
Decryption Algorithm – The algorithm that converts ciphertext back to plaintext
using the same secret key.
How It Works:
1. A single secret key is generated and shared between the sender and receiver.
2. The sender encrypts the plaintext using the secret key and a chosen encryption
algorithm.
3. The encrypted message (ciphertext) is sent to the receiver.
4. The receiver uses the same secret key and decryption algorithm to convert the
ciphertext back into plaintext.
Examples of Symmetric Encryption Algorithms:
Advanced Encryption Standard (AES)
Data Encryption Standard (DES)
Triple DES (3DES)
Advantages of Symmetric Cryptography:
Fast Processing – Since it uses a single key, encryption and decryption are quick.
Efficient for Large Data – Ideal for encrypting large files, databases, and bulk data
transmission.
Lower Computational Cost – Requires fewer computing resources compared to
asymmetric cryptography.
Disadvantages of Symmetric Cryptography:
Key Distribution Challenge – The secret key must be securely shared between
sender and receiver, which can be risky.
Scalability Issue – In large networks, managing multiple secret keys for different
users becomes difficult.
No Non-Repudiation – Since both parties have the same key, it's hard to prove who
encrypted or decrypted a message.
Real-World Use Cases:
File and Disk Encryption – AES is widely used in software like BitLocker and
VeraCrypt.
Wireless Network Security – Wi-Fi encryption protocols (WPA2, WPA3) use
symmetric encryption.
Banking Transactions – ATMs and card payment systems use symmetric encryption
to protect user data.
Asymmetric Cryptography
Asymmetric cryptography (also known as public-key cryptography) uses two keys: a public
key for encryption and a private key for decryption. This eliminates the need for secure key
exchange, making it ideal for secure communications like digital signatures and SSL/TLS
encryption.
Components of Asymmetric Cryptography:
Plaintext – The original data that needs to be encrypted.
Encryption Algorithm – The algorithm that encrypts data using the recipient's public
key.
Public Key – A publicly shared key used for encryption.
Ciphertext – The encrypted message that can only be decrypted with the
corresponding private key.
Private Key – A secret key held by the recipient for decryption.
Decryption Algorithm – The algorithm that decrypts the ciphertext using the private
key.
Examples of Asymmetric Encryption Algorithms:
RSA (Rivest-Shamir-Adleman)
ECC (Elliptic Curve Cryptography)
Diffie-Hellman (DH)
Digital Signature Algorithm (DSA)
How It Works:
A key pair is generated:
1. Public Key – Shared with anyone and used for encryption.
2. Private Key – Kept secret and used for decryption.
3. The sender encrypts the plaintext using the recipient’s public key.
4. The encrypted message (ciphertext) is sent to the receiver.
5. The receiver decrypts the message using their private key.
Advantages of Asymmetric Cryptography:
No Need for Secure Key Exchange – Since only the public key is shared, there's no
risk of interception.
Provides Authentication – Used in digital signatures to verify sender identity.
Ensures Non-Repudiation – The sender cannot deny sending the message if it was
signed with their private key.
Disadvantages of Asymmetric Cryptography:
Slower Processing – More computationally expensive than symmetric encryption.
Not Ideal for Large Data Encryption – Mostly used for secure key exchange and
authentication rather than bulk encryption.
Real-World Use Cases:
Secure Web Communication (SSL/TLS) – HTTPS websites use asymmetric
encryption for secure browsing.
Digital Signatures – Used in electronic contracts, blockchain, and certificates.
Secure Email Communication – PGP and S/MIME use asymmetric cryptography to
encrypt and sign emails.
Data Encryption Standard (DES)
Data Encryption Standard (DES) is a symmetric block cipher.
DES is based on the LUCIFER Feistel block cipher, which was invented in 1971 by
IBM cryptography researcher Horst Feistel
It is a block cipher that encrypts data in 64 bit blocks.
It takes\ a 64-bit plaintext input and generates a corresponding 64-bit ciphertext
output.
The main key length is 64-bit which is transformed into 56-bits by skipping every 8th
bit in the key.
It encrypts the text in 16 rounds where each round uses 48-bit subkey.
The same algorithm and key are used for both encryption and decryption with minor
changes.
Working of Data Encryption Standard
The following steps define the algorithm process −
Step 1 − The 64-bit plaintext block is initially provided to an initial permutation (IP) function
to start the process.
Step 2 − After that, the plaintext undergoes to the initial permutation (IP).
Step 3 − The first permutation (IP) then generates Left Plain Text (LPT) and Right Plain
Text (RPT), which are the two sides of the permuted block.
Step 4 − The encryption procedure consists of sixteen cycles for each LPT and RPT.
Step 5 − Lastly, the LPT and RPT become one, and the newly combined block is subjected to
a Final Permutation (FP).
Step 6 − This procedure yields the intended 64-bit ciphertext.
1. Initial Permutation
The 64-bit plaintext block is input into an Initial Permutation (IP) function that
rearranges the order of bits. The order of bits is changed using predefined
table.
The IP table is a 8×8 matrix (64 entries) where each entry specifies the new
position of a bit from the original plaintext.
Each of this round uses a different 48-bit subkey from the previous round
subkey. These subkeys are generated from 64-bit key.
2. Key Transformation
The 64-bit initial key is converted into 56-bit effective key. This 56-bit key
further generates 48-bit subkeys for each of the 16 Feistel rounds.
3. Round Operation
Every round receives 64-bits permuted plaintext from the Initial
Permutation function and 48-bit transformed subkey (Ki).
The 64-bit plaintext is divided into:
Left Plaintext (LPT) – 32 bits
Right Plaintext (RPT) – 32 bits
The Right Plaintext (RPT) is given to the Mangler Function (F).
The 32-bit RPT is expanded to 48 bits using the Expansion Box (E-
Box).
The expanded 48-bit block is XORed with the 48-bit round key (Ki).
The result is divided into 8 blocks of 6 bits each.
Each 6-bit block is processed through an S-Box (S1 to S8).
The S-Boxes convert the 48-bit input into a 32-bit output.
The 32-bit output is rearranged using the P-Box (Permutation Box).
The final 32-bit output is sent to the next stage of the DES round.
For example, the output of XOR operation is converted into 6 bit chunks as follows:
101010 010001 011110 111010 100001 100110 010100 100111
32-bit Swap
After these 16 rounds we get two blocks (Left and Right) of 32-bit each. The two 32-bit
halves are again swapped back, resulting in a 64-bit block. This step is called 32-bit Swap in
DES encryption algorithm.
Inverse Initial Permutation
The 64-bit block undergoes an Inverse Initial Permutation (IP-1). This is essentially
the inverse of the initial permutation applied at the beginning.
Decryption in DES
Reverse Subkey Application: The 16 round keys generated during key scheduling
are used in reverse order (from K16 to K1) during decryption.
Inverse Feistel Function: The Feistel network structure ensures that decryption
mirrors encryption. Each round performs the same operations (expansion, S-box
substitution, permutation), but with reversed subkeys.
Final Permutation (FP): After 16 rounds, the output undergoes the Inverse Initial
Permutation (IP), reversing the initial shuffling.
DES Analysis
1. Avalanche Effect
A small change (1 bit) in the plaintext causes a large change in the ciphertext.
This makes it difficult for attackers to guess the original message.
2. Completeness Effect
Every bit of the ciphertext depends on many bits of the plaintext.
This provides better security through confusion and diffusion.
3. Weak Keys
Some DES keys are called weak keys.
These keys reduce security and should not be used.
4. Cryptanalysis
DES is a well-designed block cipher.
No major attacks have successfully broken DES except brute-force key search.
Advantages of DES
1. Standard Algorithm
DES was adopted as a standard encryption algorithm by the U.S. government.
2. Fast in Hardware
DES performs faster on hardware than on software.
3. Basis for Triple DES
Triple DES (3DES) is an improved version of DES.
It uses three keys (168-bit), making it much more secure than DES.
Disadvantages of DES
1. Weak Security
DES uses only a 56-bit key, which is considered weak today.
2. Vulnerable to Brute-Force Attack
Attackers can try all possible keys until the correct one is found.
3. Can Be Cracked
Special machines like Deep Crack were developed to break DES quickly.
Real-Life Example of DES (Data Encryption Standard)
Example: ATM Card Transactions
In older banking systems, DES was used to encrypt PIN numbers and transaction data sent
between an ATM and the bank's server.
How it works:
1. You enter your PIN at the ATM.
2. The PIN is encrypted using DES before transmission.
3. The encrypted data travels through the network.
4. The bank decrypts the data using the same secret key.
5. The PIN is verified securely.
Other Real-Life Applications of DES
Protecting banking and financial transactions (older systems).
Encrypting stored passwords and sensitive files.
Securing communication in legacy government and military systems.
Smart card and payment card applications.
Types of DES
1. Double DES
2. Triple DES
Double DES
Double DES is an encryption technique in which the DES algorithm is applied twice using
two different secret keys (K1 and K2) to improve security.
Working of Double DES
Step 1
Encrypt the plaintext using the first key (K1).
Plaintext → DES (K1) → Intermediate Ciphertext
Step 2
Encrypt the intermediate ciphertext again using the second key (K2).
Intermediate Ciphertext → DES (K2) → Final Ciphertext
Decryption
1. Decrypt the final ciphertext using K2.
2. Decrypt the result using K1.
3. The original plaintext is obtained.
Meet-in-the-Middle Attack
Definition
Meet-in-the-Middle Attack is a known-plaintext attack on Double DES. The attacker encrypts
the plaintext with all possible K1 values and decrypts the ciphertext with all possible K2
values. By matching the intermediate values, the attacker finds the correct keys more quickly
than using a brute-force attack.
How it Works
1. The attacker knows the Plaintext (P) and Ciphertext (C).
2. The attacker encrypts the plaintext using all possible K1 keys.
3. The attacker decrypts the ciphertext using all possible K2 keys.
4. The attacker compares the intermediate results.
5. When both results match (meet in the middle), the correct keys are found.
Advantages of Double DES:
Provides enhanced security.
Compatible with existing DES systems.
Well-studied and easy to implement.
Triple DES
Triple DES (3DES) is an improved version of DES that encrypts the data three times to
provide stronger security.
It is also called:
Triple DES
3DES
TDEA (Triple Data Encryption Algorithm)
Encryption Process of Triple DES (3DES)
Step 1: First Encryption
The plaintext is encrypted using the first key (K1).
Step 2: Decryption
The encrypted data is then decrypted using the second key (K2).
Step 3: Final Encryption
The result is encrypted again using the third key (K3).
Final Output
The final encrypted data is called the ciphertext.
Decryption Process
To recover the original plaintext:
1. Decrypt using K3.
2. Encrypt using K2.
3. Decrypt using K1.
Modules of Triple DES
1. Admin Login
Admin logs in using a username and password.
Can access all admin functions.
2. User Login
Users log in using their username and password.
Can access their account.
3. User Registration
New users register by providing:
o Username
o Password
o Address
o Mobile Number
o Email ID
4. Create Message (Admin)
Admin creates and sends encrypted messages to users using Triple DES.
5. Check Suspicious Mails
Admin checks mails marked as suspicious by the system.
6. Data Dictionary
Admin adds suspicious words to improve suspicious mail detection.
7. View Data Dictionary
Admin views or removes suspicious words.
8. View Users List
Admin views all registered users and can remove suspicious users.
9. Create Message (User)
Users send encrypted messages to other users.
The system checks whether the message is normal or suspicious.
10. User Inbox
Users can read and delete received messages.
ADVANCED ENCRYPTION STANDARD
AES (Advanced Encryption Standard) is a symmetric key encryption algorithm used to
securely encrypt and protect electronic data.
Characteristics
AES has keys of three lengths which are of 128, 192, 256 bits.
It is flexible and has implementation for software and hardware.
It provides high security and can prevent many attacks.
It doesn't have any copyright so it can be easily used globally.
It consists of 10 rounds of processing for 128 bit keys.
Working of the Cipher
AES performs operations on bytes of data rather than in bits. Since the block size is
128 bits, the cipher processes 128 bits (or 16 bytes) of the input data at a time.
The number of rounds depends on the key length as follows:
Encryption
AES considers each block as a 16-byte (4 byte x 4 byte = 128) grid in a column-major
arrangement.
Added Round Keys
Each round comprises of 4 steps:
SubBytes
ShiftRows
MixColumns
Add Round Key
Step 1: SubBytes (Substitution)
In this step, each byte is replaced with another byte.
The replacement is done using a Substitution Box (S-Box).
This makes the data more secure and difficult to predict.
The output remains a 4 × 4 matrix (16 bytes).
Step 2: ShiftRows (Row Shifting)
In this step, the rows of the matrix are shifted to the left.
Row Shift
1st Row No shift
2nd Row Shift left by 1
3rd Row Shift left by 2
4th Row Shift left by 3
Step 3: Mix Columns
This step is a matrix multiplication. Each column is multiplied with a specific matrix and thus
the position of each byte in the column is changed as a result. This step is skipped in the last
round.
Step 4: AddRoundKey
The output from the previous step is XORed with the Round Key.
This creates a new encrypted output.
The process is repeated for every round until the final ciphertext is produced.
AES Decryption
AES Decryption is the process of converting the ciphertext back into the original
plaintext using the same secret key.
Steps in AES Decryption
1. AddRoundKey
The ciphertext is XORed with the round key.
2. Inverse MixColumns
Reverses the MixColumns operation.
Restores the original column values.
3. Inverse ShiftRows
Shifts the rows to the right.
Reverses the ShiftRows step.
4. Inverse SubBytes
Replaces each byte with its original value using the Inverse S-Box.
Reverses the SubBytes step.
Applications of AES (Advanced Encryption Standard)
1. Wireless Security
Used to secure Wi-Fi networks.
Prevents unauthorized access.
2. Database Encryption
Encrypts sensitive data stored in databases.
Protects personal and financial information.
3. Secure Communication
Used in email, messaging, voice calls, and internet communication.
Keeps data private during transmission.
4. Data Storage
Encrypts data stored on hard disks, USB drives, and storage devices.
Protects data if the device is lost or stolen.
5. Virtual Private Network (VPN)
Used in VPNs to provide secure communication over the internet.
Protects user data from hackers.
6. Password Protection
Encrypts passwords before storing them.
Prevents unauthorized users from viewing passwords.
7. File and Disk Encryption
Encrypts files, folders, and disks.
Protects sensitive information on computers and cloud storage.
RSA Algorithm
(Rivest-Shamir-Adleman)
RSA (Rivest–Shamir–Adleman) is an asymmetric (public-key) encryption algorithm used for
secure communication and data encryption.
RSA is an asymmetric cryptography algorithm.
It uses two different keys:
Public Key – Used for encryption and can be shared with everyone.
Private Key – Used for decryption and must be kept secret.
Only the receiver, who has the private key, can decrypt the encrypted data.
Example of Asymmetric Cryptography:
If Person A wants to send a message securely to Person B:
Person A encrypts the message using Person B's Public Key.
Person B decrypts the message using their Private Key.
RSA Algorithm consists of three main stages:
1. Key Generation: Creating Public and Private Keys
2. Encryption: Sender encrypts the data using Public Key to get cipher text.
3. Decryption: Decrypting the cipher text using Private Key to get the original data.
1. Key Generation
Step1: Choose two large prime numbers p and q (These values are kept secret.)
Step2: Calculate: n = p × q (This value is used in both the Public Key and Private
Key.)
Step 3: Calculate Euler's Totient Function: Φ(n) = (p − 1) × (q − 1)
Step 4: Choose the Public Key (e)
e must satisfy:
1 < e < Φ(n)
e and Φ(n) must be co-prime (GCD = 1).
Step 5: Calculate the Private Key (d)
Choose d such that:
d × e ≡ 1 mod Φ(n)
This means d is the multiplicative inverse of e.
2. RSA Encryption
Steps
1. Convert the message (M) into numbers (using ASCII or another encoding
method).
2. Use the Public Key (n, e) to encrypt the message.
3. The ciphertext is calculated using:
Where:
M = Message (Plaintext)
C = Ciphertext
e = Public Key exponent
n = Product of p × q
3. RSA Decryption
Steps
1. Receive the Ciphertext (C).
2. Use the Private Key (n, d).
3. Recover the original message using:
Example of RSA Algorithm