Here is a simple python code implementation. The code reads as a binary [rb] the file [file_path], then for the given set of characters [user_set], it counts how many each set occurred in the file and makes a dictionary [stat] with 'character set in hexadecimal' as key, and 'count of that character set' as value. Finally, prints character set in hex with their corresponding count, ordered by count.
import operator
file_path = 'example.bin'
with open(file_path, 'rb') as f:
content = f.read()
length = content.__len__()
user_set = 3
stat = {}
for i in range(length - user_set):
select = content[i:i + user_set]
count = 0
for j in range(length - user_set):
if select == content[j:j + user_set]:
count += 1
i += user_set - 1
if count>1: # if count=1, then its not included
stat[select] = count
sorted_stat = sorted(stat.items(), key=operator.itemgetter(1), reverse=True)
for x in range(1,len(sorted_stat)):
print(sorted_stat[x][0].hex()," :appeared -->",sorted_stat[x][1]," times")
an example result
f7d483 :appeared --> 5 times
0191ed :appeared --> 2 times
019075 :appeared --> 2 times