Exemplo n.º 1
0
 def flush(self):
     for char in self.plaintext.upper():
         try:
             self.compressed.extend(self.series.find_char(char))
         except Exception:
             self.compressed.extend(self.series.find_char("?"))
     binary_out=density.version+"|"+self.series.name+"|"+self.token+"!"
     i=0
     
     if not len(self.compressed)-1 % 2 == 0: self.compressed.extend(self.series.find_char(" "))
     
     while i != len(self.compressed)-1:
         try:
             s3=util.expand_bin(bin(self.compressed[i+1]))
             s2=util.expand_bin(bin(self.compressed[i]))
             s1=int(s2+s3, 2)
             binary_out += chr(s1)
         except Exception:
             import traceback
             traceback.print_stack()
             traceback.print_exc()
             sys.exit(1)
         i += 2
     f=open(self.path, 'wb')
     for char in binary_out:
         f.write(char)
     f.close()
Exemplo n.º 2
0
 def __init__(self, path, series):
     self.series=series
     self.marker=0
     self.path=path
     f=open(path, 'rb')
     compressed=""
     for i in f.readlines(): compressed += i
     l=compressed
     l=l.split("!")[0]
     l=l.split("|")
     if not l[0] == density.version: warnings.warn("Version Mismatch While Reading Density File!")
     if not l[1] == series.name: warnings.warn("Series Name Mismatch While Reading Denisty File!")
     self.token=l[2]
     parts=[]
     
     compressed=compressed.split("!", 1)[1]
     
     for char in compressed:
         b=util.expand_bin(bin(ord(char)).replace("0b", ""), 8)
         p1=int(b[:4],2)
         p2=int(b[4:],2)
         parts.extend([p1,p2])
     self.plaintext=series.decompress_segment(parts)