Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: decode_0bin_1bin_files.py
- # Author: Jeoi Reqi
- """
- This Python script decodes the contents of '0.bin' and '1.bin' files, saving the results as plain text in corresponding txt files.
- Requirements:
- - Python 3
- Description:
- The script takes two binary files, 0.bin and 1.bin, as input and decodes their contents into ASCII plaintext using UTF-8 encoding.
- The decoded text is then saved to two separate text files, decoded_0.txt and decoded_1.txt, respectively.
- The purpose of this script is to demonstrate the decoding process and verify the functionality of decoding binary files into human-readable text.
- Usage:
- Run the script using a Python 3 interpreter. Ensure that the 0.bin and 1.bin files are present in the same directory as the script.
- The decoded text will be saved in decoded_0.txt and decoded_1.txt.
- """
- import os
- def decode_binary_file(input_file, output_file):
- with open(input_file, 'rb') as binary_file:
- # Read binary data
- binary_data = binary_file.read()
- # Decode binary data into ASCII plaintext
- decoded_text = binary_data.decode('utf-8')
- # Write the decoded text to the output file
- with open(output_file, 'w') as plaintext_file:
- plaintext_file.write(decoded_text)
- if __name__ == "__main__":
- # Specify the input and output file names
- input_file_0 = '0.bin'
- output_file_0 = 'decoded_0.txt'
- input_file_1 = '1.bin'
- output_file_1 = 'decoded_1.txt'
- # Decode 0.bin
- decode_binary_file(input_file_0, output_file_0)
- print(f'{input_file_0} decoded and saved to {output_file_0}')
- # Decode 1.bin
- decode_binary_file(input_file_1, output_file_1)
- print(f'{input_file_1} decoded and saved to {output_file_1}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement