Advertisement
nucular

NOLC (Not Only Leet Converter) 1.0.1.1

Mar 5th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.97 KB | None | 0 0
  1. # SAVE THIS WITH UTF-8 ENCODING!
  2.  
  3. #!/usr/bin/env python
  4. """NOLC (Not Only Leet Converter) 1.0.1.1
  5. by nucular
  6.  
  7. Converts text to many types of fun languages such as Leet, Leet2, Greek, Upside down, Morse, Messed Words
  8. The rules are from leetspeaker.js on http://www.2cu.at/leetspeaker
  9.  
  10. For examples and testing, get NOLCtest from
  11.     http://www.pastebin.com/SOMETHING
  12.  
  13.  
  14. Something > Readable Text isn't possible yet. Sorry.
  15. Also, I had to remove all the examples from this documentation because
  16. our lovely pydoc can't read unicode chars.
  17.  
  18. CHANGES:
  19.  - No more unicode warnings... Now does everything with the u!
  20.  TO 1.0.1:
  21.     - Added tostr() helper function because i wanted to do.
  22.     - Renamed z() to z_ui()
  23.  TO 1.0.1.1 (lol):
  24.     - now uses dot instead of middledot in morse function
  25.  
  26.  
  27. Copyright (C) 2013 by nucular
  28. This program is free software: you can redistribute it and/or modify
  29. it under the terms of the GNU General Public License Version 3 as published by
  30. the Free Software Foundation.
  31.  
  32. This program is distributed in the hope that it will be useful,
  33. but WITHOUT ANY WARRANTY; without even the implied warranty of
  34. MERCHANIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  35. GNU General Public License for more details.
  36.  
  37. You should have received a copy of the GNU General Public License
  38. along with this program. If not, see <http://www.gnu.org/licenses/>
  39. """
  40.  
  41. # USAGE
  42. # nolc.leet(<text>)     Returns unicode             ex. "Leet" > "1337"
  43. # nolc.leet2(<text>)    Returns unicode             ex. "Leet" > "£ēē†"
  44. # nolc.greek(<text>)    Returns unicode             ex. "Greek" > "Gяεεκ"
  45. # nolc.flip(<text>)     Returns unicode             ex. "Flip" > "dılɟ"
  46. # nolc.updown(<text>)   Returns str or unicode*     ex. "Updown" > "UpDoWn"
  47. # nolc.morse(<text>)    Returns str                 ex. "Morse" > "-- --- .-. ... . "
  48. # nolc.mess(<text>)     Returns str or unicode*     ex. "Mess this" > "Mses tihs"
  49. # *Depends on input
  50.  
  51.  
  52. import random
  53. random.seed()
  54.  
  55. __version__ = "1.0.1"
  56.  
  57. 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"]
  58.  
  59. 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"]
  60.  
  61. valid_leet = lower + [u"ä", u"ö", u"ü", u"ß", u" "]
  62. valid_leet2 = lower + upper + [u"ä", u"ö", u"ü", u"Ä", u"Ö", u"Ü", u"ß", u" "]
  63. valid_greek = valid_leet2
  64. valid_flip = lower + [u"ä", u"ö", u"ü", u"ß"] + upper + [u"Ä", u"Ö", u"Ü", u".", u",", u"?", u"!", u";", u"_", u"\"", u" "]
  65. 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" "]
  66.  
  67. 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" "]
  68. 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"β", " "]
  69. 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"ß", " "]
  70. 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" "]
  71. 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"  "]
  72.  
  73.  
  74. def reverse(text):
  75.     """Little helper function, reverses some text in unicode."""
  76.     text_array = []
  77.     for i in text:
  78.         text_array.append(i)
  79.     text_array.reverse()
  80.     return u"".join(text_array)
  81.  
  82. def leet(text):
  83.     """Input: str/unicode
  84.     Output: unicode
  85.         Converts <text> to Leet."""
  86.     text = unicode(text)
  87.     ret = u""
  88.     text = text.lower()
  89.     for i in text:
  90.         try:
  91.             pos = valid_leet.index(i)
  92.             ret = ret + in_leet[pos]
  93.         except:
  94.             ret = ret + i
  95.     return ret
  96.  
  97. def leet2(text):
  98.     """Input: str/unicode
  99.     Output: unicode
  100.         Converts <text> to Leet2."""
  101.     text = unicode(text)
  102.     ret = u""
  103.     for i in text:
  104.         try:
  105.             pos = valid_leet2.index(i)
  106.             ret = ret + in_leet2[pos]
  107.         except:
  108.             ret = ret + i
  109.     return ret
  110.  
  111. def greek(text):
  112.     """Input: str/unicode
  113.     Output: unicode
  114.         Converts <text> to Greek."""
  115.     text = unicode(text)
  116.     ret = u""
  117.     for i in text:
  118.         try:
  119.             pos = valid_greek.index(i)
  120.             ret = ret + in_greek[pos]
  121.         except:
  122.             ret = ret + i
  123.     return ret
  124.  
  125. def flip(text):
  126.     """Input: str/unicode
  127.     Output: unicode
  128.         Flips <text> upside-down."""
  129.     text = unicode(text)
  130.     ret = u""
  131.     text = text.lower()
  132.     for i in text:
  133.         try:
  134.             pos = valid_flip.index(i)
  135.             ret = ret + in_flip[pos]
  136.         except:
  137.             ret = ret + i
  138.     ret = reverse(ret)
  139.     return ret
  140.  
  141. def updown(text):
  142.     """Input: str/unicode
  143.     Output: same
  144.         Returns <text> camel-cased like "UpDoWn"."""
  145.     ret = ""
  146.     uod = 1
  147.     for i in text:
  148.         if uod == 0:
  149.             ret = ret + i.lower()
  150.             uod = 1
  151.         else:
  152.             ret = ret + i.upper()
  153.             uod = 0
  154.     return ret
  155.  
  156. def morse(text):
  157.     """Input: str/unicode
  158.     Output: unicode
  159.         Converts <text> to morsecode."""
  160.     ret = ""
  161.     text = text.upper()
  162.     for i in text:
  163.         try:
  164.             pos = valid_morse.index(i)
  165.             ret = ret + in_morse[pos]
  166.         except:
  167.             ret = ret + i
  168.     return ret
  169.  
  170. def mess_word(text):
  171.     """Input: str/unicode
  172.     Output: same
  173.         Jumbles all mid chars of <text>."""
  174.     midchars = list(text)[1:len(text)-1]
  175.     midchars_ret = ""
  176.     while midchars != []:
  177.         rand = random.randrange(len(midchars))
  178.         midchars_ret = midchars_ret + midchars[rand]
  179.         del midchars[rand]
  180.     return text[0:1] + midchars_ret + text[len(text)-1]
  181.  
  182. def mess(text):
  183.     """Input: str/unicode
  184.     Output: same
  185.         Jumbles all mid chars of every word of <text>."""
  186.     if text == "" or len(text) < 3:
  187.         return text
  188.     lines = text.split("\n")
  189.     lines_ret = []
  190.     for text2 in lines:
  191.         words = text2.split(" ")
  192.         words_messed = []
  193.         for i in words:
  194.             words_messed.append(mess_word(i))
  195.         lines_ret.append(" ".join(words_messed))
  196.     return "\n".join(lines_ret)
  197.  
  198. def tostr(text, replace_char = "?"):
  199.     """Input: something parsable by str()
  200.     Output: string
  201.         Helper, converts <text> to string data type without ugly error messages.
  202.         Replaces unicode chars etc by <replace_char>"""
  203.     ret = ""
  204.     for i in text:
  205.         try:
  206.             ret = ret + str(i)
  207.         except:
  208.             ret = ret + replace_char
  209.     return ret
  210.  
  211. def z_ui():
  212.     print "NOLC (Not Only Leet Converter) " + __version__
  213.     print "by nucular"
  214.     print "-"*50
  215.     print "To try the functionality of NOLC, get NOLCtest from http://www.pastebin.com/6BegCWqY"
  216.     a = raw_input(">")
  217. if __name__ == '__main__':
  218.     z_ui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement