TDCTF Academy Logo TDCTF ACADEMY

Expert 4: Homomorphic Encryption - Komputasi pada Data Terenkripsi

Target: Memahami homomorphic encryption - melakukan operasi pada ciphertext tanpa dekripsi
Tools: python3


Praktikum

Konsep: Dengan homomorphic encryption, Anda bisa mengirim data terenkripsi ke server, server memprosesnya (tanpa bisa lihat isi), dan mengembalikan hasil terenkripsi. Ini adalah Holy Grail privasi cloud.

cd ~ && mkdir crypto-exp4 && cd crypto-exp4

python3 << 'PYEOF'
# === SIMPLE HOMOMORPHIC ENCRYPTION (Paillier-like) ===
# Untuk demo: menggunakan enkripsi additively homomorphic sederhana

import random

class SimpleHomomorphic:
"""Simplified additively homomorphic encryption (unsecure, for demo)"""
def __init__(self):
self.key = random.randint(1000, 9999)

def encrypt(self, m):
return m + self.key # simplified: c = m + key

def decrypt(self, c):
return c - self.key

def add(self, c1, c2):
return c1 + c2 # E(m1) + E(m2) = E(m1 + m2)!

# === DEMO ===
crypto = SimpleHomomorphic()

# Alice punya dua angka
alice_salary = 50000
alice_bonus = 10000

# Alice encrypt
enc_salary = crypto.encrypt(alice_salary)
enc_bonus = crypto.encrypt(alice_bonus)

# Kirim ke cloud - server tidak tahu angka asli!
print("Data di cloud (encrypted):")
print(f" Enc Salary: {enc_salary}")
print(f" Enc Bonus: {enc_bonus}")
print()

# Server melakukan komputasi pada data terenkripsi
print("Server menghitung total gaji (homomorphically)...")
enc_total = crypto.add(enc_salary, enc_bonus) # E(salary) + E(bonus)
print(f" Enc Total: {enc_total}")
print()

# Alice decrypt hasilnya
total = crypto.decrypt(enc_total)
print(f"Alice decrypt: {total}")
print(f"✅ {alice_salary} + {alice_bonus} = {total}")
print()

# Demonstrasi: server tidak pernah lihat data asli!
print("=== Server tidak tahu apa-apa! ==*")
print(f"Server hanya lihat: {enc_salary}, {enc_bonus}, {enc_total}")
print(f"Server TIDAK TAHU: gaji Alice Rp 50.000!")
print()

# === Real-world comparison ===
print("=== Homomorphic Encryption Types ==*")
print(f"{'Type':<25} {'Supports':<30} {'Practical?'}")
print("-"*70)
print(f"{'Partially (PHE)':<25} {'Add atau Mul saja':<30} {'✅ Tahun 2000an'}")
print(f"{'Somewhat (SWHE)':<25} {'Add + Mul (terbatas)':<30} {'⚠️ Research'}")
print(f"{'Fully (FHE)':<25} {'Add + Mul (unlimited)':<30} {'⚠️ 2020s - slow'}")
print()
print("Contoh implementasi:")
print(" - Paillier: additively homomorphic")
print(" - ElGamal: multiplicatively homomorphic")
print(" - BFV/BGV: FHE (lattice-based)")
print(" - CKKS: FHE untuk floating point")
PYEOF

Temuan

Tipe HE Operasi Kecepatan Aplikasi
PHE (Paillier) Add Fast Voting, salary
SWHE Add + Mul Medium Research
FHE (CKKS) Unlimited Slow (1000x) Medical, ML

Refleksi: Homomorphic encryption adalah Holy Grail privasi cloud - server bisa memproses data sensitif tanpa pernah melihatnya. Saat ini FHE masih sangat lambat (~1000× lebih lambat dari plaintext), tapi perkembangan hardware dan algoritma menjanjikan. Dalam 5-10 tahun, FHE bisa menjadi standar untuk komputasi cloud yang privasi-aware.


Generated by @farishhz Agent Pentest Pipeline - TDCTF Security Academy

PADA HALAMAN INI