source: products/quintagroup.captcha.core/trunk/quintagroup/captcha/core/Crypto.py @ 3128

Last change on this file since 3128 was 3128, checked in by vmaksymiv, 13 years ago

pep8 fixes

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