def lsbExtract(q):
    post, filename = q.get()
    rgb_data = libstegofile.rgb_data_t()
    png_struct = libstegofile.png_internal_data_t()
    para = libstegofile.lsb_parameter_t()
    para.password = str(post["pw"])
    para.pwlen = len(para.password)
    para.select_mode = 2
    para.use_msb = 0
    stegomsg = libstego.new_charp()
    stegolen = libstego.new_intp()
    retcode = libstegofile.io_png_read(filename, rgb_data, png_struct)
    if retcode == 0:
        pass
    else:
        return -1
    bytes = libstego.new_charpp()
    num_bytes = libstego.new_intp()
    libstego.lsb_convert_png(rgb_data, bytes, num_bytes)

    libstego.lsb_extract_indirect(
        libstego.charpp_value(bytes), libstego.intp_value(num_bytes), stegomsg, stegolen, para
    )
    msglen = libstego.intp_value(stegolen)
    q.put((str(libstego.charp_value(stegomsg)))[0:msglen])
def create_lsb_parameter(password, method, use_msb):
    """This functions gets parameter
    method
    password
    and with them produces and returns a new lsb parameter
    using libstegofile's types.h.
    """
    para = libstegofile.lsb_parameter_t()
    para.password = password
    para.pwlen = len(password)
    para.select_mode = method
    print "use_msb: " + ` use_msb `
    if use_msb:
        para.use_msb = 1
    else:
        para.use_msb = 0
    print "para.use_msb: " + ` para.use_msb `
    return para
def lsbEmbed(q):
    post, filename = q.get()
    rgb_data = libstegofile.rgb_data_t()
    stego_data = libstegofile.rgb_data_t()
    png_struct = libstegofile.png_internal_data_t()
    retcode = libstegofile.io_png_read(filename, rgb_data, png_struct)
    if retcode == 0:
        pass
    else:
        return -1
    para = libstegofile.lsb_parameter_t()
    message = str(post["message"])
    para.password = str(post["pw"])
    para.pwlen = len(para.password)
    para.select_mode = 2
    para.use_msb = 0
    data = libstego.new_charpp()
    datalen = libstego.new_intp()
    libstego.lsb_convert_png(rgb_data, data, datalen)
    libstego.lsb_embed_indirect(libstego.charpp_value(data), libstego.intp_value(datalen), message, len(message), para)
    libstegofile.io_png_integrate(png_struct, rgb_data)
    libstegofile.io_png_write(filename, png_struct)
    q.put(filename)
def setup_methods(password, filetype):
    # Add all parameter sets for your algorithms here
    # Order them from the most secure to the least secure

    global num_methods
    global method_to_algo
    global methods

    num_methods = 0

    """JPEG params"""
    if filetype in ["JPEG", "JPG"]:
        # PQ
        #~ para = libstegofile.pq_parameter()
        #~ para.header_size = 0
        #~ para.quality = 0
        #~ para.password = password
        #~ para.pwlen = len(password)
        #~ methods[num_methods] = para
        #~ method_to_algo[num_methods] = "PQ"
        #~ num_methods += 1

        # F5
        para = libstegofile.f5_parameter()
        methods[num_methods] = para
        method_to_algo[num_methods] = "F5"
        num_methods += 1

        """GIF params"""
    elif filetype == "GIF":
        # Adv. Gifshuffle
        para = libstegofile.gifshuffle_parameter()
        para.method = 1
        para.password = password
        para.pwlen = len(password)
        methods[num_methods] = para
        method_to_algo[num_methods] = "Adv. Gifshuffle"
        num_methods += 1

        # Gifshuffle
        # TODO add Gifshuffle parameter set(s) here

        # Frirui
        para = libstegofile.frirui_parameter()
        para.method = 0
        para.size = 100
        para.password = password
        para.pwlen = len(password)
        methods[num_methods] = para
        method_to_algo[num_methods] = "Frirui"
        num_methods += 1

        # Sort/Unsort
        para = libstegofile.sortunsort_parameter()
        para.password = password
        para.pwlen = len(password)
        methods[num_methods] = para
        method_to_algo[num_methods] = "Sort/Unsort"
        num_methods += 1


        """PNG params"""
    elif filetype == "PNG":
        # CPT
        for i in [8,6,4,2]:
            para = libstegofile.cpt_parameter()
            para.block_width = i;
            para.block_height = i;
            para.password = password
            para.pwlen = len(password)
            methods[num_methods] = para
            method_to_algo[num_methods] = "CPT"
            num_methods += 1

        # Battlesteg
        para = libstegofile.battlesteg_parameter()
        para.startbit = 7
        para.move_away = 3
        para.range = 5
        para.password = password
        para.pwlen = len(password)
        methods[num_methods] = para
        method_to_algo[num_methods] = "Battlesteg"
        num_methods += 1


        """SVG Params"""
    elif filetype == "SVG":
        # SVG Steg
        for i in [6,4,2,0]:
            para = libstegofile.svg_parameter_t()
            para.password = password
            para.pwlen = len(password)
            para.first_embed_digit = i
            methods[num_methods] = para
            method_to_algo[num_methods] = "SVG Steg"
            num_methods += 1


        """WAV Params"""
    elif filetype == "WAV":
        # Echo Hiding
        para = libstegofile.eh_parameter()
        para.amplitude = 0.4;
        para.zero_offset = 900;
        para.one_offset = 2700;
        para.block_size = 80000;
        methods[num_methods] = para
        method_to_algo[num_methods] = "Echo Hiding"
        num_methods += 1

        # Phase Coding
        # TODO: add Phase Coding parameter set(s) here


    """LSB"""
    # LSB isn't dependant on a certain filetype
    para = libstegofile.lsb_parameter_t()
    para.password = password
    para.pwlen = len(password)
    para.select_mode = 2
    para.use_msb = 0
    methods[num_methods] = para
    method_to_algo[num_methods] = "LSB"
    num_methods += 1
def setup_methods(password):
    # Add all parameter sets for your algorithms here
    # Order them from the most secure to the least secure

    num_methods = 0

    """JPEG params"""
    # PQ
    para = libstegofile.pq_parameter()
    para.header_size = 0
    para.quality = 0
    methods[num_methods] = para
    method_to_algo[num_methods] = "PQ"
    num_methods += 1

    # F5
    para = libstegofile.f5_parameter()
    methods[num_methods] = para
    method_to_algo[num_methods] = "F5"
    num_methods += 1

    """GIF params"""
    # Adv. Gifshuffle
    para = libstegofile.gifshuffle_parameter()
    methods[num_methods] = para
    method_to_algo[num_methods] = "Adv. Gifshuffle"
    num_methods += 1

    # Gifshuffle
    # TODO add Gifshuffle parameter set(s) here

    # Frirui
    para = libstegofile.frirui_parameter()
    para.method = 0
    para.size = 100
    para.password = password
    para.pwlen = len(password)
    methods[num_methods] = para
    method_to_algo[num_methods] = "Frirui"
    num_methods += 1

    # Sort/Unsort
    para = libstegofile.sortunsort_parameter()
    methods[num_methods] = para
    method_to_algo[num_methods] = "Sort/Unsort"
    num_methods += 1


    """PNG params"""
    # CPT
    for i in [2,4,6,8]:
        para = libstegofile.cpt_parameter()
        para.block_width = i;
        para.block_height = i;
        para.password = password
        para.pwlen = len(password)
        methods[num_methods] = para
        method_to_algo[num_methods] = "CPT"
        num_methods += 1

    # Battlesteg
    para = libstegofile.battlesteg_parameter()
    para.startbit = 7
    para.move_away = 3
    para.range = 5
    para.password = password
    para.pwlen = len(password)
    methods[num_methods] = para
    method_to_algo[num_methods] = "Battlesteg"
    num_methods += 1


    """SVG Params"""
    # SVG Steg
    for i in [6,4,2,0]:
        para = libstegofile.svg_parameter_t()
        para.password = password
        para.pwlen = len(password)
        para.first_embed_digit = i
        methods[num_methods] = para
        method_to_algo[num_methods] = "SVG Steg"
        num_methods += 1


    """WAV Params"""
    # Echo Hiding
    # TODO: add Echo Hiding parameter set(s) here

    # Phase Coding
    # TODO: add Phase Coding parameter set(s) here

    """LSB"""
    para = libstegofile.lsb_parameter_t()
    para.password = password
    para.pwlen = len(password)
    para.select_mode = 2
    para.use_msb = 0
    methods[num_methods] = para
    method_to_algo[num_methods] = "LSB"
    num_methods += 1