moar PEP8

This commit is contained in:
neersighted 2012-02-28 21:47:11 -08:00
parent 9f0bcbbac5
commit 715f926846
5 changed files with 69 additions and 66 deletions

View file

@ -1,78 +1,74 @@
'''
Plugin which (de)cyphers a string
Doesn't cypher non-alphanumeric strings yet.
by instanceoftom
'''
from util import hook
chars="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ "
chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ "
len_chars = len(chars)
@hook.command
def cypher(inp):
".cypher <pass> <string> -- Cyphers <string> with <password>."
".cypher <pass> <string> -- Cyphers <string> with <password>."
passwd = inp.split(" ")[0]
len_passwd = len(passwd)
inp = " ".join(inp.split(" ")[1:])
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 = ""
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_chr_index = (chr_index + passwd_chr_index) % len_chars
out_chr = chars[out_chr_index]
out += out_chr
out += out_chr
passwd_index = ( passwd_index + 1) % len_passwd
except ValueError:
out += character
continue
passwd_index = (passwd_index + 1) % len_passwd
except ValueError:
out += character
continue
return out
return out
@hook.command
def decypher(inp):
".decypher <pass> <string> -- Decyphers <string> with <password>."
".decypher <pass> <string> -- Decyphers <string> with <password>."
passwd = inp.split(" ")[0]
len_passwd = len(passwd)
inp = " ".join(inp.split(" ")[1:])
passwd = inp.split(" ")[0]
len_passwd = len(passwd)
inp = " ".join(inp.split(" ")[1:])
passwd_index = 0
for character in inp:
try:
chr_index = chars.index(character)
passwd_index = (passwd_index + 1) % len_passwd
except ValueError:
continue
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]
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 =""
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_chr_index = (chr_index - passwd_chr_index) % len_chars
out_chr = chars[out_chr_index]
out += out_chr
out += out_chr
passwd_index = (passwd_index - 1) % len_passwd
except ValueError:
out += character
continue
passwd_index = ( passwd_index - 1) % len_passwd
except ValueError:
out += character
continue
return out[::-1]
return out[::-1]