Skip to content

Instantly share code, notes, and snippets.

@jason-s13r
Created April 30, 2013 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jason-s13r/5486455 to your computer and use it in GitHub Desktop.
Save jason-s13r/5486455 to your computer and use it in GitHub Desktop.
# vim: noai:ts=4:sw=4:expandtab:syntax=python
import re
from xbotpp.modules import Module
class lolcrypt(Module):
"""\
Provide lolcryption.
"""
def __init__(self):
Module.__init__(self)
def action(self, bot, event, args, buf):
"""\
Lolcrypt the given arguments, or the buffer (if present)
Pass "-d" as the first parameter to de-lolcrypt.
"""
if len(args) is 0 and buf == "":
return "%slolcrypt [-d] <text> or %scommand | lolcrypt [-d]" % (self.bot.prefix, self.bot.prefix)
delol = (len(args) != 0 and args[0] == "-d")
cipher = list("aeioubcdfghjklmnpqrstvwxyz")
text = buf if buf != "" else " ".join(args[1:]) if delol else " ".join(args[0:])
mod = lambda a, n: ((a%n)+n)%n
buf = ""
for char in text:
caps = re.match("[A-Z]", char)
char = char.lower()
if not char in cipher:
buf += char.upper() if caps else char
continue
i = cipher.index(char)
if re.match("[" + "".join(cipher[0:5]) + "]", char):
if delol:
char = cipher[mod(i-2,5)]
else:
char = cipher[(i+2)%5]
else:
if delol:
char = cipher[mod(i-15,21)+5]
else:
char = cipher[(i+5)%21+5]
buf += char.upper() if caps else char
return buf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment