Advertisement
Python253

escape_sha512_generator

May 17th, 2024
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: escape_sha512_generator.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    This script generates SHA-512 hashes for various escape sequences in Python and saves them to a file.
  10.  
  11. Escape Sequences:
  12.    \': Single quote
  13.    \": Double quote
  14.    \\: Backslash
  15.    \n: Newline
  16.    \r: Carriage Return
  17.    \t: Horizontal Tab
  18.    \b: Backspace
  19.    \f: Formfeed
  20.    \v: Vertical Tab
  21.    \0: Null Character
  22.    \\N{Name}: Unicode character Database named lookup
  23.    \\xhh: Character with hex value hh
  24.  
  25. Requirements:
  26.    - Python 3.x
  27.  
  28. Usage:
  29.    To use this script, simply run it in a Python environment.
  30.    Ensure Python 3.x is installed on your system.
  31.  
  32. # Expected Results:
  33. # {
  34. #    "'": {
  35. #        "meaning": "Single quote",
  36. #        "sha512_hash": "f19d19eb36ae3d9c152e7878e7e5da81be5e26639f6f86f3c16c2f7a138bd04fb42c474bd8d0484484de1b4f6f9999671f3a1b65c1160a52ee9c8a05c60b216f"
  37. #    },
  38. #    "\"": {
  39. #        "meaning": "Double quote",
  40. #        "sha512_hash": "64b86773543b6e7a490a7d4cb67207217975ef84c6d3e0ad5b6867f4ebbe8338b6a0b8bb8cf4f8a1cf96b4769e1e9c3cc4c233a0eb585ee26a3d42a3e93c41fd"
  41. #    },
  42. #    "\\": {
  43. #        "meaning": "Backslash",
  44. #        "sha512_hash": "01527451233d83943f7600a0a3e5f734e064f063315eaf3d741875bc1c449c17c0586602e7f3c647c78a4c51cb99ef5752b0e2dfc56bcfd487d56bb0834e3a13"
  45. #    },
  46. #    "\n": {
  47. #        "meaning": "Newline",
  48. #        "sha512_hash": "cd0df0f58d46bc22a0ad4bb0c7992a82e4be2e0ab1f9a42a08e15919192f120f0093be6c80f64c2fb641b71e25f0a1dd2f518f4137bc9757f7cbe11419f29a48"
  49. #    },
  50. #    "\r": {
  51. #        "meaning": "Carriage Return",
  52. #        "sha512_hash": "b4e037ceee56db3a626103efef9b2b022631da5061e8a89c8f7d2566f4a8c1227e98fb23d04fde18b0cda93af4f18cc702f14cc4484dc8a44cb0de2cb3601c3"
  53. #    },
  54. #    "\t": {
  55. #        "meaning": "Horizontal Tab",
  56. #        "sha512_hash": "e7330b72b71bb762b88373c22b4f423bc59ad5d087d52592c02be94e49485376128d3a48199d48d6bc03be645d3c477d35abcc2fd7b8838be0f88c4a59e1f6e"
  57. #    },
  58. #    "\b": {
  59. #        "meaning": "Backspace",
  60. #        "sha512_hash": "e4b95e433f893e1cc372c0d9f09d1ee24b84cde09cc89b513ae3763f0a46e47027b1bb84e2c7dbde7f80845201c22a474a914d288b1c2d8a8b255ec68d1a625f"
  61. #    },
  62. #    "\f": {
  63. #        "meaning": "Formfeed",
  64. #        "sha512_hash": "a194a6a2eaf240ef68844aa84ac2cd73db0da0993c8e116aa9403943a23e1aae6a703118f50d5cf0e1024772177993cbf4dd21a70046b4337c6f75dcce19eb1a"
  65. #    },
  66. #    "\v": {
  67. #        "meaning": "Vertical Tab",
  68. #        "sha512_hash": "aa5d52a2d9798bc5b1d8d6a90d81f49a4d1ef67f8679c30b377eaee26d05406d0aa190e676b1c16a21af6c1d062ccf593c1aa5bc603d54e4f96244c2df5b53aa"
  69. #    }
  70. # }
  71.  
  72. Additional Notes:
  73.    - The script calculates SHA-512 hashes for each escape sequence listed in the ESCAPE_SEQUENCES dictionary.
  74.    - The resulting SHA-512 hashes, along with their meanings, are saved to a file named 'sum_escape_sha512.txt'.
  75.    - The output file is formatted in JSON for easy readability and parsing.
  76.  
  77. """
  78.  
  79. import hashlib
  80.  
  81. def sha512sum(string):
  82.     """Return the SHA-512 hash of a given string."""
  83.     return hashlib.sha512(string.encode()).hexdigest()
  84.  
  85. def generate_escape_sha512():
  86.     """Generate SHA-512 hashes for various escape sequences."""
  87.     escape_sha512_dict = {}
  88.     for escape_sequence, meaning in ESCAPE_SEQUENCES.items():
  89.         sha512_hash = sha512sum(escape_sequence)
  90.         escape_sha512_dict[escape_sequence] = {
  91.             "meaning": meaning,
  92.             "sha512_hash": sha512_hash
  93.         }
  94.     return escape_sha512_dict
  95.  
  96. def save_sha512_to_file(sha512_dict, filename):
  97.     """Save the SHA-512 dictionary to a file in JSON format."""
  98.     with open(filename, 'w', encoding='utf-8') as outfile:
  99.         outfile.write("{\n")
  100.         for escape_sequence, data in sha512_dict.items():
  101.             meaning = data["meaning"]
  102.             sha512_hash = data["sha512_hash"]
  103.             outfile.write(f'    "{escape_sequence}": {{\n')
  104.             outfile.write(f'        "meaning": "{meaning}",\n')
  105.             outfile.write(f'        "sha512_hash": "{sha512_hash}"\n')
  106.             outfile.write("    },\n")
  107.         outfile.write("}\n")
  108.  
  109. if __name__ == "__main__":
  110.     ESCAPE_SEQUENCES = {
  111.         "\'": "Single quote",
  112.         "\"": "Double quote",
  113.         "\\": "Backslash",
  114.         "\n": "Newline",
  115.         "\r": "Carriage Return",
  116.         "\t": "Horizontal Tab",
  117.         "\b": "Backspace",
  118.         "\f": "Formfeed",
  119.         "\v": "Vertical Tab",
  120.         "\0": "Null Character",
  121.         "\\N{Name}": "Unicode character Database named lookup",
  122.         "\\xhh": "Character with hex value hh"
  123.     }
  124.     output_filename = 'sum_escape_sha512.txt'
  125.     escape_sha512_result = generate_escape_sha512()
  126.     save_sha512_to_file(escape_sha512_result, output_filename)
  127.     print("SHA-512 hashes for escape sequences saved to:", output_filename)
  128.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement