Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: uni_md5_generator.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script calculates MD5 sums for all Unicode characters and saves them to a file.
- Functions:
- - md5sum(string):
- Return the MD5 sum of a given string.
- - save_unicode_md5(filename):
- Save MD5 sums for all Unicode characters to a file.
- Requirements:
- - Python 3.x
- Usage:
- - Run the script to generate MD5 sums for Unicode characters and save them to 'sum_uni.txt'.
- Additional Notes:
- - This script may take some time to complete, depending on the speed of the system.
- """
- import hashlib
- import unicodedata
- def md5sum(string):
- """Return the MD5 sum of a given string."""
- return hashlib.md5(string.encode('utf-8', errors='ignore')).hexdigest()
- def save_unicode_md5(filename):
- """Save MD5 sums for all Unicode characters to a file."""
- unicode_md5_dict = {}
- print("Calculating MD5 sums for Unicode characters. This may take some time...")
- # Iterate over all Unicode characters
- for code_point in range(0x110000):
- character = chr(code_point) # Get Unicode character
- name = unicodedata.name(character, f"<{code_point:04X}>") # Get character name
- md5_hash = md5sum(character) # Calculate MD5 sum
- unicode_md5_dict[name] = md5_hash # Store in dictionary
- # Write the dictionary to the output file with JSON-like formatting
- with open(filename, 'w', encoding='utf-8') as outfile:
- for name, md5_hash in sorted(unicode_md5_dict.items()):
- outfile.write(f'"{name}": "{md5_hash}",\n')
- print(f"\nMD5 sums for Unicode characters saved to:", filename)
- if __name__ == "__main__":
- output_filename = 'sum_uni.txt'
- save_unicode_md5(output_filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement