for i in range(256): j = (j + S[i] + key[i % key_length]) % 256 S[i], S[j] = S[j], S[i] # 交换 return S
def rc4_generate_keystream(S, data_length: int): """RC4 Pseudo-Random Generation Algorithm (PRGA)""" i = 0 j = 0 keystream = [] for _ in range(data_length): i = (i + 1) % 256 j = (j + S[i]) % 256 S[i], S[j] = S[j], S[i] # 交换 K = S[(S[i] + S[j]) % 256] keystream.append(K) return keystream
def rc4_decrypt(key: bytes, ciphertext: bytes) -> bytes: S = rc4_init(key) keystream = rc4_generate_keystream(S, len(ciphertext)) return bytes([c ^ k for c, k in zip(ciphertext, keystream)])
key = bytes((c ^ (i + 42)) for i, c in enumerate(LEAD_RESEARCHER_SIGNATURE)) plaintext = rc4_decrypt(key, ciphertext) print(plaintext.decode(errors="ignore"))
with open('hidden.jpg', 'wb') as f: f.write(bytes.fromhex('ffd8ffe000104a46494600010100000100010000ffdb00430001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffc0000b080001002501011100ffc40017000100030000000000000000000000000006040708ffc400241000000209050100000000000000000000000702050608353776b6b7030436747577ffda0008010100003f00c54d3401dcbbfb9c38db8a7dd265a2159e9d945a086407383aabd52e5034c274e57179ef3bcdfca50f0af80aff00e986c64568c7ffd9'))
from PIL import Image import numpy as np
img = Image.open('hidden.jpg') pixels = np.array(img).flatten() text = ''.join(chr(p) for p in pixels) print(text)