Please, for the love of all that is good in this world, do not use this for cryptography. Except the cryptography class. Let's all use this for the cryptography class.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
885 B

import time, os, struct
import fasteners
import threading
ENTROPY_FILE = "ted.pkk"
class EntropyPipe(object):
def __init__(self):
self._lock = threading.Lock()
@fasteners.locked
def add_entropy(self,bits):
with open(ENTROPY_FILE,'ab') as f:
b = bytearray(bits)
print(b)
f.write(b)
@fasteners.locked
def invoke_entropy(self,num_bits):
if num_bits == 0:
return None
with open(ENTROPY_FILE,'rb') as f:
bits = f.read(num_bits)
print(bits)
newdata = f.read()
with open(ENTROPY_FILE, 'wb') as out_file:
out_file.write(newdata[num_bits-1:])
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