-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateDeCode.py
53 lines (41 loc) · 1.44 KB
/
DateDeCode.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
# Caleb's Decoding Program, Feb 14, 2016
import operator
#Date Pattern that we use to decode / encode, should be all numeric, any length
pattern = '09192016'
#either operator.add or operator.sub if you are going up or down in the alphabet
updown = operator.sub
#this can ether be clear text, to encode, or coded text to decode
string_in = """
Dnba Eamkb,
Spbjub os mprpg xklu. J qqpf eod fwlozkd xva xitot jom K
cbt't fbrv tp yen zxw ahgiw gxt Cixibuvcs. Uu hnmy mefv
ods wcmfy sndagt, J'rl lbun ypa Fjmlqn. Eu yxv tpox chju
hqus mrjomra xgnct oqr Dnrrtcoat?
Mhxtc (Reukr)
"""
#the rest of this stuff should just work
upper = range(65,90)
lower = range(97,122)
if updown is operator.sub : opposite = operator.add
else : opposite = operator.sub
string_out = ''
pattern_position = 0
for c in string_in:
if c.isalpha():
if c.isupper() :
n_out = updown(ord(c), int(pattern[pattern_position]))
if n_out in upper : c_out = chr(n_out)
else: c_out = chr(opposite(n_out, 26))
if c.islower():
n_out = updown(ord(c), int(pattern[pattern_position]))
if n_out in lower : c_out = chr(n_out)
else: c_out = chr(opposite(n_out, 26))
#append our character to the string out
string_out += c_out
#check to see if we are at the end of the pattern
pattern_position += 1
if pattern_position == len(pattern): pattern_position = 0
else:
#we had a non alphabet character, so we just copy it over unchanged
string_out += c
print string_out