root/qPloneCaptchas/trunk/Crypto.py

Revision 470, 0.5 KB (checked in by crchemist, 4 years ago)

Added pycrypto and xor crypt engine.

  • Property svn:eol-style set to native
Line 
1# xor implementation with PyCrypto interface
2
3def new(key):
4    return Xor(key)
5
6class Xor:
7    def __init__(self, key):
8        self.__key = key
9       
10    def __xor(self, s):
11        res = ''
12        for i in range(len(s)):
13            res += chr(ord(s[i]) ^ ord(self.__key[i]))
14        return res
15           
16       
17    def __normkey(self, s):
18        self.__key = self.__key * (len(s) / len(self.__key))
19       
20    def encrypt(self, s):
21        self.__normkey(s)
22        return self.__xor(s)
23       
24    decrypt = encrypt
Note: See TracBrowser for help on using the browser.