Browse Source

Frontend improvements

compression
Joshua-Gordon 3 years ago
parent
commit
00b32c9c04
  1. 9
      entropy.py
  2. 9
      routes.py
  3. 8
      static/bit_script.js
  4. 2
      templates/bitpage.html

9
entropy.py

@ -1,4 +1,4 @@
import time, os
import time, os, struct
import fasteners
import threading
@ -27,6 +27,11 @@ class EntropyPipe(object):
newdata = f.read()
with open(ENTROPY_FILE, 'wb') as out_file:
out_file.write(newdata[num_bits-1:])
return bits
bits_int = []
for b in bits:
print(b)
bits_int.append(str(b))
#bits_int = [1 if b == b'\x01' else 0 for b in bits]
return bits_int

9
routes.py

@ -1,4 +1,4 @@
from flask import Flask, render_template
from flask import Flask, render_template, jsonify
import sys
@ -25,6 +25,13 @@ def zero():
e.add_entropy([False])
return render_template('bitpage.html')
@app.route('/api/randbit', methods=["GET"])
def randbit():
bit = e.invoke_entropy(1)[0]
return jsonify({
"bit" : str(ord(bit))
})
if __name__ == '__main__':
if len(sys.argv) == 2:
port = sys.argv[1]

8
static/bit_script.js

@ -21,3 +21,11 @@ function send(bool) {
xhr.open("GET",specific_url,true)
xhr.send()
}
function receive() {
fetch(url + "randbit")
.then((data) => data.json())
.then((value) => {
document.getElementById("bit").innerHTML = JSON.stringify(value["bit"])
})
}

2
templates/bitpage.html

@ -6,4 +6,6 @@
<h2>Add a bit to the entropy pool:</h2>
<button onClick="send(true)">One</button>
<button onClick="send(false)">Zero</button>
<h2>Need a bit? Get one here: <div id="bit">_</div></h2>
<button onClick="receive()">Get bit</button>
{% endblock %}
Loading…
Cancel
Save