]> git.somenet.org - pub/jan/scripts.git/blob - hax/someencode.py
added ingress adb helpers.
[pub/jan/scripts.git] / hax / someencode.py
1 #!/usr/bin/env python
2
3 import sys
4 import os
5 import signal
6 import csv
7 import binascii
8
9
10 def someencode(infilename, strfilename, outfilename):
11   with open(infilename, 'r') as infile:
12     infilestr=infile.read()
13   with open(strfilename, 'r') as strfile:
14     strfilestr=strfile.read().strip()
15
16   bitstrstr = "".join(["{0:08b}".format(ord(i)) for i in strfilestr ])
17
18 #  print (infilestr)
19   print (bitstrstr)
20
21   retstr = ""
22   bit = 0
23
24   for c in infilestr:
25     if bit >= len(bitstrstr):
26       retstr = retstr + c
27     elif c not in "abcdefghinjklmnopqrstuvwxyz":
28       retstr = retstr + c
29     elif bitstrstr[bit] == "1":
30       retstr = retstr + chr(ord(c)-32)
31       bit += 1
32     else:
33       retstr = retstr + c
34       bit += 1
35
36   if bit < len(bitstrstr):
37     print("SOME PAYLOAD NOT ENCODED!")
38   open(outfilename, 'w').write(retstr)
39
40
41 if __name__ == "__main__":
42         def signal_handler(signal, frame):
43                 print('SIG received. exitting!')
44                 sys.exit(0)
45         signal.signal(signal.SIGINT, signal_handler)
46
47         someencode("in.txt", "str.txt", "out.txt")
48