Imager XOR

Descrizione

Benvenuto su Imager XOR, un sito che ti permette di cifrare immagini usando la tecnica XOR o di combinare due immagini tra loro.


Funzionalità

XOR Properties

SOURCE

import io
import os
import json

from flask import Flask, render_template, send_file, request

app = Flask(__name__)
KEY = os.urandom(1000000) # 1MB of random data

def xor(a: bytes, b: bytes) -> bytes:
    return bytes([x ^ y for x, y in zip(a, b)])


@app.route("/encrypt_image", methods=["POST"])
def encrypt_image():
    if "image" not in request.files:
        return json.dumps({"error": "No image provided"}), 400

    image = request.files["image"]

    # Check if the image is a PNG, JPG or JPEG
    if not any([image.filename.endswith(ext) for ext in [".png", ".jpg", ".jpeg"]]):
        return json.dumps({"error": "Invalid image format"}), 400

    data_image = image.read()
    if not data_image:
        return json.dumps({"error": "No image provided"}), 400

    if len(data_image) > 1000000: # 1MB
        return json.dumps({"error": "Image is too large (Max 1MB)"}), 400

    encrypted_image = xor(data_image, KEY)

    # Save the encrypted image to a file
    encrypted_io = io.BytesIO(encrypted_image)
    encrypted_io.seek(0)

    ext = image.filename.rsplit(".", 1)[-1] # Get the extension of the uploaded image
    return send_file(encrypted_io, mimetype="application/octet-stream", as_attachment=True, download_name=f"encrypted_image.{ext}")

@app.route("/images_xor", methods=["POST"])
def images_xor():
    if "first_image" not in request.files or "second_image" not in request.files:
        return json.dumps({"error": "No images provided"}), 400

    image1 = request.files["first_image"]
    image2 = request.files["second_image"]

    if not any([image1.filename.endswith(ext) for ext in [".png", ".jpg", ".jpeg"]] + [image2.filename.endswith(ext) for ext in [".png", ".jpg", ".jpeg"]]):
        return json.dumps({"error": "Invalid image format"}), 400

    data_image1 = image1.read()
    data_image2 = image2.read()

    if not data_image1 or not data_image2:
        return json.dumps({"error": "No images provided"}), 400

    if len(data_image1) > 1000000 or len(data_image2) > 1000000: # 1MB
        return json.dumps({"error": "Image is too large (Max 1MB)"}), 400

    xored_image = xor(data_image1, data_image2)

    xored_io = io.BytesIO(xored_image)
    xored_io.seek(0)

    ext = image1.filename.rsplit(".", 1)[-1] # Get the extension of the uploaded image
    return send_file(xored_io, mimetype="application/octet-stream", as_attachment=True, download_name=f"xored_image.{ext}")

@app.route("/get_flag")
def get_flag():
    return send_file("static/images/encrypted_flag.png", mimetype="image/png", as_attachment=True, download_name="encrypted_flag.png")

Encrypt Image

OUTPUT

XORing Images

OUTPUT