Wednesday, May 11, 2011

My Latest Leet Program

Just for fun today I did an update of an EnglishToLeetSpeak translator I had written a couple years ago.  I noticed that when I posted my update, my post count was almost ironic.  :-)

For a sample of how it works, look at this paragraph from my previous post:


Spent some time today installing a barebones (ie. no desktop) version of Ubuntu on an old Acer Aspire One netbook.  Feels weird to refer to it as old, as it was only a few years ago....


S|>en† So]V[e †!]V[e †o])ay !nS†aLL!nG a (3aRe(3oneS (!e. no ])eS|<†o|>) veRS!on of µ(3µn†µ on an oL]) aceR aS|>!Re one ne†(3oo|<.  feeLS UUe!R]) †o RefeR †o !† aS oL]), aS !† UUaS onLy a feUU yeaRS aGo....

Here's the code: 

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# an experiment in python to produce a good leet encoder
# that does not use a one-to-one mapping
# mFragin May 2011
# version 1.5 maps first and then substitutes, so
# each example is internally letter consistant

import random, string

myDefinitions = [["4","@","/-\\","∂","λ","a","A"],
["|<","k","K"], ["1","|","|_","l","L"], ["|v|","]V[","(T)","|\\/|","/\\/\\","m","M"], ["|\\|","]\\[","~","n","N"], ["0","[]","¤","Ω","o","O"], ["|o","|>","p","P"],
["%","><","}{","x","X"], ["Ψ","¥","y","Y"], ["2","z","Z"]] myKeys = string.ascii_lowercase # Make a dictionary of the keys and values myDict =dict(zip(myKeys, myDefinitions)) # Get a string from user and make it lower case stringToConvert = raw_input("\nEnter a string: ").lower() leetString = "" variations = int(raw_input("\nHow many variations? ")) for i in range(variations): leetString = "" chosenLetters = {} for letter in stringToConvert: if letter in chosenLetters: leetString += chosenLetters[letter] elif letter in string.ascii_lowercase: choice = random.choice(myDict[letter]) leetString += choice chosenLetters[letter] = choice else: leetString += letter print leetString

No comments:

Post a Comment