-
Notifications
You must be signed in to change notification settings - Fork 0
/
encrypt.py
75 lines (56 loc) · 1.55 KB
/
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
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
def main():
ans = raw_input("Do you want to encrypt or decrypt. (e/d) ")
if ans == "e":
encode()
elif ans == "d":
decode()
# Encoding
def encode():
word = raw_input("Please enter the word you want to encrypt.")
#Find length of the word
length = len(word)
start = 0
a = 0
length
#Generate encrypted word
while start < length:
letter = word[start]
convert1 = start
start = convert1 +1
#Give encode_word a value if it is first run.
if a < 1:
encode_word = ""
convert2 = a +1
a = convert2
number = ord(letter)
alg = number + 2
encode_char = chr(alg)
convert4 = encode_word +encode_char
encode_word = convert4
print encode_word
raw_input("Press any key to exit")
def decode():
word = raw_input("Please enter the word you want to decrypt.")
#Find length of the word
length = len(word)
start = 0
a = 0
length
#Generate encrypted word
while start < length:
letter = word[start]
convert1 = start
start = convert1 +1
#Give encode_word a value if it is first run.
if a < 1:
encode_word = ""
convert2 = a +1
a = convert2
number = ord(letter)
alg = number - 2
encode_char = chr(alg)
convert4 = encode_word +encode_char
encode_word = convert4
print encode_word
raw_input("Press any key to exit")
main()