Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: ascii_sha512_generator.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script calculates SHA-512 hashes for every ASCII character and saves them to a file.
- Functions:
- - sha512sum(string):
- Return the SHA-512 hash of a given string.
- - calculate_ascii_sha512():
- Calculate SHA-512 hashes for every ASCII character.
- - save_sha512_to_file(sha512_dict, filename):
- Save the SHA-512 dictionary to a file in JSON format.
- Requirements:
- - Python 3.x
- Usage:
- - Run the script to generate SHA-512 hashes for ASCII characters and save them to 'sum_ascii_sha512.txt'.
- Additional Notes:
- - This script may take some time to complete, depending on the speed of the system.
- """
- import hashlib
- import json
- def sha512sum(string):
- """Return the SHA-512 hash of a given string."""
- return hashlib.sha512(string.encode()).hexdigest()
- def calculate_ascii_sha512():
- """Calculate SHA-512 hashes for every ASCII character."""
- ascii_sha512_dict = {}
- print("Calculating SHA-512 hashes for ASCII characters. This may take some time...")
- for i in range(128): # ASCII range
- char = chr(i)
- sha512_hash = sha512sum(char)
- ascii_sha512_dict[char] = sha512_hash
- return ascii_sha512_dict
- def save_sha512_to_file(sha512_dict, filename):
- """Save the SHA-512 dictionary to a file in JSON format."""
- with open(filename, 'w', encoding='utf-8') as outfile:
- json.dump(sha512_dict, outfile, indent=4)
- if __name__ == "__main__":
- filename = 'sum_ascii_sha512.txt'
- ascii_sha512_dict = calculate_ascii_sha512()
- save_sha512_to_file(ascii_sha512_dict, filename)
- print("\nSHA-512 hashes for ASCII characters saved to:", filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement