-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypher.py
More file actions
46 lines (39 loc) · 1.02 KB
/
Copy pathcypher.py
File metadata and controls
46 lines (39 loc) · 1.02 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 2 18:15:36 2020
@author: clarekirkland
"""
import string
alphabet = string.ascii_lowercase
# Decypher the user's cyper by mapping to the alphabet
def decypher(code):
graph = []
count = 1
for i in code:
if (i.isalpha()):
i = i.lower()
if (i not in graph):
graph.append(i)
else:
graph.append(str(count))
count = (count + 1)%10
return graph
# Decode the encoded text based on the map
def decode(encoded,c_map):
ans = ""
for i in encoded:
if (i.isalpha()):
i = i.lower()
if (i in c_map):
ans += alphabet[c_map.index(i)]
else:
ans += ' '
return ans
# Get and translate cypher
code = str(input("What is the encryption code? "))
c_map = decypher((code.replace(' ','')).lower())
# Loop over the user's encoded text
while (True):
res = input("What do you want to decode? ")
print(decode(res, c_map))