Added cypher plugin by instanceoftom, removed duplicate plugin

This commit is contained in:
Luke Rogers 2012-02-17 12:58:16 +13:00
parent c0fb393b52
commit d5fd951a39
2 changed files with 78 additions and 38 deletions

78
plugins/cypher.py Normal file
View file

@ -0,0 +1,78 @@
'''
Plugin which (de)cyphers a string
Doesn't cypher non-alphanumeric strings yet.
by instanceoftom
'''
from util import hook
chars="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ "
len_chars = len(chars)
@hook.command
def cypher(inp):
".cypher <pass> <string> -- cyphers a string with the password"
passwd = inp.split(" ")[0]
len_passwd = len(passwd)
inp = " ".join(inp.split(" ")[1:])
out =""
passwd_index=0
for character in inp:
try:
chr_index = chars.index(character)
passwd_chr_index = chars.index(passwd[passwd_index])
out_chr_index = (chr_index + passwd_chr_index) % len_chars
out_chr = chars[out_chr_index]
out += out_chr
passwd_index = ( passwd_index + 1) % len_passwd
except ValueError:
out += character
continue
return out
@hook.command
def decypher(inp):
".decypher <pass> <string> -- decyphers a string with the password"
passwd = inp.split(" ")[0]
len_passwd = len(passwd)
inp = " ".join(inp.split(" ")[1:])
passwd_index=0
#I am lazy and I could do the math to get the passwd_index
#for this inp, but meh thats for a later day so lets loop.
for character in inp:
try:
chr_index = chars.index(character)
passwd_index = ( passwd_index + 1) % len_passwd
except ValueError:
continue
passwd_index = passwd_index-1
reversed_message = inp[::-1]
out =""
for character in reversed_message:
try:
chr_index = chars.index(character)
passwd_chr_index = chars.index(passwd[passwd_index])
out_chr_index = (chr_index - passwd_chr_index) % len_chars
out_chr = chars[out_chr_index]
out += out_chr
passwd_index = ( passwd_index - 1) % len_passwd
except ValueError:
out += character
continue
return out[::-1]

View file

@ -1,38 +0,0 @@
from util import hook
def find_location(ip, api):
import string
import urllib
response = urllib.urlopen("http://api.ipinfodb.com/v3/ip-city/?key="+api+"&ip="+ip).read()
response = response.split(";")
give = {}
give["country"] = response[4].title()
give["country_short"] = response[3].upper()
give["state"] = response[5].title()
give["city"] = response[6].title()
give["timezone"] = response[10].title()
return give
def timezone(ip):
time = find_location(ip)["timezone"]
time = time.replace(":",".")
time = time.replace(".00","")
return int(time)
@hook.command
def locations(inp, say = None, me = None, bot = None):
".location <ip> - Performs a GeoIP check on the ip given."
api = bot.config['api_keys']['geoip']
if api == "":
return "No API key"
give = find_location(inp, api)
if give["country"] not in [""," ","-"," - "]:
if give["state"] == give["city"]:
localstring = give["city"]
else:
localstring = give["city"] + ", " + give["state"]
say("That IP comes from " + give["country"] + " (" + give["country_short"] + ")")
say("I think it's in " + localstring + " with a timezone of " + give["timezone"] + "GMT")
else:
say("Either that wasn't an IP or I cannot locate it in my database. :(")
return