-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path19_manual_password_encoder_decoder.py
More file actions
78 lines (64 loc) · 2.22 KB
/
19_manual_password_encoder_decoder.py
File metadata and controls
78 lines (64 loc) · 2.22 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import string
vowels = ['a', 'e', 'i', 'o', 'u']
v_char = ['#', '$', '%', '&', '*']
alpha_char = string.ascii_lowercase
reversed_alpha_char = alpha_char[::-1]
alpha_char_u = string.ascii_uppercase
spec_char = string.punctuation
digits = string.digits
def encode(enc: str):
encrypt = []
for s in enc:
if s in vowels:
encrypt.append(v_char[vowels.index(s)])
elif s in spec_char:
encrypt.append("|" + s)
elif s in alpha_char + alpha_char_u:
encrypt.append(s.swapcase())
elif s in digits:
encrypt.append("^" + reversed_alpha_char[digits.index(s)])
elif s in spec_char:
encrypt.append("^" + s)
return "".join(encrypt)
word = input("kindly input the word you want to encrypt ")
print(encode(word))
def decode(decr: str):
decrypt = []
dec = list(decr)
for item in range(0, len(dec)):
if dec[item] in v_char:
decrypt.append(vowels[v_char.index(dec[item])])
elif dec[item] == '^':
decrypt.append(reversed_alpha_char.index(dec[item + 1]))
# decrypt.append(digits(reverse_alpha_char.index(dec[item + 1])))
# dec.remove(dec[item])
elif dec[item] == "|":
decrypt.append(dec[item + 1])
# dec.remove(dec[item])
elif dec[item] in alpha_char_u + alpha_char:
decrypt.append(dec[item].swapcase())
return "".join(decrypt)
word = input("kindly input the word you want to decrypt ")
print(decode(word))
# def decoded(decr: str):
# decrypt = []
#
# for x in decr:
# if x in v_char:
# decrypt.append(vowels[v_char.index(x)])
# elif x == '^':
# decrypt.append(reversed_alpha_char.index[(x)+ 1])
# # decrypt.append(digits(reverse_alpha_char.index(x + 1)))
# x.pop((x) + 1)
# elif x == "|":
# decrypt.append (decr.index[(x) + 1])
# x.pop((x) + 1)
# elif x in alpha_char_u + alpha_char:
# decrypt.append (x.swapcase())
#
# return "".join(decrypt)
#
#
# word = input("kindly input the word you want to decrypt ")
#
# print(decoded(word))