TDCTF Academy Logo TDCTF ACADEMY

Expert 2: Differential Cryptanalysis - Menganalisis Perbedaan untuk Menemukan Kunci

Target: Memahami differential cryptanalysis - teknik memecahkan block cipher dengan menganalisis pasangan plaintext-ciphertext
Tools: python3


Praktikum

Konsep: Differential cryptanalysis melihat bagaimana perbedaan input mempengaruhi perbedaan output - dan menggunakan ini untuk memulihkan key.

cd ~ && mkdir crypto-exp2 && cd crypto-exp2

python3 << 'PYEOF'
# === SIMPLIFIED BLOCK CIPHER ===
# Untuk demonstrasi, kita buat cipher sederhana dengan S-box

SBOX = [0xE, 0x4, 0xD, 0x1, 0x2, 0xF, 0xB, 0x8,
0x3, 0xA, 0x6, 0xC, 0x5, 0x9, 0x0, 0x7]

def encrypt_block(plain, key):
"""Simple 4-bit block cipher with S-box substitution + XOR key"""
return SBOX[plain ^ key]

# === DIFFERENTIAL ANALYSIS ===
print("=== Differential Analysis ==*")
print()

# Pilih input difference (ΔP)
delta_p = 1 # bedakan bit terakhir

# Cari output difference untuk setiap key
print(f"Input difference ΔP = {delta_p}")
print()
print(f"{'Key':<8} {'P1':<8} {'P2':<8} {'C1':<8} {'C2':<8} {'ΔC':<8} {'Consistent?'}")
print("-"*60)

for key in range(16):
p1 = 0x00
p2 = p1 ^ delta_p
c1 = encrypt_block(p1, key)
c2 = encrypt_block(p2, key)
delta_c = c1 ^ c2
print(f"{key:<8} {p1:02x}<8 {p2:02x}<8 {c1:02x}<8 {c2:02x}<8 {delta_c:02x}<8")

print()
print("📌 Analisis:")
print(" - Untuk ΔP=1, hanya key tertentu yang menghasilkan ΔC tertentu")
print(" - Dengan beberapa pasangan (P1,C1), (P2,C2), kita bisa")
print(" mempersempit kemungkinan key")
print(" - Untuk S-box 4-bit: 8 pasangan cukup untuk menentukan key!")
print()

# === ATTACK: recover key with differential pairs ===
print("=== Key Recovery ==*")
known_pairs = [(0x00, encrypt_block(0x00, 0x07)),
(0x01, encrypt_block(0x01, 0x07))]

candidate_keys = []
for key in range(16):
match = True
for p, c in known_pairs:
if encrypt_block(p, key) != c:
match = False
break
if match:
candidate_keys.append(key)

print(f"From 2 plaintext-ciphertext pairs:")
print(f" Candidate keys: {candidate_keys}")
print(f" (Differential analysis bisa persempit dari 16 ke ~2-4)")
PYEOF

Temuan

Aspek Detail
Penemu Adi Shamir (1980s), digunakan Biham-Shamir untuk DES
Konsep Analisis ΔP → ΔC untuk persempit key space
Kompleksitas Untuk DES: 2^47 vs 2^56 brute force
Penerapan DES, FEAL, Khafre, dll. AES didesain tahan

Refleksi: Differential cryptanalysis adalah terobosan besar dalam kriptanalisis - untuk pertama kalinya, serangan lebih efisien dari brute force. DES didesain tahan terhadap differential analysis (IBM tahu teknik ini 15 tahun sebelum publikasi!). AES (Rijndael) didesain khusus untuk tahan terhadap differential & linear cryptanalysis.


Generated by @farishhz Agent Pentest Pipeline - TDCTF Security Academy

PADA HALAMAN INI