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