0% found this document useful (0 votes)
19 views1 page

Hex

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Hex

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import binascii

def decode_and_save(file_path, save_path=r"C:\inboxrules_decoded.txt"):


try:
with open(file_path, 'rb') as file:
encoded_data = file.read()
decoded_data = binascii.unhexlify(encoded_data)
decoded_text = decoded_data.decode('utf-8', errors='ignore')
with open(save_path, 'w', encoding='utf-8') as outfile:
outfile.write(decoded_text)
print(f"Decoded data saved to {save_path}")
except Exception as e:
print(f"An error occurred during decoding: {e}")

def encode_and_save(new_file_path, original_encoded_file_path):


try:
with open(new_file_path, 'r', encoding='utf-8') as file:
decoded_text = file.read()
encoded_data = binascii.hexlify(decoded_text.encode('utf-8'))
with open(original_encoded_file_path, 'wb') as outfile:
outfile.write(encoded_data)
print(f"Encoded data saved to {original_encoded_file_path}")
except Exception as e:
print(f"An error occurred during encoding: {e}")

def main():
file_path = input("Enter the path of the file to decode (default:
inboxrules.txt): ") or "inboxrules.txt"
while True:
print("\nMenu Options:")
print("1 - Decode file and save as inboxrules_decoded.txt in C:\\")
print("2 - Encode modified file and save with same coding as
inboxrules.txt")
print("3 - Exit")
choice = input("Choose an option (1, 2, or 3): ")

if choice == '1':
decode_and_save(file_path)
elif choice == '2':
new_file_path = input("Enter the path of the modified decoded file: ")
encode_and_save(new_file_path, file_path)
elif choice == '3':
print("Exiting...")
break
else:
print("Invalid choice. Please choose 1, 2, or 3.")

if __name__ == "__main__":
main()

You might also like