From d6bdf3ab38f3361173787db44d998ed46c341e33 Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Wed, 4 Sep 2013 20:13:45 +0800 Subject: [PATCH] Possible fix for non alphanumeric characters, needs testing. --- plugins/cypher.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/plugins/cypher.py b/plugins/cypher.py index 7ef72ce..1c4d7d6 100755 --- a/plugins/cypher.py +++ b/plugins/cypher.py @@ -2,11 +2,10 @@ Plugin which (de)cyphers a string Doesn't cypher non-alphanumeric strings yet. by instanceoftom +All character cyphering added - TheNoodle """ from util import hook -chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ " -len_chars = len(chars) @hook.command @@ -20,19 +19,15 @@ def cypher(inp): out = "" passwd_index = 0 for character in inp: - try: - chr_index = chars.index(character) - passwd_chr_index = chars.index(passwd[passwd_index]) + chr_index = ord(character) + passwd_chr_index = ord(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) % 255 + out_chr = chr[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 return out @@ -46,11 +41,7 @@ def decypher(inp): 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 = (passwd_index + 1) % len_passwd passwd_index -= 1 reversed_message = inp[::-1] @@ -58,10 +49,10 @@ def decypher(inp): out = "" for character in reversed_message: try: - chr_index = chars.index(character) - passwd_chr_index = chars.index(passwd[passwd_index]) + chr_index = ord(character) + passwd_chr_index = ord(passwd[passwd_index]) - out_chr_index = (chr_index - passwd_chr_index) % len_chars + out_chr_index = (chr_index - passwd_chr_index) % 255 out_chr = chars[out_chr_index] out += out_chr