Encryption
Obfuscation
특징
| 구분 | Encryption | Steganography |
|---|---|---|
| 핵심 목적 | 기밀성 | 은닉 |
| 공격자가 보는 것 | 암호문 | 정상 데이터 |
| 키의 역할 | 필수 | 선택적 |
| 해독 가능성 | 해독 불가 | 즉시 노출 |
Symmetric-Key Encryption 실습
코드
from cryptography.fernet import Fernet
key = Fernet.generate_key()
cipher = Fernet(key)
print("Secret Key:", key)
plaintext = b"Hello Security+"
print("Plaintext:", plaintext)
ciphertext = cipher.encrypt(plaintext)
print("Ciphertext:", ciphertext)
decrypted = cipher.decrypt(ciphertext)
print("Decrypted:", decrypted)
출력
Secret Key: b'o0bqtDCZB9600KQ_DaJeRf_2Sp8OsHyQAWgqVWLYhBs='
Plaintext: b'Hello Security+'
Ciphertext: b'gAAAAABpXNCKl_2EpnjQEJjjYVirMh8mOeNoa3991iuwBZdND0HJy8A9rkous8DvPQ7RPSq7DD6Yq22F1oYffHrrj_E-taSJrg=='
Decrypted: b'Hello Security+'
Image-Steganography-Encode 실습
from PIL import Image
img = Image.open("input.png").convert("RGB")
pixels = img.load()
secret_message = "HELLO"
binary = "".join(format(ord(c), "08b") for c in secret_message) + "00000000"
width, height = img.size
idx = 0
for y in range(height):
for x in range(width):
if idx >= len(binary):
break
bit = int(binary[idx])
r, g, b = pixels[x, y]
r = 255 if bit == 1 else 0
pixels[x, y] = (r, g, b)
idx += 1
img.save("encoded_image.png")
print("✅ Visible steganography image created: stego_visible.png")
원본 이미지

인코딩된 이미지

Image-Steganography-Decoder 실습
Code
from PIL import Image
img = Image.open("encoded_image.png").convert("RGB")
pixels = img.load()
width, height = img.size
bits = ""
for y in range(height):
for x in range(width):
r, g, b = pixels[x, y]
bit = "1" if r >= 128 else "0"
bits += bit
message = ""
for i in range(0, len(bits), 8):
byte = bits[i : i + 8]
if len(byte) < 8:
break
if byte == "00000000":
break
message += chr(int(byte, 2))
print("✅ Decoded message:", message)