Changed implementation of xor command to be cooler.

This commit is contained in:
Jeremy Fincher 2004-12-10 07:04:10 +00:00
parent c5e48d574f
commit c70007278c

View File

@ -43,7 +43,7 @@ import sha
import random import random
import inspect import inspect
import mimetypes import mimetypes
from itertools import imap from itertools import imap, cycle
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
@ -144,12 +144,10 @@ class Fun(callbacks.Privmsg):
http://www.yoe.org/developer/xor.html for information about XOR http://www.yoe.org/developer/xor.html for information about XOR
encryption. encryption.
""" """
passwordlen = len(password) chars = cycle(password)
i = 0
ret = [] ret = []
for c in text: for c in text:
ret.append(chr(ord(c) ^ ord(password[i]))) ret.append(chr(ord(c) ^ ord(chars.next())))
i = (i + 1) % passwordlen
irc.reply(''.join(ret)) irc.reply(''.join(ret))
xor = wrap(xor, ['something', 'text']) xor = wrap(xor, ['something', 'text'])