SecurityCryptography
Interactive Lab
๐ Cryptography Lab
Explore encryption algorithms โ from classical ciphers to modern RSA, AES, and cryptographic hashing. Interactive simulators let you see every step of the process.
Symmetric Encryption
Same key encrypts and decrypts. Fast and efficient for bulk data. Examples: AES, DES, Blowfish.
Use when: encrypting files, database columns, or large volumes of data where both parties already share a secret key.
Asymmetric Encryption
Public key encrypts, private key decrypts. Solves key distribution. Examples: RSA, ECC, DSA.
Use when: key exchange, digital signatures, TLS/SSL certificates, and scenarios where parties have never shared a secret.
125
Encrypted
KHOOR
Decrypted
HELLO
Substitution Table
A
โ
D
B
โ
E
C
โ
F
D
โ
G
E
โ
H
F
โ
I
G
โ
J
H
โ
K
I
โ
L
J
โ
M
K
โ
N
L
โ
O
M
โ
P
N
โ
Q
O
โ
R
P
โ
S
Q
โ
T
R
โ
U
S
โ
V
T
โ
W
U
โ
X
V
โ
Y
W
โ
Z
X
โ
A
Y
โ
B
Z
โ
C
Algorithm Comparison
| Algorithm | Type | Key Size | Speed | Use Case |
|---|---|---|---|---|
| AES | Symmetric | 128/256 bits | Fast | Data at rest, TLS |
| DES | Symmetric | 56 bits | Fast | Legacy systems |
| RSA | Asymmetric | 2048/4096 bits | Slow | Key exchange, signatures |
| ECC | Asymmetric | 256 bits | Moderate | Mobile, IoT, TLS |
| Blowfish | Symmetric | 32-448 bits | Fast | File encryption |
| DSA | Asymmetric | 1024/2048 bits | Slow | Digital signatures |
Cryptography Interview Questions
1. What is the difference between symmetric and asymmetric encryption?
Symmetric encryption uses the same key for encryption and decryption (e.g., AES). Asymmetric encryption uses a public key to encrypt and a private key to decrypt (e.g., RSA). Symmetric is faster but requires secure key exchange; asymmetric solves key distribution but is computationally expensive.
2. How does RSA encryption work?
RSA relies on the difficulty of factoring large primes. Two large primes p and q are chosen, n = p ร q, ฯ(n) = (p-1)(q-1). A public exponent e is chosen (typically 65537), and the private key d = eโปยน mod ฯ(n). Encryption: c = m^e mod n. Decryption: m = c^d mod n.
3. What is the difference between hashing and encryption?
Hashing is a one-way function that produces a fixed-size output; it cannot be reversed. Encryption is a two-way function that can be decrypted with the proper key. Hashing is used for integrity checks and password storage; encryption is used for confidentiality.
4. What is a digital signature and how does it work?
A digital signature provides authenticity and non-repudiation. The sender hashes the message and encrypts the hash with their private key. The receiver decrypts the hash with the sender's public key and compares it to the hash of the received message. If they match, the message is authentic.
5. What is the AES encryption algorithm?
AES (Advanced Encryption Standard) is a symmetric block cipher that operates on 128-bit blocks with 128/192/256-bit keys. It uses multiple rounds (10/12/14) of SubBytes, ShiftRows, MixColumns, and AddRoundKey operations. It is the standard for modern symmetric encryption.
AES Encryption Code Examples
Python
from cryptography.fernet import Fernet # Generate a key key = Fernet.generate_key() cipher = Fernet(key) # Encrypt plaintext = b"Sensitive data" ciphertext = cipher.encrypt(plaintext) # Decrypt decrypted = cipher.decrypt(ciphertext) print(decrypted.decode())
JavaScript (Node.js)
const crypto = require('crypto');
const algorithm = 'aes-256-cbc';
const key = crypto.randomBytes(32);
const iv = crypto.randomBytes(16);
function encrypt(text) {
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
function decrypt(encrypted) {
const decipher = crypto.createDecipheriv(algorithm, key, iv);
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}Go
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"fmt"
)
func main() {
key := []byte("examplekey123456")
plaintext := []byte("Hello, AES!")
block, _ := aes.NewCipher(key)
aesGCM, _ := cipher.NewGCM(block)
nonce := make([]byte, aesGCM.NonceSize())
rand.Read(nonce)
ciphertext := aesGCM.Seal(nil, nonce, plaintext, nil)
fmt.Printf("Encrypted: %x\n", ciphertext)
}