Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: uni_sha256_generator.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script calculates SHA-256 hashes for all Unicode characters and saves them to a file.
- Functions:
- - sha256sum(string):
- Return the SHA-256 hash of a given string.
- - save_unicode_sha256(filename):
- Save SHA-256 hashes for all Unicode characters to a file.
- Requirements:
- - Python 3.x
- Usage:
- - Run the script to generate SHA-256 hashes for Unicode characters and save them to 'sum_uni_sha256.txt'.
- Additional Notes:
- - This script may take some time to complete, depending on the speed of the system.
- """
- import hashlib
- import unicodedata
- def sha256sum(string):
- """Return the SHA-256 hash of a given string."""
- return hashlib.sha256(string.encode('utf-8', errors='ignore')).hexdigest()
- def save_unicode_sha256(filename):
- """Save SHA-256 hashes for all Unicode characters to a file."""
- unicode_sha256_dict = {}
- print("Calculating SHA-256 hashes 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
- sha256_hash = sha256sum(character) # Calculate SHA-256 hash
- unicode_sha256_dict[name] = sha256_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, sha256_hash in sorted(unicode_sha256_dict.items()):
- outfile.write(f'"{name}": "{sha256_hash}",\n')
- print(f"\nSHA-256 hashes for Unicode characters saved to:", filename)
- if __name__ == "__main__":
- output_filename = 'sum_uni_sha256.txt'
- save_unicode_sha256(output_filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement