Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: escape_sha256_generator.py
- # Version: 1.0.1
- # Author: Jeoi Reqi
- """
- Description:
- This script generates SHA-256 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",
- # "sha256_hash": "265fda17a34611b1533d8a281ff680dc5791b0ce0a11c25b35e11c8e75685509"
- # },
- # "\"": {
- # "meaning": "Double quote",
- # "sha256_hash": "8a331fdde7032f33a71e1b2e257d80166e348e00fcb17914f48bdb57a1c63007"
- # },
- # "\\": {
- # "meaning": "Backslash",
- # "sha256_hash": "a9253dc8529dd214e5f22397888e78d3390daa47593e26f68c18f97fd7a3876b"
- # },
- # "\n": {
- # "meaning": "Newline",
- # "sha256_hash": "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
- # },
- # "\r": {
- # "meaning": "Carriage Return",
- # "sha256_hash": "9d1e0e2d9459d06523ad13e28a4093c2316baafe7aec5b25f30eba2e113599c4"
- # },
- # "\t": {
- # "meaning": "Horizontal Tab",
- # "sha256_hash": "2b4c342f5433ebe591a1da77e013d1b72475562d48578dca8b84bac6651c3cb9"
- # },
- # "\b": {
- # "meaning": "Backspace",
- # "sha256_hash": "beead77994cf573341ec17b58bbf7eb34d2711c993c1d976b128b3188dc1829a"
- # },
- # "\f": {
- # "meaning": "Formfeed",
- # "sha256_hash": "ef6cbd2161eaea7943ce8693b9824d23d1793ffb1c0fca05b600d3899b44c977"
- # },
- # "\v": {
- # "meaning": "Vertical Tab",
- # "sha256_hash": "e7cf46a078fed4fafd0b5e3aff144802b853f8ae459a4f0c14add3314b7cc3a6"
- # }
- # }
- Additional Notes:
- - The script calculates SHA-256 hashes for each escape sequence listed in the ESCAPE_SEQUENCES dictionary.
- - The resulting SHA-256 hashes, along with their meanings, are saved to a file named 'sum_escape_sha256.txt'.
- - The output file is formatted in JSON for easy readability and parsing.
- """
- import hashlib
- def sha256sum(string):
- """Return the SHA-256 hash of a given string."""
- return hashlib.sha256(string.encode()).hexdigest()
- def generate_escape_sha256():
- """Generate SHA-256 hashes for various escape sequences."""
- escape_sha256_dict = {}
- for escape_sequence, meaning in ESCAPE_SEQUENCES.items():
- sha256_hash = sha256sum(escape_sequence)
- escape_sha256_dict[escape_sequence] = {
- "meaning": meaning,
- "sha256_hash": sha256_hash
- }
- return escape_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:
- outfile.write("{\n")
- for escape_sequence, data in sha256_dict.items():
- meaning = data["meaning"]
- sha256_hash = data["sha256_hash"]
- outfile.write(f' "{escape_sequence}": {{\n')
- outfile.write(f' "meaning": "{meaning}",\n')
- outfile.write(f' "sha256_hash": "{sha256_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_sha256.txt'
- escape_sha256_result = generate_escape_sha256()
- save_sha256_to_file(escape_sha256_result, output_filename)
- print("SHA-256 hashes for escape sequences saved to:", output_filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement