Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SAVE THIS WITH UTF-8 ENCODING!
- #!/usr/bin/env python
- """NOLC (Not Only Leet Converter) 1.0.1.1
- by nucular
- Converts text to many types of fun languages such as Leet, Leet2, Greek, Upside down, Morse, Messed Words
- The rules are from leetspeaker.js on http://www.2cu.at/leetspeaker
- For examples and testing, get NOLCtest from
- http://www.pastebin.com/SOMETHING
- Something > Readable Text isn't possible yet. Sorry.
- Also, I had to remove all the examples from this documentation because
- our lovely pydoc can't read unicode chars.
- CHANGES:
- - No more unicode warnings... Now does everything with the u!
- TO 1.0.1:
- - Added tostr() helper function because i wanted to do.
- - Renamed z() to z_ui()
- TO 1.0.1.1 (lol):
- - now uses dot instead of middledot in morse function
- Copyright (C) 2013 by nucular
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License Version 3 as published by
- the Free Software Foundation.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>
- """
- # USAGE
- # nolc.leet(<text>) Returns unicode ex. "Leet" > "1337"
- # nolc.leet2(<text>) Returns unicode ex. "Leet" > "£ēē†"
- # nolc.greek(<text>) Returns unicode ex. "Greek" > "Gяεεκ"
- # nolc.flip(<text>) Returns unicode ex. "Flip" > "dılɟ"
- # nolc.updown(<text>) Returns str or unicode* ex. "Updown" > "UpDoWn"
- # nolc.morse(<text>) Returns str ex. "Morse" > "-- --- .-. ... . "
- # nolc.mess(<text>) Returns str or unicode* ex. "Mess this" > "Mses tihs"
- # *Depends on input
- import random
- random.seed()
- __version__ = "1.0.1"
- lower = [u"a",u"b",u"c",u"d",u"e",u"f",u"g",u"h",u"i",u"j",u"k",u"l",u"m",u"n",u"o",u"p",u"q",u"r",u"s",u"t",u"u",u"v",u"w",u"x",u"y",u"z"]
- upper = [u"A",u"B",u"C",u"D",u"E",u"F",u"G",u"H",u"I",u"J",u"K",u"L",u"M",u"N",u"O",u"P",u"Q",u"R",u"S",u"T",u"U",u"V",u"W",u"X",u"Y",u"Z"]
- valid_leet = lower + [u"ä", u"ö", u"ü", u"ß", u" "]
- valid_leet2 = lower + upper + [u"ä", u"ö", u"ü", u"Ä", u"Ö", u"Ü", u"ß", u" "]
- valid_greek = valid_leet2
- valid_flip = lower + [u"ä", u"ö", u"ü", u"ß"] + upper + [u"Ä", u"Ö", u"Ü", u".", u",", u"?", u"!", u";", u"_", u"\"", u" "]
- valid_morse = upper + [u"0", u"1", u"2", u"3", u"4", u"5", u"6", u"7", u"8", u"9", u"À", u"Ä", u"È", u"É", u"Ö", u"Ü", u"ß", u"Ñ", u".", u",", u":", u";", u"?", u"!", u"-", u"_", u"(", u")", u"'", u"„", u"“", u"\"", u"=", u"+", u"/", u"@", u" "]
- in_leet = [u"4", u"8", u"(", u"Ð", u"3", u"ƒ", u"6", u"|-|", u"!", u"j", u"|<", u"1", u"/\\/\\", u"|\\|", u"0", u"p", u"q", u"2", u"5", u"7", u"|_|", u"\\/", u"\\/\\/", u")(", u"9", u"2", u"ä", u"ö", u"ü", u"55", u" "]
- in_leet2 = [u"ã", u"b", u"¢", u"đ", u"ē", u"ƒ", u"ģ", u"ħ", u"ï", u"ĵ", u"ķ", u"ł", u"м", u"ñ", u"º", u"ρ", u"φ", u"ŕ", u"ş", u"†", u"μ", u"ν", u"ω", u"×", u"ÿ", u"ż", u"Д", u"β", u"©", u"Ð", u"€", u"F", u"Ģ", u"Ħ", u"|", u"Ĵ", u"Ķ", u"£", u"Μ", u"Ñ", u"0", u"Ρ", u"Ω", u"®", u"$", u"Ţ", u"Ū", u"V", u"Ŵ", u"Χ", u"¥", u"Ż", u"ǽ", u"ǿ", u"ů", u"Æ", u"Ø", u"Ů", u"β", " "]
- in_greek = [u"α", u"β", u"c", u"δ", u"ε", u"ƒ", u"g", u"н", u"i", u"j", u"κ", u"ℓ", u"м", u"η", u"ο", u"ρ", u"φ", u"я", u"s", u"τ", u"μ", u"ν", u"ω", u"χ", u"y", u"z", u"Λ", u"Β", u"C", u"Δ", u"Σ", u"F", u"G", u"H", u"І", u"Ј", u"Κ", u"L", u"Μ", u"Π", u"Θ", u"Ρ", u"Ω", u"Я", u"Ѕ", u"Τ", u"U", u"V", u"ш", u"Ж", u"Ψ", u"Z", u"ά", u"ό", u"ύ", u"Ä", u"Ö", u"Ü", u"ß", " "]
- in_flip = [u"ɐ", u"q", u"ɔ", u"p", u"ǝ", u"ɟ", u"ƃ", u"ɥ", u"ı", u"ɾ", u"ʞ", u"l", u"ɯ", u"u", u"o", u"b", u"b", u"ɹ", u"s", u"ʇ", u"n", u"ʌ", u"ʍ", u"x", u"ʎ", u"z", u"ɐ", u"q", u"ɔ", u"p", u"ǝ", u"ɟ", u"ƃ", u"H", u"I", u"ɾ", u"ʞ", u"l", u"W", u"N", u"O", u"d", u"b", u"ɹ", u"S", u"ʇ", u"n", u"Λ", u"M", u"X", u"ʎ", u"Z", u"ɐ", u"ǝ", u"O", u"ǝ", u"n", u"ǝ", u"˙", u"'", u"¿", u"¡", u"؛", u"‾", u"\\", u"ss", u" "]
- in_morse = [u".- ", u"-... ", u"-.-. ", u"-.. ", u". ", u"..-. ", u"--. ", u".... ", u".. ", u".--- ", u"-.- ", u".-.. ", u"-- ", u"-. ", u"--- ", u".--. ", u"--.- ", u".-. ", u"... ", u"- ", u"..- ", u"...- ", u".-- ", u"-..- ", u"-.-- ", u"--.. ", u"----- ", u".---- ", u"..--- ", u"...-- ", u"....- ", u"..... ", u"-.... ", u"--... ", u"---.. ", u"----. ", u".--.- ", u".-.- ", u".-..- ", u"..-.. ", u"---. ", u"..-- ", u"...--.. ", u"--.-- ", u".-.-.- ", u"--..-- ", u"---... ", u"-.-.-. ", u"..--.. ", u".-.-.- ", u"-....- ", u"..--.- ", u"-.--. ", u"-.--.- ", u".----. ", u".-..-. ", u".-..-. ", u".-..-. ", u"-...- ", u".-.-. ", u"-..-. ", u".--.-. ", u" "]
- def reverse(text):
- """Little helper function, reverses some text in unicode."""
- text_array = []
- for i in text:
- text_array.append(i)
- text_array.reverse()
- return u"".join(text_array)
- def leet(text):
- """Input: str/unicode
- Output: unicode
- Converts <text> to Leet."""
- text = unicode(text)
- ret = u""
- text = text.lower()
- for i in text:
- try:
- pos = valid_leet.index(i)
- ret = ret + in_leet[pos]
- except:
- ret = ret + i
- return ret
- def leet2(text):
- """Input: str/unicode
- Output: unicode
- Converts <text> to Leet2."""
- text = unicode(text)
- ret = u""
- for i in text:
- try:
- pos = valid_leet2.index(i)
- ret = ret + in_leet2[pos]
- except:
- ret = ret + i
- return ret
- def greek(text):
- """Input: str/unicode
- Output: unicode
- Converts <text> to Greek."""
- text = unicode(text)
- ret = u""
- for i in text:
- try:
- pos = valid_greek.index(i)
- ret = ret + in_greek[pos]
- except:
- ret = ret + i
- return ret
- def flip(text):
- """Input: str/unicode
- Output: unicode
- Flips <text> upside-down."""
- text = unicode(text)
- ret = u""
- text = text.lower()
- for i in text:
- try:
- pos = valid_flip.index(i)
- ret = ret + in_flip[pos]
- except:
- ret = ret + i
- ret = reverse(ret)
- return ret
- def updown(text):
- """Input: str/unicode
- Output: same
- Returns <text> camel-cased like "UpDoWn"."""
- ret = ""
- uod = 1
- for i in text:
- if uod == 0:
- ret = ret + i.lower()
- uod = 1
- else:
- ret = ret + i.upper()
- uod = 0
- return ret
- def morse(text):
- """Input: str/unicode
- Output: unicode
- Converts <text> to morsecode."""
- ret = ""
- text = text.upper()
- for i in text:
- try:
- pos = valid_morse.index(i)
- ret = ret + in_morse[pos]
- except:
- ret = ret + i
- return ret
- def mess_word(text):
- """Input: str/unicode
- Output: same
- Jumbles all mid chars of <text>."""
- midchars = list(text)[1:len(text)-1]
- midchars_ret = ""
- while midchars != []:
- rand = random.randrange(len(midchars))
- midchars_ret = midchars_ret + midchars[rand]
- del midchars[rand]
- return text[0:1] + midchars_ret + text[len(text)-1]
- def mess(text):
- """Input: str/unicode
- Output: same
- Jumbles all mid chars of every word of <text>."""
- if text == "" or len(text) < 3:
- return text
- lines = text.split("\n")
- lines_ret = []
- for text2 in lines:
- words = text2.split(" ")
- words_messed = []
- for i in words:
- words_messed.append(mess_word(i))
- lines_ret.append(" ".join(words_messed))
- return "\n".join(lines_ret)
- def tostr(text, replace_char = "?"):
- """Input: something parsable by str()
- Output: string
- Helper, converts <text> to string data type without ugly error messages.
- Replaces unicode chars etc by <replace_char>"""
- ret = ""
- for i in text:
- try:
- ret = ret + str(i)
- except:
- ret = ret + replace_char
- return ret
- def z_ui():
- print "NOLC (Not Only Leet Converter) " + __version__
- print "by nucular"
- print "-"*50
- print "To try the functionality of NOLC, get NOLCtest from http://www.pastebin.com/6BegCWqY"
- a = raw_input(">")
- if __name__ == '__main__':
- z_ui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement