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