Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: escape_sha512_generator.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script generates SHA-512 hashes for various escape sequences in Python and saves them to a file.
- Escape Sequences:
- \': Single quote
- \": Double quote
- \\: Backslash
- \n: Newline
- \r: Carriage Return
- \t: Horizontal Tab
- \b: Backspace
- \f: Formfeed
- \v: Vertical Tab
- \0: Null Character
- \\N{Name}: Unicode character Database named lookup
- \\xhh: Character with hex value hh
- Requirements:
- - Python 3.x
- Usage:
- To use this script, simply run it in a Python environment.
- Ensure Python 3.x is installed on your system.
- # Expected Results:
- # {
- # "'": {
- # "meaning": "Single quote",
- # "sha512_hash": "f19d19eb36ae3d9c152e7878e7e5da81be5e26639f6f86f3c16c2f7a138bd04fb42c474bd8d0484484de1b4f6f9999671f3a1b65c1160a52ee9c8a05c60b216f"
- # },
- # "\"": {
- # "meaning": "Double quote",
- # "sha512_hash": "64b86773543b6e7a490a7d4cb67207217975ef84c6d3e0ad5b6867f4ebbe8338b6a0b8bb8cf4f8a1cf96b4769e1e9c3cc4c233a0eb585ee26a3d42a3e93c41fd"
- # },
- # "\\": {
- # "meaning": "Backslash",
- # "sha512_hash": "01527451233d83943f7600a0a3e5f734e064f063315eaf3d741875bc1c449c17c0586602e7f3c647c78a4c51cb99ef5752b0e2dfc56bcfd487d56bb0834e3a13"
- # },
- # "\n": {
- # "meaning": "Newline",
- # "sha512_hash": "cd0df0f58d46bc22a0ad4bb0c7992a82e4be2e0ab1f9a42a08e15919192f120f0093be6c80f64c2fb641b71e25f0a1dd2f518f4137bc9757f7cbe11419f29a48"
- # },
- # "\r": {
- # "meaning": "Carriage Return",
- # "sha512_hash": "b4e037ceee56db3a626103efef9b2b022631da5061e8a89c8f7d2566f4a8c1227e98fb23d04fde18b0cda93af4f18cc702f14cc4484dc8a44cb0de2cb3601c3"
- # },
- # "\t": {
- # "meaning": "Horizontal Tab",
- # "sha512_hash": "e7330b72b71bb762b88373c22b4f423bc59ad5d087d52592c02be94e49485376128d3a48199d48d6bc03be645d3c477d35abcc2fd7b8838be0f88c4a59e1f6e"
- # },
- # "\b": {
- # "meaning": "Backspace",
- # "sha512_hash": "e4b95e433f893e1cc372c0d9f09d1ee24b84cde09cc89b513ae3763f0a46e47027b1bb84e2c7dbde7f80845201c22a474a914d288b1c2d8a8b255ec68d1a625f"
- # },
- # "\f": {
- # "meaning": "Formfeed",
- # "sha512_hash": "a194a6a2eaf240ef68844aa84ac2cd73db0da0993c8e116aa9403943a23e1aae6a703118f50d5cf0e1024772177993cbf4dd21a70046b4337c6f75dcce19eb1a"
- # },
- # "\v": {
- # "meaning": "Vertical Tab",
- # "sha512_hash": "aa5d52a2d9798bc5b1d8d6a90d81f49a4d1ef67f8679c30b377eaee26d05406d0aa190e676b1c16a21af6c1d062ccf593c1aa5bc603d54e4f96244c2df5b53aa"
- # }
- # }
- Additional Notes:
- - The script calculates SHA-512 hashes for each escape sequence listed in the ESCAPE_SEQUENCES dictionary.
- - The resulting SHA-512 hashes, along with their meanings, are saved to a file named 'sum_escape_sha512.txt'.
- - The output file is formatted in JSON for easy readability and parsing.
- """
- import hashlib
- def sha512sum(string):
- """Return the SHA-512 hash of a given string."""
- return hashlib.sha512(string.encode()).hexdigest()
- def generate_escape_sha512():
- """Generate SHA-512 hashes for various escape sequences."""
- escape_sha512_dict = {}
- for escape_sequence, meaning in ESCAPE_SEQUENCES.items():
- sha512_hash = sha512sum(escape_sequence)
- escape_sha512_dict[escape_sequence] = {
- "meaning": meaning,
- "sha512_hash": sha512_hash
- }
- return escape_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:
- outfile.write("{\n")
- for escape_sequence, data in sha512_dict.items():
- meaning = data["meaning"]
- sha512_hash = data["sha512_hash"]
- outfile.write(f' "{escape_sequence}": {{\n')
- outfile.write(f' "meaning": "{meaning}",\n')
- outfile.write(f' "sha512_hash": "{sha512_hash}"\n')
- outfile.write(" },\n")
- outfile.write("}\n")
- if __name__ == "__main__":
- ESCAPE_SEQUENCES = {
- "\'": "Single quote",
- "\"": "Double quote",
- "\\": "Backslash",
- "\n": "Newline",
- "\r": "Carriage Return",
- "\t": "Horizontal Tab",
- "\b": "Backspace",
- "\f": "Formfeed",
- "\v": "Vertical Tab",
- "\0": "Null Character",
- "\\N{Name}": "Unicode character Database named lookup",
- "\\xhh": "Character with hex value hh"
- }
- output_filename = 'sum_escape_sha512.txt'
- escape_sha512_result = generate_escape_sha512()
- save_sha512_to_file(escape_sha512_result, output_filename)
- print("SHA-512 hashes for escape sequences saved to:", output_filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement