Browse Source

Thermal entropy improvement

master
Joshua-Gordon 3 years ago
parent
commit
f70e92d80a
  1. 13
      routes.py
  2. 28
      thermal.py

13
routes.py

@ -27,10 +27,15 @@ def zero():
@app.route('/api/randbit', methods=["GET"])
def randbit():
bit = e.invoke_entropy(1)[0]
return jsonify({
"bit" : str(ord(bit))
})
try:
bit = e.invoke_entropy(1)[0]
return jsonify({
"bit" : str(ord(bit))
})
except IndexError:
return jsonify({
"bit" : "Entropy machine broke"
})
if __name__ == '__main__':
if len(sys.argv) == 2:

28
thermal.py

@ -0,0 +1,28 @@
#!/usr/bin/python3
import requests
import cv2
import shutil
API = "http://localhost:5000/api/"
def send(bit):
if bit == "1":
requests.get(API + "one")
elif bit == "0":
requests.get(API + "zero")
def thermal_entropy():
url = 'http://the-internet.cosi.clarkson.edu/thermal.jpg'
response = requests.get(url, stream=True)
with open('thermal.jpg', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
im = cv2.imread('thermal.jpg')
h,w,_ = im.shape
pixl = im[w//2,h//2]
for i in pixl:
b = "{0:b}".format(i)
for bit in b:
send(bit)
thermal_entropy()
Loading…
Cancel
Save