-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncrypting.py
More file actions
52 lines (41 loc) · 968 Bytes
/
Encrypting.py
File metadata and controls
52 lines (41 loc) · 968 Bytes
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
import math
word = input('Phrase to be encrypted: ')
word = word.lower()
wl = []
space = 32
period = 27
comma = 28
question = 29
exclamation = 30
for letter in word:
if letter == ' ':
wl.append(space)
elif letter == '.':
wl.append(period)
elif letter == ',':
wl.append(comma)
elif letter == '?':
wl.append(question)
elif letter == '!':
wl.append(exclamation)
else:
wl.append(ord(letter) - 96)
print('Phrase input to numbers: ', *wl)
encrypt_list_short = []
encrypt_list_long = []
p = 3
q = 11
e = 3
n = p * q
def encrypt(me):
global encrypt_list_long
en = math.pow(me, e)
c = en % n
c = int(c)
encrypt_list_short.append("%02d" % c)
encrypt_list_long = [' '.join(encrypt_list_short)]
return c
# run function on int list
for item in wl:
c = encrypt(item)
print('Encrypted phrase: ', *encrypt_list_long)