root/qPloneCaptchas/tags/1.2.3/Crypto.py

Revision 470 (checked in by crchemist, 2 years ago)

Added pycrypto and xor crypt engine.

  • Property svn:eol-style set to native
Line 
1 # xor implementation with PyCrypto interface
2
3 def new(key):
4     return Xor(key)
5
6 class 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.