-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncrypter.py
61 lines (53 loc) · 2.02 KB
/
Encrypter.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
50
51
52
53
54
55
56
57
58
59
60
61
def encrypt(original_word, modifier, *mod_modifier):
if not mod_modifier:
mod_modifier = 0
else:
mod_modifier = sum(mod_modifier)
if modifier < 0:
negative = -1
else:
negative = 1
# list setup
#alphabet = [chr(char) for char in range(ord("a"), ord("z") + 1)]
#digits = [chr(num) for num in range(ord('0'), ord('9') + 1)]
ascii_characters = [chr(char) for char in range(128)]
alphabet = ascii_characters
digits = ascii_characters
# encrypter
encrypted_word = ""
for char in original_word:
if char.lower() in alphabet:
index_num = alphabet.index(char.lower())
while (index_num + modifier) * negative >= len(alphabet):
index_num -= len(alphabet) * negative
x_char = alphabet[(index_num + modifier) * negative]
if char.isupper():
x_char = x_char.upper()
elif char in digits:
index_num = digits.index(char.lower())
while index_num + modifier >= len(digits):
index_num -= len(digits)
x_char = digits[index_num + modifier]
else:
x_char = char
encrypted_word = encrypted_word + x_char
modifier += mod_modifier
return encrypted_word
original_word = input("What message do you want to encrypt?\n")
while True:
modifier = input("How many characters up or down do you want to change it by?\n")
if modifier.replace("-", "").isdigit():
modifier = int(modifier)
break
else:
print("\033[F\033[K", end="")
print("\033[F\033[K", end="")
while True:
mod_modifier = input("How many numbers do you want to change the modifier by after each encryption?\n")
if mod_modifier.replace("-", "").isdigit():
mod_modifier = int(mod_modifier)
break
else:
print("\033[F\033[K", end="")
print("\033[F\033[K", end="")
print(encrypt(original_word, modifier, mod_modifier))