Fun with Python: Elite Hacker Handle Generator
Introduction
It’s time for some more Fun with Python! This is a truly fun one that has 0 usefulness.
Have you ever wanted to be a L337 H@X0r?!
Well now you can be! With this handy-dandy Hacker Handle Generator™! (Disclaimer: This script will not grant you the ability to become an elite hacker, or make you cooler in a way, shape or form. Rules and regulations apply. No refunds.)
As always, this code is provided for educational purposes only and I make no guarantees or warranties. Use at your own risk. This code is released under the GNU GPL.
My instructions are for Windows and I assume some basic level of computer proficiency.
Preparation
None required this time. Copy/paste, run and have fun!
The Code
Copy and paste the code into Notepad and save it as “namegen.py”. Make sure to select All FIles in the drop-down for Save type as so that it saves a .py file. Save it anywhere.
import os
import random
replace_a = ["@","4","/-\\"]
replace_b = ["8","|3","13","ß"]
replace_c = ["(","<","[","©","¢"]
replace_d = ["|)","[>","|>","Ð"]
replace_e = ["3","€","£"]
replace_g = ["6","9","&"]
replace_h = ["#","|-|","[-]"]
replace_i = ["1","|","!"]
replace_l = ["|_","|","1","£"]
replace_o = ["0", "()", "Ø"]
replace_r = ["®"]
replace_s = ["5","$","§"]
replace_t = ["7","+","†"]
replace_y = ["¥"]
replace_z = ["2",">_"]
replaceable_letters = ["a","b","c","d","e","g","h","i","l","o","r","s","t","y","z"]
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
def replacer(letter):
variable_name = f"replace_{letter}"
letter_list = globals().get(variable_name, f"Variable replace_{letter} does not exist")
replacer_id = random.randint(0,len(letter_list))
if replacer_id == len(letter_list):
replacer_id -= 1
return(letter_list[replacer_id])
def menu():
clear()
print("^*^*^*^ Hacker Handle Generator ^*^*^*^")
print("| Input your name and press Enter! |")
print("=======================================")
while True:
name = ""
cmd = input("> ")
for l in cmd:
if l in replaceable_letters:
replaced_letter = replacer(l.lower())
name += replaced_letter
else:
name += l
print("Lame Name: " + cmd)
print("L337 Handle: " + name)
if __name__ == '__main__':
menu()
The Script in Action
You can run this script by double-clicking it. It contains a while loop that will keep it running in the Python interpreter window.
Alternatively, open a Command Prompt, navigate to its location and type the command:
python namegen.py
The menu will appear. Simply input a name and press Enter.
Conclusion
That’s it! A silly, simple script to replace letters in text and create “Hacker Handles”. The script is ugly, and I’ll probably play with it more to add functionality and reusability for other purposes. For example, I want to add a function that will reduce the level of name “leetness” so that it replaces fewer letters, and I can think of a few other ways this concept can be leveraged.
I’ll try to clean it up too, as I learn more efficient ways to approach tasks. For example, a helpful shorthand I discovered while building this is the ability to dynamically choose the global variable based on a standardized name format (Lines 25 and 26). My first attempt included a long match/case statement to match each letter with its global variable list which spanned around 40+ lines. Two lines is more elegant, and very useful.
Unfortunately, at the moment this scrip replaces one letter at a time, so it won’t actually change something like “Elite Hacker” to “L337 H@X0r” because that would require replacing letter combos. I’ll work on that in the next version.
Basically, it reads the entered name one letter at a time, validates the letter can be replaced, then replaces the letter with a random option from the appropriate global list variable.
As always, this code is provided for educational purposes only and I make no guarantees or warranties. Use at your own risk. This code is released under the GNU GPL.
Thanks for reading, and have fun.
Daily Cuppa
Today’s cup of tea is a lovely Organic Vanilla Rooibos provided by Equal Exchange. Organic, free trade, aromatic and cozy.
If you enjoyed creating your hacker handle, or the site in general, you can buy the author a cup of tea and show your appreciation. The author is also available for work.