Created
July 17, 2017 20:34
-
-
Save edcrypt/081096cfa7f20ec28cf39b80d4b8eb44 to your computer and use it in GitHub Desktop.
Entropy Harvester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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