Encode and decode Files using python (Binhex)














































Encode and decode Files using python (Binhex)



Binhex module encode and decodes files in following binhex4 format . The following format is used in the representation Macintosh files in ASCII . Only the data fork is handled 
The binhex module define the following function:

binhex.binhex(input, output): Convert a binary file with filename input to binhex file output. The output parameter can either be a filename or a file-like object (any object supporting a write() and close() method).

binhex.hexbin(input, output): Decode a binhex file input. input may be a filename or a file-like object supporting read() and close() methods. The resulting file is written to a file named output unless the argument is None in which case the output filename is read from the binhex file

The following exception is also defined :

excpetion binhex.error: Exception is raised whenever something cant be encoded using binhex format for example the file name is too long to fit in filename field or when input is not properly encodes in binhex format 

import binhex
import sys
infile = "file.txt"
binhex.binhex(infile, 'test.hqx')

The following file needs to converted with Binhex 4.0

:#'CTE'8ZG(Kd!&4&@&3rN!3!N!8G!*!%Ql&6D@e`E'8JDA-JBQ9dG'9b)(4SB@i
JBfpYF'aPH-bk!!!:

To convert Hex into Binary

import binhex
import sys
infile = "test.hqx"
binhex.binhex(infile, 'test.txt')



Comments

  • Akshit
    29-Jun-2021 12:51:41 PM
    Also Sir about the UI of this website, I don't really like it much. Please tell CPP Secrets about my feedback.
    Thank you!
  • Akshit
    29-Jun-2021 12:49:18 PM

    Sir I loved you content, keep up the good work. I hope you become a professor some day <3