I have been working on testing whether same encrypted files are same without decrypting it. I have a test file provided to me one with normal data and another encrypted version of it. I need to check whether that test file(without encryption) which goes through an api and encrypts it will be the same as encrypted file that I got. Here, is the python script for checking these files:
def compare_binaries(self,f1, f2):
'''
Using ittertools zip_longest to check each lines of both files
f1 - binary file of source file
f2- binary file of target file
Returns True if all lines are same else False if any line is not same
'''
for line1, line2 in zip_longest(f1, f2, fillvalue=None):
if line1 == line2:
continue
else:
return False
return True
Is this process okay for checking the encrypted files are same or are there better alternatives for it?
'\n'
,'\r'
, and'\r\n'
to just'\n'
. Depending on your threat model, this may be an exploitable loophole.cmp
compares binary files for exact byte-for-byte equality without any shenanigans like "lines".