-
Notifications
You must be signed in to change notification settings - Fork 0
/
ct_io.py
62 lines (45 loc) · 1.54 KB
/
ct_io.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
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 16 22:55:23 2018
@author: Panangam
b"""
charlist = 'abcdefghijklmnopqrstuvwxyz. 1234'
def readProjectTwoCTFile(filename):
ct_list = []
ct_list_temp = []
with open(filename) as fin:
for line in fin:
if len(line) > 2 and line[1] == '.':
if len(ct_list_temp) > 0:
ct_list.append(ct_list_temp)
ct_list_temp = []
elif line[0] == '0' or line[0] == '1':
ct_raw = line
ct_raw_list = ct_raw.split(' ')
ct_raw_list = [c.strip() for c in ct_raw_list if c.strip() != '']
ct_list_temp += ([int(c, 2) for c in ct_raw_list])
if len(ct_list_temp) > 0:
ct_list.append(ct_list_temp)
return ct_list
def decode_es(ct):
return ''.join([c_decode_es(ctchar) for ctchar in ct])
def encode_es(pt):
return [c_encode_es(character) for character in pt]
def c_decode_es(ct_c):
return charlist[ct_c]
def c_encode_es(pt_c):
return charlist.find(pt_c)
ct_list = readProjectTwoCTFile('ct1.txt')
ct1 = ct_list[0]
ct2 = ct_list[1]
ct3 = ct_list[2]
ct4 = ct_list[3]
if __name__ == '__main__':
ct_list = readProjectTwoCTFile('ct1.txt')
print(len(ct_list), 'ct')
for ct in ct_list:
print('length:', len(ct))
for ct in ct_list:
print(ct)
print(decode_es(ct_list[2]))
print(encode_es('overnight'))