Last change
on this file since 1591 was
797,
checked in by chervol, 17 years ago
|
initial import
|
File size:
489 bytes
|
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 | def __normkey(self, s): |
---|
17 | self.__key = self.__key * (len(s) / len(self.__key)) |
---|
18 | |
---|
19 | def encrypt(self, s): |
---|
20 | self.__normkey(s) |
---|
21 | return self.__xor(s) |
---|
22 | |
---|
23 | decrypt = encrypt |
---|
Note: See
TracBrowser
for help on using the repository browser.