def get_capacity(algorithm, filename, para): """This function gets parameters algorithm ... the String naming the chosen algorithm filename ... the chosen input filename para ... a parameter for the chosen algorithm and computes the capacity of the algorithm for the given file and parameters. It returns the capacity. """ if filename[-3:] == "gif": palette_data = libstegofile.palette_data_t() gif_struct = libstegofile.gif_internal_data_t() bla = libstegofile.io_gif_read(filename, palette_data, gif_struct) if algorithm == "Frirui": cap = libstego.frirui_check_capacity(palette_data, para) elif algorithm == "GifShuffle": cap = libstego.gifshuffle_check_capacity(palette_data, para) elif algorithm == "Sort / Unsort": cap = libstego.sortunsort_check_capacity(palette_data, para) libstegofile.io_gif_cleanup_data(palette_data) # libstegofile.io_gif_cleanup_internal(gif_struct) elif filename[-3:] == "png": rgb_data = libstegofile.rgb_data_t() rgb_internal = libstegofile.png_internal_data_t() bla = libstegofile.io_png_read(filename, rgb_data, rgb_internal) if algorithm == "Battlesteg": cap = libstego.battlesteg_check_capacity(rgb_data, para) elif algorithm == "CPT": cap = libstego.cpt_check_capacity(rgb_data, para) elif algorithm == "LSB": bytes = libstego.new_charpp() num_bytes = libstego.new_intp() libstego.lsb_convert_png(rgb_data, bytes, num_bytes) cap = libstego.lsb_check_capacity_indirect( libstego.charpp_value(bytes), libstego.intp_value(num_bytes), para ) libstego.lsb_cleanup_converted_data(libstego.charpp_value(bytes)) libstego.delete_charpp(bytes) elif filename[-3:] == "wav": wav_data = wav_data_t() wav_int = wav_internal_data_t() bla = libstegofile.io_wav_read(filename, wav_data, wav_int) if algorithm == "Echo Hiding": cap = libstego.echohiding_check_capacity(wav_data, para) elif algorithm == "Phase Coding": cap = libstego.phasecoding_check_capacity(wav_data, para) elif algorithm == "PW": cap = libstego.pw_check_capacity(wav_data, para) elif filename[-3:] == "svg": svg_data = libstegofile.svg_data_t() svg_int = libstegofile.svg_internal_data_t() bla = libstegofile.io_svg_read(filename, svg_data, svg_int) if algorithm == "SVG Steg": cap = libstego.svg_check_capacity(svg_data, para) elif filename[-3:] in ["peg", "jpg"]: jpeg_data = libstegofile.jpeg_data_t() jpeg_int = libstegofile.jpeg_internal_data_t() bla = libstegofile.io_jpeg_read(filename, jpeg_data, jpeg_int) if algorithm == "F5": cap = libstego.f5_check_capacity(jpeg_data, para) elif algorithm == "MB2": cap = libstego.mb2_check_capacity(jpeg_data, para) elif algorithm == "PQ": cap = libstego.pq_check_capacity(jpeg_data, para) elif algorithm == "LSB": cap = libstego.lsb_check_capacity(palette_data, para) print cap if cap[0] == 0: return cap[1] else: print "Error computing capacity!" return 666
def get_best_method(filename, msglen): global num_methods global method_to_algo global methods for method in range(0, num_methods): fits = False para = methods[method] print "Testing method " + `method+1` print "Algorithm: " + method_to_algo[method] if method_to_algo[method] == "PQ": # prepare data strucures jpeg_data = libstegofile.jpeg_data_t() jpeg_int = libstegofile.jpeg_internal_data_t() # read file data err = libstegofile.io_jpeg_read(filename, jpeg_data, jpeg_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.pq_check_capacity(jpeg_data, para) >= msglen: fits = True # cleanup libstegofile.io_jpeg_cleanup_data(jpeg_data) libstegofile.io_jpeg_cleanup_internal_data(jpeg_int) elif method_to_algo[method] == "F5": # prepare data strucures jpeg_data = libstegofile.jpeg_data_t() jpeg_int = libstegofile.jpeg_internal_data_t() # read file data err = libstegofile.io_jpeg_read(filename, jpeg_data, jpeg_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.f5_check_capacity(jpeg_data) >= msglen: fits = True # cleanup libstegofile.io_jpeg_cleanup_data(jpeg_data) libstegofile.io_jpeg_cleanup_internal_data(jpeg_int) elif method_to_algo[method] in ["Adv. Gifshuffle", "Gifshuffle"]: # prepare data strucures palette_data = libstegofile.palette_data_t() gif_int = libstegofile.gif_internal_data_t() # read file data err = libstegofile.io_gif_read(filename, palette_data, gif_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.gifshuffle_check_capacity(palette_data, para) >= msglen: fits = True # cleanup libstegofile.io_gif_cleanup_data(palette_data) libstegofile.io_gif_cleanup_internal(gif_int) elif method_to_algo[method] == "Frirui": # prepare data strucures palette_data = libstegofile.palette_data_t() gif_int = libstegofile.gif_internal_data_t() # read file data err = libstegofile.io_gif_read(filename, palette_data, gif_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.frirui_check_capacity(palette_data, para) >= msglen: fits = True # cleanup libstegofile.io_gif_cleanup_data(palette_data) libstegofile.io_gif_cleanup_internal(gif_int) elif method_to_algo[method] == "Sort/Unsort": # prepare data strucures palette_data = libstegofile.palette_data_t() gif_int = libstegofile.gif_internal_data_t() # read file data err = libstegofile.io_gif_read(filename, palette_data, gif_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.sortunsort_check_capacity(palette_data, para) >= msglen: fits = True # cleanup libstegofile.io_gif_cleanup_data(palette_data) libstegofile.io_gif_cleanup_internal(gif_int) elif method_to_algo[method] == "CPT": # prepare data strucures rgb_data = libstegofile.rgb_data_t() png_int = libstegofile.png_internal_data_t() # read file data err = libstegofile.io_png_read(filename, rgb_data, png_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.cpt_check_capacity(rgb_data, para) >= msglen: fits = True # cleanup libstegofile.io_png_cleanup_data(rgb_data) libstegofile.io_png_cleanup_internal(png_int) elif method_to_algo[method] == "Battlesteg": # prepare data strucures rgb_data = libstegofile.rgb_data_t() png_int = libstegofile.png_internal_data_t() # read file data err = libstegofile.io_png_read(filename, rgb_data, png_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.battlesteg_check_capacity(rgb_data, para) >= msglen: fits = True # cleanup libstegofile.io_png_cleanup_data(rgb_data) libstegofile.io_png_cleanup_internal(png_int) elif method_to_algo[method] == "SVG Steg": # prepare data strucures svg_data = libstegofile.svg_data_t() svg_int = libstegofile.svg_internal_data_t() # read file data err = libstegofile.io_svg_read(filename, svg_data, svg_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.svg_check_capacity(svg_data, para) >= msglen: fits = True # cleanup libstegofile.io_svg_cleanup_data(svg_data) libstegofile.io_svg_cleanup_internal(svg_int) elif method_to_algo[method] == "Echo Hiding": # prepare data strucures wav_data = libstegofile.wav_data_t() wav_int = libstegofile.wav_internal_data_t() # read file data err = libstegofile.io_wav_read(filename, wav_data, wav_int) if err != 0: # TODO better error handling -> detailed message what went wrong # by using the 'lstg_errno' code return None # check if message fits with the current params if libstego.eh_check_capacity(wav_data, para) >= msglen: fits = True # cleanup libstegofile.io_wav_cleanup_data(wav_data) libstegofile.io_wav_cleanup_internal(wav_int) elif method_to_algo[method] == "Phase Coding": # TODO implement pass elif method_to_algo[method] == "LSB": # TODO implement pass if fits: print "best method: " + `method+1` return method return None