Advertisement
Python253

uni_sha512_generator

May 17th, 2024
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: uni_sha512_generator.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script calculates SHA-512 hashes for all Unicode characters and saves them to a file.
  10.  
  11. Functions:
  12.    - sha512sum(string):
  13.        Return the SHA-512 hash of a given string.
  14.    - save_unicode_sha512(filename):
  15.        Save SHA-512 hashes for all Unicode characters to a file.
  16.  
  17. Requirements:
  18.    - Python 3.x
  19.  
  20. Usage:
  21.    - Run the script to generate SHA-512 hashes for Unicode characters and save them to 'sum_uni_sha512.txt'.
  22.  
  23. Additional Notes:
  24.    - This script may take some time to complete, depending on the speed of the system.
  25. """
  26.  
  27. import hashlib
  28. import unicodedata
  29.  
  30. def sha512sum(string):
  31.     """Return the SHA-512 hash of a given string."""
  32.     return hashlib.sha512(string.encode('utf-8', errors='ignore')).hexdigest()
  33.  
  34. def save_unicode_sha512(filename):
  35.     """Save SHA-512 hashes for all Unicode characters to a file."""
  36.     unicode_sha512_dict = {}
  37.     print("Calculating SHA-512 hashes for Unicode characters. This may take some time...")
  38.     # Iterate over all Unicode characters
  39.     for code_point in range(0x110000):
  40.         character = chr(code_point)  # Get Unicode character
  41.         name = unicodedata.name(character, f"<{code_point:04X}>")  # Get character name
  42.         sha512_hash = sha512sum(character)  # Calculate SHA-512 hash
  43.         unicode_sha512_dict[name] = sha512_hash  # Store in dictionary
  44.  
  45.     # Write the dictionary to the output file with JSON-like formatting
  46.     with open(filename, 'w', encoding='utf-8') as outfile:
  47.         for name, sha512_hash in sorted(unicode_sha512_dict.items()):
  48.             outfile.write(f'"{name}": "{sha512_hash}",\n')
  49.  
  50.     print("SHA-512 hashes for Unicode characters saved to:", filename)
  51.  
  52. if __name__ == "__main__":
  53.     output_filename = 'sum_uni_sha512.txt'
  54.     save_unicode_sha512(output_filename)
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement