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()