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