import matplotlib.pyplot as plt # Function to convert file to hex def file_to_hex(filename): with open(filename, 'rb') as f: return f.read().hex() # List of your files files = ["testfile1", "testfile2", "testfile3", "testfile4"] # Convert files to hex hex_files = [file_to_hex(file) for file in files] # Align hex values max_len = max(len(h) for h in hex_files) aligned_hex_files = [h.ljust(max_len, '0') for h in hex_files] # Function to compare hex files and determine differences def compare_hex_files(hex_files): differences = [] num_files = len(hex_files) length = len(hex_files[0]) for i in range(0, length, 2): chunk = [hex_file[i:i+2] for hex_file in hex_files] unique_chunks = set(chunk) if len(unique_chunks) == 1: differences.append('ALL_SAME') elif len(unique_chunks) == num_files: differences.append('ALL_DIFFERENT') else: differences.append('MAJORITY_WINS') return differences # Compute differences diffs = compare_hex_files(aligned_hex_files) # Simple text-based output of differences for i, diff in enumerate(diffs): print(f'Byte {i:04x}: {diff}') # Advanced visualization using matplotlib colors = {'ALL_SAME': 'green', 'ALL_DIFFERENT': 'red', 'MAJORITY_WINS': 'yellow'} color_list = [colors[diff] for diff in diffs] plt.figure(figsize=(12, 6)) plt.bar(range(len(diffs)), [1] * len(diffs), color=color_list) plt.xlabel('Byte Position') plt.ylabel('Difference') plt.title('Hex File Comparison') plt.show()