Created
January 17, 2015 14:49
-
-
Save anch0vy/9ecb51da34aed49ae427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import StringIO | |
import struct | |
from struct import pack | |
def make_packet(bf,ori): | |
len_ori=len(ori) | |
if len(ori)%8!=0: | |
ori=ori+'\x00'*(8-len(ori)%8) | |
encoded=bf.encode(ori) | |
len_enc=len(encoded) | |
header=pack('>II',len_enc,len_ori) | |
return header+encoded | |
def unpack(t,s): | |
ret=struct.unpack(t,s) | |
if len(ret)==1: | |
return ret[0] | |
else: | |
return ret | |
def unpack2(s): | |
return struct.unpack('>H',s)[0] | |
def unpack4(s): | |
return struct.unpack('>I',s)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment