Skip to content

Instantly share code, notes, and snippets.

@cryptolok
Last active November 3, 2019 19:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cryptolok/de265ce9e466cae167179378ee8eef7e to your computer and use it in GitHub Desktop.
Save cryptolok/de265ce9e466cae167179378ee8eef7e to your computer and use it in GitHub Desktop.
WebCam video-based pseudo-random number generator
#!/bin/bash
# poor-man's quantum photon detector randomizer
# ~1kb/s
# over a test of a thousand time, global entropy was equal to 7.99/8 and passed nearly all Dieharder tests, as well as FIPS 140-2
# however, sigma, mean and chi-square stats aren't too much enthusiastic
# overall, the result is pretty impressive, but of course, don't use it in production :)
DEVICE=/dev/video0
# for external cameras should be /dev/video1
FORMAT=image2pipe
# fps-based image sequence from demuxer through pipe, format is automatically determined, as well as FPS and resolution
# TODO force PNG format?
TIMING=0.1
# such timing is considered more or less practical for RNG based on my tests
while true
do
ffmpeg -i $DEVICE -f $FORMAT -t $TIMING - 2> /dev/null | sha512sum | cut -d ' ' -f 1
done
# in the end when pressing Ctrl+C there will be repetitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment