Skip to content

Instantly share code, notes, and snippets.

@Suzhou65
Created February 19, 2021 09:32
Show Gist options
  • Save Suzhou65/31f8532a0f3c9a1b530291c4ef46954b to your computer and use it in GitHub Desktop.
Save Suzhou65/31f8532a0f3c9a1b530291c4ef46954b to your computer and use it in GitHub Desktop.
Translate string into 1337

Function

import json
def leet(string):
    #Reading leet dictionary
    try:
        with open("leet.json", "r") as leet_dictionary:
            leet_book = json.load(leet_dictionary)
    #If file not found
    except FileNotFoundError:
        print("leet dictionary not found !")
    #Split string
    temporarily = []
    temporarily[:] = string
    #Encode
    for index, data in enumerate(temporarily):
        for key, value in leet_book.items():
            if key in data:
                temporarily[index]=data.replace(key, leet_book[key])
    #Join again
    result_string = "".join(temporarily) 
    return result_string

Using

string = input("Enter Raw String: ")
output = leet(string)
#Result
print(f"{string} | {output}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment