Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

'.join([chr((ord(flag[i]) << 8) + ord(flag[i + 1])) for i in range(0, len(flag), 2)])

#!/usr/bin/python3
 
def unpack(encoded_flag):
    flag = ""
    for packed_char in encoded_flag:
        start_int = ord(packed_char) #get the integer value of the packed unicode character
        highChar = ord(packed_char)>>8  #bit shift the integer 8 bits to the right, which in essence divides by 256
        flag += chr(highChar)
        lowChar = start_int - (highChar<<8) #difference between sum of 2 packed characters, and the first character multiplied by 256 or <<8
        lowChar = ord(packed_char)%256 #or you could simply use the modulus operator to get the remainder, which will be the lower char
        # explanation for retrieving lowChar.  If you multiple a number by 256 
        # and then add another number that is less than 256, 
        # the number added will always be the remainder when dividing the 
        # sum of those two numbers by 256.
        flag += chr(lowChar)
    print(flag)
 
def pack(flag):
    if(len(flag)%2):  #must be divisible by 2 since two chars are packed into a single char during encoding
        flag+=" "     #add blank space for padding
    encoded_flag = ''.join([chr((ord(flag[i]) << 8) + ord(flag[i + 1])) for i in range(0, len(flag), 2)])
    print(encoded_flag)
    return encoded_flag
 
 
flag = "This is the text that will be packed"
enc = pack(flag)
unpack(enc)
Comment

PREVIOUS NEXT
Code Example
Python :: cv2.cvtcolor grayscale 
Python :: python pandas save df to xlsx file 
Python :: install fastapi conda 
Python :: play video in google colab 
Python :: jupyter notebook reload module 
Python :: python beep windows 
Python :: python print traceback from exception 
Python :: show full pd dataframe 
Python :: download playlist from youtube python 
Python :: python actualizar pip 
Python :: get stats from list python 
Python :: how to automatically copy an output to clipboard in python 
Python :: matplotlib.pyplot imshow size 
Python :: how to simulate a key press in python 
Python :: split data validation 
Python :: import kfold 
Python :: get text from txt file python 
Python :: convert list of strings to ints python 
Python :: read multiple csv python 
Python :: Extract images from html page based on src attribute using beatutiful soup 
Python :: save plot python 
Python :: how to fillna in all columns with their mean values 
Python :: make a list from 0 to n python 
Python :: save request response json to file python 
Python :: ERROR: Failed building wheel for Pillow 
Python :: translate sentences in python 
Python :: drop rows that contain null values in a pandas dataframe 
Python :: os.system return value 
Python :: pandas convert all column names to lowercase 
Python :: numpy for data science 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =