Skip to content

Instantly share code, notes, and snippets.

@chrisdpa-tvx
Last active July 16, 2018 15:01
Show Gist options
  • Save chrisdpa-tvx/df744a7e6402fe1390550cc5479550f8 to your computer and use it in GitHub Desktop.
Save chrisdpa-tvx/df744a7e6402fe1390550cc5479550f8 to your computer and use it in GitHub Desktop.
Hide high entropy strings
#!/usr/bin/python -u
import math
import sys
def entropy(string):
prob = [float(string.count(c)) / len(string) for c in dict.fromkeys(list(string))]
return - sum([p * math.log(p) / math.log(2.0) for p in prob])
for l in sys.stdin.readlines():
for a in l.split():
if entropy(a) > 4.4:
print('*')
else:
sys.stdout.write(a)
sys.stdout.write(' ')
sys.stdout.write('\n')
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment