Skip to content

Commit 3b5cf4f

Browse files
committed
Added encrypt and decrypt decorators.
1 parent 95723f2 commit 3b5cf4f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/string.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
3+
import re
4+
5+
from Crypto import Random
6+
from Crypto.Cipher import AES
7+
8+
class string(object):
9+
10+
encrypted_text = '\0'
11+
__KEY__ = Random.new().read(32)
12+
__IV__ = Random.new().read(16)
13+
14+
@classmethod
15+
def encrypt(cls,func):
16+
def wrapper(*arguments):
17+
if not re.match('<__main__.*object at.*>',str(arguments[0])):
18+
raise SyntaxError('Method must be an instance method of a class!')
19+
for string in arguments[1:]:
20+
key = AES.new(
21+
cls.__KEY__,
22+
AES.MODE_CFB,
23+
cls.__IV__
24+
)
25+
cls.encrypted_text = key.encrypt(string)
26+
return func(arguments[0].__class__,cls.encrypted_text)
27+
return wrapper
28+
29+
@classmethod
30+
def decrypt(cls,func):
31+
def wrapper(*arguments):
32+
if not re.match('<__main__.*object at.*>',str(arguments[0])):
33+
raise SyntaxError('Method must be an instance method of a class!')
34+
for string in arguments[1:]:
35+
key = AES.new(
36+
cls.__KEY__,
37+
AES.MODE_CFB,
38+
cls.__IV__
39+
)
40+
cls.encrypted_text = key.decrypt(string)
41+
return func(arguments[0].__class__,cls.encrypted_text)
42+
return wrapper

0 commit comments

Comments
 (0)