-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecorators.py
49 lines (41 loc) · 1.37 KB
/
decorators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def decorate(func):
def wrapper(plaintext):
print('='*len(func(plaintext)))
print(func(plaintext))
print('='*len(func(plaintext)))
return wrapper
def encrypt(func):
def wrapper(plaintext, encryption_key):
# plaintext = len(func(plaintext))
string = encryption_key.upper()
k = len(string)
j = 0
ciphertext = ''
for i in range(len(func(plaintext, encryption_key))):
if string[i%k].isdigit():
ciphertext += plaintext[i]
continue
key = (i - j) % k
if plaintext[i].isupper():
capital = ((ord(plaintext[i]) - ord('A')*2)+ ord(string[key])) % 26
c = chr(capital + ord('A'))
ciphertext += c
# print(ciphertext)
if plaintext[i].islower():
small = ((ord(plaintext[i]) - ord('a'))+ ord(string[key]) - ord('A')) % 26
c = chr(small + ord('a'))
ciphertext += c
# print(ciphertext)
if not plaintext[i].isalpha():
ciphertext += plaintext[i]
j += 1
return ciphertext
return wrapper
@encrypt
def hello(plaintext, encryption_key):
return plaintext
@decorate
def text(input_text):
return 20*input_text
print(hello("Hello World!", 'abc'))
print(text('500'))