I used to be growing a program to transform the content material of a binary file to readable ACII. That is my code:
import struct
import base64
import codecs
import re
print("************Welcome to binary dumper and binary to ASCII decoder************")
print("Please solely select BINARY CONTENT information as a result of in any other case an error will ocurr")
filename_ext = enter("Enter filname to be dumped and decoded: ")
print("n")
filename = enter("Please enter the filename WITHOUT the extention: ")
print("n")
print("Printing binary information...")
print("n")
f = open(filename_ext, 'rb')
content material = f.learn()
f.shut()
print(content material)
contenttoconvert = enter("Please copy the content material that was output earlier than and paste it right here: ")
resubedcontent = re.sub("b|'", "", contenttoconvert)
padding = "=========".encode('utf-8')
base64_file_bytes = str(content material).encode('utf-8')
a_binary_string = int(resubedcontent, 2)
binary_values = a_binary_string.break up()
#Break up string on whitespace
ascii_string = ""
for binary_value in binary_values:
an_integer = float(binary_value)
#Convert to base 2 decimal integer
ascii_character = chr(an_integer)
#Convert to ASCII character
ascii_string += ascii_character
#Append character to `ascii_string`
print(ascii_string)
with open("output_" + filename, 'wb')as output:
print("n")
print("Outputing file...")
print("n")
decoded_file_data = base64.decodebytes(base64_file_bytes + padding)
output.write(codecs.encode(decoded_file_data, 'hex_codec'))
The content material of the file i learn is that this: 01010000 01010101 01010100 01000001
so i simply take away the b of binary and the added semi quotes but it surely retains saying the identical. Hope i used to be clear.