write-ups-challenges-2024-2025/budapest/decrypt_image.py
2024-11-25 22:28:19 +01:00

18 lines
561 B
Python

def decrypt_image():
print("Decrypting image...")
in_path = "budapest_encrypted.jpg"
out_path = "budapest_decrypted.jpg"
key = [str(ord(c)) for c in input("Enter the key to decrypt the image: ")]
file = open(in_path, 'rb')
img = file.read()
file.close()
img_bytes = bytearray(img)
for index, values in enumerate(img_bytes):
img_bytes[index] = values ^ int(key[index % len(key)])
img = open(out_path, 'wb')
img.write(bytes(img_bytes))
img.close()
print("Image decrypted successfully")
decrypt_image()