Advertisement
Python253

ascii_sha512_generator

May 17th, 2024
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: ascii_sha512_generator.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script calculates SHA-512 hashes for every ASCII character and saves them to a file.
  10.  
  11. Functions:
  12.    - sha512sum(string):
  13.        Return the SHA-512 hash of a given string.
  14.    - calculate_ascii_sha512():
  15.        Calculate SHA-512 hashes for every ASCII character.
  16.    - save_sha512_to_file(sha512_dict, filename):
  17.        Save the SHA-512 dictionary to a file in JSON format.
  18.  
  19. Requirements:
  20.    - Python 3.x
  21.  
  22. Usage:
  23.    - Run the script to generate SHA-512 hashes for ASCII characters and save them to 'sum_ascii_sha512.txt'.
  24.  
  25. Additional Notes:
  26.    - This script may take some time to complete, depending on the speed of the system.
  27. """
  28.  
  29. import hashlib
  30. import json
  31.  
  32. def sha512sum(string):
  33.     """Return the SHA-512 hash of a given string."""
  34.     return hashlib.sha512(string.encode()).hexdigest()
  35.  
  36. def calculate_ascii_sha512():
  37.     """Calculate SHA-512 hashes for every ASCII character."""
  38.     ascii_sha512_dict = {}
  39.     print("Calculating SHA-512 hashes for ASCII characters. This may take some time...")
  40.     for i in range(128):  # ASCII range
  41.         char = chr(i)
  42.         sha512_hash = sha512sum(char)
  43.         ascii_sha512_dict[char] = sha512_hash
  44.     return ascii_sha512_dict
  45.  
  46. def save_sha512_to_file(sha512_dict, filename):
  47.     """Save the SHA-512 dictionary to a file in JSON format."""
  48.     with open(filename, 'w', encoding='utf-8') as outfile:
  49.         json.dump(sha512_dict, outfile, indent=4)
  50.  
  51. if __name__ == "__main__":
  52.     filename = 'sum_ascii_sha512.txt'
  53.     ascii_sha512_dict = calculate_ascii_sha512()
  54.     save_sha512_to_file(ascii_sha512_dict, filename)
  55.     print("\nSHA-512 hashes for ASCII characters saved to:", filename)
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement