Skip to content

🔮Using a chaotic Plasma globe as an entropy source for random number generation

Notifications You must be signed in to change notification settings

JW2586/plasma-ball-entropy-generator

Repository files navigation

🔮 Plasma ball entropy generator

This is a proof of concept inspired by Cloudflare's implementation of Lavarand

alt text

Using a chaotic Plasma globe as an entropy source for random number generation

Extracts binary data from an image captured by a Raspberry Pi camera. Mixes the entropy with the number of nanoseconds since epoch. Seeds the entropy pool into a ChaCha20 CSPRNG.

import picamera
import picamera.array
import numpy
from PIL import Image
import hashlib
import time
import sys
from randomgen import ChaCha
from io import BytesIO

with picamera.PiCamera() as camera:
    with picamera.array.PiRGBArray(camera) as output:
        camera.resolution = (2464, 2464)
        camera.capture(output, 'rgb')
        pil_im = Image.fromarray(output.array, mode="RGB")
        hexStream = BytesIO()
        pil_im.save(hexStream, format="jpeg")
        hex_data = hexStream.getvalue()
        mixedEntropy = str(bin(int.from_bytes(hex_data,byteorder=sys.byteorder))[2:]) + str(bin(time.time_ns())[2:])
        hashHex = hashlib.sha256(str(mixedEntropy).encode('ASCII')).hexdigest()
        hashInt = int(hashHex, 16)
        randomNum = numpy.random.Generator(ChaCha(seed=hashInt))
        randomValue=randomNum.standard_normal()
        print(randomValue)

Alternative method adds up the RGB values for each pixel, creating an overall total. Mixes the value with the number of nanoseconds since epoch. Seeds the entropy pool into a ChaCha20 CSPRNG.

import picamera
import picamera.array
import numpy
from PIL import Image
import hashlib
import time
from randomgen import ChaCha

with picamera.PiCamera() as camera:
    with picamera.array.PiRGBArray(camera) as output:
        camera.resolution = (2464, 2464)
        camera.capture(output, 'rgb')
        pixelTotal = numpy.sum(output.array)
        pixelTotal = int(str(pixelTotal)[1:])
        mixedEntropy = str(bin(pixelTotal)[2:]) + str(bin(time.time_ns())[2:])
        hashHex = hashlib.sha256(mixedEntropy.encode('ASCII')).hexdigest()
        hashInt = int(hashHex, 16)
        randomNum = numpy.random.Generator(ChaCha(seed = hashInt))
        randomValue = randomNum.standard_normal()
        print(randomValue)

References

About

🔮Using a chaotic Plasma globe as an entropy source for random number generation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages