-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.py
42 lines (29 loc) · 772 Bytes
/
encrypt.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
'''
Example:
("abcdefghij", 1) -> "bdfhjacegi"
("abcdefghij", 2) -> "bdfhjacegi" -> "dhaeibfjcg"
'''
def encrypt(text: str, n: int):
if text == '':
return text
if text is None:
return text
if (n == '') or (int(n) <= 0):
return text
raw_string = text
arr_len = len(raw_string)
arr_of_even = []
arr_of_uneven = []
n = int(n)
for elem in range(arr_len):
if elem % 2 == 0:
arr_of_even.append(raw_string[elem])
else:
arr_of_uneven.append(raw_string[elem])
result = ''.join(arr_of_uneven + arr_of_even)
if n > 1:
return encrypt(result, n - 1)
return result
text = input('Type your message: ')
n = input('Type n param: ')
print(encrypt(text, n))