Skip to content

Instantly share code, notes, and snippets.

@607011
Created June 8, 2018 14:27
Show Gist options
  • Save 607011/38affdc7c075d777882f1c16b67e2ca4 to your computer and use it in GitHub Desktop.
Save 607011/38affdc7c075d777882f1c16b67e2ca4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from pymouse import PyMouseEvent
import hashlib
import struct
class Entropist(PyMouseEvent):
def __init__(self, hashfunc=hashlib.sha512):
super(Entropist, self).__init__()
self.verbose = False
self.hash = hashfunc()
self.THRESHOLD = 1024 * self.hash.block_size / 8
self.total = 0
self.entropy = bytearray()
self.last_x = 0
self.last_y = 0
def move(self, x, y):
data = struct.pack("ff", self.last_x - x, self.last_y - y)
self.last_x, self.last_y = x, y
self.hash.update(data)
self.total += len(data)
if self.verbose:
print('\r> {} {}'.format(self.hash.hexdigest(), self.total), end='')
if self.total > self.THRESHOLD:
self.total = 0
self.entropy += self.hash.digest()
if self.verbose:
print('\n{}\n'.format(self.entropy.hex()))
else:
print(self.hash.hexdigest(), end='', flush=True)
E = Entropist(hashlib.sha512)
E.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment