Created
February 28, 2014 13:20
-
-
Save blambi/9270982 to your computer and use it in GitHub Desktop.
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
# Blowfish cipher needs 8 byte blocks to work with | |
def __pad_file(self, file_buffer): | |
pad_bytes = 8 - (len(file_buffer) % 8) | |
for i in range(pad_bytes - 1): file_buffer += chr(randrange(0, 256)) | |
# final padding byte; % by 8 to get the number of padding bytes | |
bflag = randrange(6, 248); bflag -= bflag % 8 - pad_bytes | |
file_buffer += chr(bflag) | |
return file_buffer | |
def __depad_file(self, file_buffer): | |
pad_bytes = ord(file_buffer[-1]) % 8 | |
if not pad_bytes: pad_bytes = 8 | |
return file_buffer[:-pad_bytes] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment