Last active
July 16, 2018 15:01
-
-
Save chrisdpa-tvx/df744a7e6402fe1390550cc5479550f8 to your computer and use it in GitHub Desktop.
Hide high entropy strings
This file contains 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
#!/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