-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoderAndDecoder.py
More file actions
49 lines (42 loc) · 1.28 KB
/
EncoderAndDecoder.py
File metadata and controls
49 lines (42 loc) · 1.28 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
47
48
49
import os
import pickle
#This Encoding is done based on values from array saved in the pickle file.
pickle_in = open("datasets.pickle","rb")
this_array = pickle.load(pickle_in)
#The below function reverses the encoding procedure
def revertor(encod):
encod = str(encod)
numbers_in_2_groups=[]
def number_grouper_for_revertor(file):
for i in range(0,len(list(file))):
if(i%2 == 0):
item = list(file)[i]+list(file)[i+1]
numbers_in_2_groups.append(item)
return numbers_in_2_groups
number_grouper_for_revertor(encod)
final_reverted_item=[]
for i in numbers_in_2_groups:
for item in this_array:
if(item[1] == int(i)):
final_reverted_item.append(item[0])
final_reverted_item = ''.join(map(str,final_reverted_item))
return(final_reverted_item)
def convertor(filename):
final_array = []
for item in list(filename):
for index in this_array:
if(item == index[0]):
final_array.append(index[1])
concat_form = ''.join(map(str,final_array))
return concat_form
def convertor_test(filename):
counter=0
rename_overflow=False
if(len(filename)>120):
rename_overflow=True
for item in list(filename):
for index in this_array:
if(item == index[0]):
counter+=1
unknown_characters = len(list(filename))-counter
return unknown_characters,rename_overflow