masterthesis/codes/md5dist-plot/dist.py

47 lines
1.3 KiB
Python
Raw Normal View History

2022-03-29 20:37:56 +02:00
#!/usr/bin/env python3
from collections import defaultdict
import matplotlib.pyplot as plt
def main():
with open('./countmap.txt', 'r') as f:
countmap = {}
keys = []
values = []
for line in f:
split = line.split(': ')
prefix = split[0].strip()
key = int(prefix, 16)
value = int(split[1].strip())
countmap[key] = value
keys.append(key)
values.append(value)
plt.bar(keys, values)
plt.title('Distribution of lowest byte of hashed IP addresses')
plt.savefig('dist.png')
plt.show()
# with open('./hashes.txt', 'r') as f:
# # countmap = defaultdict(lambda: 0)
# ints = set()
# data = []
# for line in f.readlines():
# # line = line.strip()
# # prefix = line[len(line) - 2:]
# prefix = line.strip()
# ints.add(prefix)
# # countmap[prefix] = countmap[prefix] + 1
# data.append(int(prefix, 16))
# plt.hist(data, bins=len(ints))
# plt.title('Distribution of lowest byte of hashed IP addresses')
# plt.savefig('dist.png')
# plt.show()
# # print(countmap)
if __name__ == '__main__':
main()