An AVRNG implementation
Project description
AVRNG - GVRSF 2020 submission
An audio-visual random number generator, built for the Vancouver District Science Fair 2020.
Built with Python 3.7, October 2019 - current.
This PIP package is a mirror of the project at the GitHub. This distribution may lag behind development at the GitHub.
Applications
The AVRNG works well in a variety of application, mainly for security and surveillance-based solutions. One example use case is in an office, where security cameras can pass footage to the AVRNG and generate keys for the office's encryption algorithms. These keys are truly random due to the inherent randomness in sensor data when capturing footage, and to unpredictable compression and time-stamps.
To find the key, an attacker would have to obtain the exact data source with the same compression and XOR rate, and hash at the exact time and parameters the program would be running at. This security makes the AVRNG a TRNG.
A main inspiration was unique TRNG creations, such as the ones employed by Cloudflare. A great video on the topic was created by Tom Scott.
How it works
A video is split into audio and video streams. These streams are cut to smaller intervals.
For the audio, it's split on the interval specified in running the AVRNG. This smaller .wav file is hashed with Skein, a next-level hash and former SHA3 candidate.
The video stream is cut with the scenedetect tool, splitting at every unique scene. This works especially well with security footage (main application) with many pauses or intervals of near-identical footage. These smaller videos are then split into individual JPEGS, due to the JPEG's compression algorithm that will preserve the inherent randomness in the camera's sensor data. These photos then are hashed with Skein, as above.
These two data streams are intertwined together along with a time component, using XOR and bit addition algorithms. These outputs are written to a file, which can then be used as keys for cryptosecure applications.
Installation
With PIP
This method requires PIP to be installed and set up on your machine.
Open Terminal, and run pip install avrng
to install the package.
With Git / Command Line
This method requires Git to be set up properly and configured on your machine.
Open Terminal, Command Prompt, or Git Bash (or any terminal app), and run git clone https://github.com/kewbish/avrng.git
to create a copy of this repo on your local machine.
You should have a folder with the files. Proceed to installing dependencies.
With GitHub.com UI
Navigate to https://github.com/kewbish/avrng and click the green Clone or download
button. Choose to Download ZIP
. Navigate to the folder downloaded, and unzip the project files. Proceed to installing dependencies.
With GitHub Desktop
This method requires GitHub Desktop.
Open GitHub Desktop. (Alternatively, click Clone or download
and select Open with Desktop
.)
Click the Add
dropdown in the top-left, and select Clone a repository
. Open the URL
pane, and paste https://github.com/kewbish/avrng
into the Repository URL
field. Select a local path, and click Clone
.
You should now have a copy of the project files. Proceed to installing dependencies.
Dependencies
Install the following via pip:
- Pydub
- Pyskein
- Scenedetect (requires numpy, opencv2, and ffmpeg)
Alternatively, run
pip install -r requirements.txt
with the prepackaged requirements file.
Documentation
A GUI tool and a CLI are included.
GUI Usage
To run the GUI, open Terminal (or similar) and run python3 main.py
in the project root. Alternatively, run main.py
in an IDE.
To use the Tkinter GUI, input your desired values. The defaults are what I've tested to be the most consistent.
The end button will open a file dialog. Navigate to your desired source .mp4.
The output file will be generated in the parent directory of the selected video file.
CLI Usage
To use the CLI, open Terminal (or similar) and run python3 hash.py path\to\file.mp4 17 1
.
The return_all()
function wraps all the functionality of the AVRNG into one function.
Its three arguments are as follows:
- path: complete path to source file
- cs: length of individual output number
- ai: interval to read data, in seconds
Sample command -
python hash.py \files\video.mp4 17 1
This will generate a text file with individual numbers invideos
directory.
This format is also used when importing and using theavrng
pip package.
PIP Package
Add import avrng.avrng as av
to the top of your Python file to add the package to your script.
Use the function as av.return_all()
with the appropriate arguments.
(If you alternatively only want hashed lists of audio or video streams, you can access these through av.handle_audio()
or av.handle_video()
with the path and an integer as arguments.)
Comparison
The following comparison is between the AVRNG and the inbuilt Python random.randint() function.
Test | AVRNG | Inbuilt Python | Comments |
---|---|---|---|
Runs Test | 0.38529 | 0.15147 | AVRNG 2.5 times more random |
Entropy / bit | 0.984360 | 0.982485 | AVRNG 0.19% more random |
Chi square | 28742.64 | 365.44 | AVRNG 78.65 times more distributed |
Arithmetic mean | 0.4265 | 0.4222 | AVRNG closer to target 0.5 |
Serial correlation | 0.018786 | 0.019704 | AVRNG closer to zero, more unexpected |
Speed | 22.47s | 0.03513s | Inbuilt Python 639.5 times more efficient |
License
Released under the GNU General Public License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file avrng-1.0.tar.gz
.
File metadata
- Download URL: avrng-1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67af7420d8754bfa16c00432ddcd64be39ea63cb95fed1a1f9a69611eb9b49d0 |
|
MD5 | 72e8bdd8365f0387e4162c48d2a953f7 |
|
BLAKE2b-256 | 1c788e27bd1a6e13ff6b06123fe87b3d35a6c348884c7a3df41e1089a4e608b3 |
File details
Details for the file avrng-1.0-py3-none-any.whl
.
File metadata
- Download URL: avrng-1.0-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92f05f51c5d7fc84bac9a01af207775d2b3c12d2e04a663fbc349450d2176a9a |
|
MD5 | 094e6c382faeeb9a20ddc467e1346221 |
|
BLAKE2b-256 | dc16338ef67344eae33c1bbcdfe6e9ad1ddd46e7a385440a5b372736bba6ccde |