Browse Source

Allow bit input

compression
Joshua-Gordon 3 years ago
parent
commit
a23b7de619
  1. 1
      .gitignore
  2. 2
      entropy.py
  3. 17
      routes.py
  4. 23
      static/bit_script.js
  5. 3
      templates/base.html
  6. 9
      templates/bitpage.html
  7. 1
      templates/index.html

1
.gitignore

@ -1,2 +1,3 @@
*.db
*.pkk
*.pyc

2
entropy.py

@ -12,7 +12,7 @@ class EntropyPipe(object):
@fasteners.locked
def add_entropy(self,bits):
with open(ENTROPY_FILE,'wb') as f:
with open(ENTROPY_FILE,'ab') as f:
b = bytearray(bits)
print(b)
f.write(b)

17
routes.py

@ -2,12 +2,29 @@ from flask import Flask, render_template
import sys
import entropy
app = Flask(__name__)
e = entropy.EntropyPipe()
@app.route('/')
def root():
return render_template('index.html')
@app.route('/bits')
def bits():
return render_template('bitpage.html')
@app.route('/api/one', methods=["GET"])
def one():
e.add_entropy([True])
return render_template('bitpage.html')
@app.route('/api/zero', methods=["GET"])
def zero():
e.add_entropy([False])
return render_template('bitpage.html')
if __name__ == '__main__':
if len(sys.argv) == 2:
port = sys.argv[1]

23
static/bit_script.js

@ -0,0 +1,23 @@
const url = "/api/"
params = {
"method" : "GET"
}
function send(bool) {
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if(xhr.readyState == 4) {
console.log(xhr.response)
} else {
console.log(xhr)
}
}
if(bool) {
var specific_url = url + "one"
} else {
var specific_url = url + "zero"
}
console.log(specific_url)
xhr.open("GET",specific_url,true)
xhr.send()
}

3
templates/base.html

@ -3,6 +3,9 @@
<meta charset='utf-8'>
{% block style %}
{% endblock %}
{% block script %}
{% endblock %}
<title>COSI Random</title>
</head>

9
templates/bitpage.html

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block script %}
<script src="/static/bit_script.js"></script>
{% endblock %}
{% block content %}
<h2>Add a bit to the entropy pool:</h2>
<button onClick="send(true)">One</button>
<button onClick="send(false)">Zero</button>
{% endblock %}

1
templates/index.html

@ -1,4 +1,5 @@
{% extends "base.html" %}
{% block content %}
<p>Hello, welcome to COSI Random! Have a complementary bit: 0</p>
<p>Give us some <a href="/bits">bits</a>?</p>
{% endblock %}
Loading…
Cancel
Save