File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1+ # create a random letter cypher for a string
2+ import random
3+
4+ def make_dash (string ):
5+ out_string = ''
6+ for char in string :
7+ if char != ' ' :
8+ out_string += '-'
9+ else :
10+ out_string += char
11+ return out_string
12+
13+ def make_new_key ():
14+ new_alpha = []
15+ alphabet = list ('abcdefghijklmnopqrstuvwxyz' )
16+ alpha_save = alphabet [:]
17+ while alphabet :
18+ pick = random .choice (alphabet )
19+ new_alpha .append (pick )
20+ index = alphabet .index (pick )
21+ alphabet .pop (index )
22+ return dict (zip (alpha_save , new_alpha ))
23+
24+ def scramble (string , mapper ):
25+ out_string = ''
26+ for char in string :
27+ if char != ' ' :
28+ out_string += mapper [char ]
29+ else :
30+ out_string += char
31+ return out_string
32+
33+ sentence = "the quick brown fox jumps over the lazy dog"
34+ new_key = make_new_key ()
35+ print (make_dash (sentence ))
36+ print (scramble (sentence , new_key ))
Original file line number Diff line number Diff line change 1-
21"""A tiny Python program to check that Python is working.
32Try running this program from the command line like this:
43 python hello.py
You can’t perform that action at this time.
0 commit comments