Skip to content

Instantly share code, notes, and snippets.

@edcrypt
Created July 17, 2017 20:34
Show Gist options
  • Save edcrypt/081096cfa7f20ec28cf39b80d4b8eb44 to your computer and use it in GitHub Desktop.
Save edcrypt/081096cfa7f20ec28cf39b80d4b8eb44 to your computer and use it in GitHub Desktop.
Entropy Harvester
import entropy # pip install entropy
from collections import namedtuple
MIN_ENTROPY = 0.5
MIN_LENGTH = 140
S = namedtuple('S', 'text entropy')
def read_entropic(prompt='', min_entropy=MIN_ENTROPY, min_length=MIN_LENGTH):
s = ''
ent = 0
length = 0
while ent <= min_entropy and length < min_length:
if s:
s += '\n'
s += input(prompt)
length = len(s)
ent = entropy.shannon_entropy(s)
return S(s, ent)
if __name__ == '__main__':
print('Smash the keyboard. Hit [ENTER].')
print('Repeat until we harvest enough entropy:')
print(read_entropic())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment