# Entropy-RNG: Camera-Based Random Number Generator This project uses a live video feed from an **Axis M1013** network camera to generate cryptographically secure random numbers. The camera is pointed at a high-contrast scene (e.g., ceiling and lamps) to ensure ever-changing pixel data, which is used as a source of entropy. --- ## How It Works 1. **Capture Image Frames** The script fetches a single frame from the camera's MJPEG stream using OpenCV or manual HTTP requests. 2. **Extract Entropy** The pixel data from the frame is hashed using SHA-256 to generate a high-quality entropy pool. 3. **Generate Random Numbers** The entropy is used to seed Python's `secrets` module, which generates cryptographically secure random numbers of specified bit lengths (e.g., 128-bit, 256-bit). --- ## Requirements - Python 3.x - OpenCV (`opencv-python`) - Pillow (`Pillow`) - `requests` library Install dependencies: ```bash pip install opencv-python Pillow requests ``` --- ## Usage ### 1. OpenCV Method (Recommended) Run the OpenCV script to fetch a frame and generate random numbers: ```bash python3 entropy-rng-opencv.py ``` **Example Output:** ``` 128-bit random number: 0x67dbaf3c5eba5a0d41429d2173a21f2f 256-bit random number: 0xe3a707c10f70f975e074633ad22ea0eaaa8b482e87c6418e3ae2380b2e647a4 ``` ### 2. Manual HTTP Method Run the manual script (alternative to OpenCV): ```bash python3 entropy-rng-cam.py ``` **Example Output:** ``` 128-bit random number: 0x494d97b11a4b6008e4597cfc29108354 256-bit random number: 0xd59f7f4d22ebf7507b702fb60e0f2a6ccbf2ad4b5e3ab969f9152222da8e9443 ``` --- ## Output Format The generated random numbers are in **hexadecimal format** (e.g., `0x67dbaf3c5eba5a0d41429d2173a21f2f`). - 128-bit numbers: 32 hex digits - 256-bit numbers: 64 hex digits --- ## Why This Approach? - **True Entropy Source**: The camera feed provides a dynamic, unpredictable source of entropy. - **Cryptographically Secure**: Uses SHA-256 hashing and Python's `secrets` module. - **No Additional Hardware**: Leverages existing network cameras. --- ## Notes - Ensure the camera feed is **dynamic** (e.g., pointing at changing light patterns). - For production use, consider adding error handling and logging.