forked from Dadsaster/python_class
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcryptogram.py
More file actions
36 lines (32 loc) · 916 Bytes
/
cryptogram.py
File metadata and controls
36 lines (32 loc) · 916 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
# create a random letter cypher for a string
import random
def make_dash(string):
out_string = ''
for char in string:
if char != ' ':
out_string += '-'
else:
out_string += char
return out_string
def make_new_key():
new_alpha = []
alphabet = list('abcdefghijklmnopqrstuvwxyz')
alpha_save = alphabet[:]
while alphabet:
pick = random.choice(alphabet)
new_alpha.append(pick)
index = alphabet.index(pick)
alphabet.pop(index)
return dict(zip(alpha_save, new_alpha))
def scramble(string, mapper):
out_string = ''
for char in string:
if char != ' ':
out_string += mapper[char]
else:
out_string += char
return out_string
sentence = "the quick brown fox jumps over the lazy dog"
new_key = make_new_key()
print(make_dash(sentence))
print(scramble(sentence, new_key))