source: products/qPloneCaptchas/trunk/Crypto.py @ 2111

Last change on this file since 2111 was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 533 bytes
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 repository browser.