def run(): lines = [x.fromhex() for x in data.fromfile("data/d4.txt").split(b"\n")] topscore = -100. topdata = None for l in lines: if len(l) < 1: continue for x in range(255): s = english.scorefull(l ^ data.Data([x])) if s > topscore: topscore = s topdata = l ^ data.Data([x]) print(topdata)
def xlsxToCsv(filename, index): for x in index: filenameOut = filename.replace(".xlsx", "") + "_clean_sheet" + str(x) + ".csv" dataObj = data.Data(filename, x) dataObj.encodeAllUnicode() dataObj.save(filenameOut)
def run(): print(" === Preliminaries === ") print("Hamming test:") print(" ", data.Data(b"this is a test").hammingbits(b"wokka wokka!!!")) print(" === START === ") print(" = Searching for KEYSIZE = ") keysize_scores = [(s, scorekeysize(s)) for s in range(2, 40)] keysizes = sorted(keysize_scores, key=lambda k: k[1]) print(keysizes) print(" = Searching for KEY = ") for i in range(1): # Used for testing keysize = keysizes[i][0] print("Testing keysize: ", keysize) key = findkey(keysize) print(key) print((in1 ^ key).toascii())
import lib.data as data print(data.Data(b"abcd").fromhex())
def run(): print((in1 ^ data.Data(b"ICE")).tohex())
#!/bin/python3 import lib.data as data in1 = data.Data( b"Burning 'em, if you ain't quick and nimble\nI go crazy when I hear a cymbal" ) def run(): print((in1 ^ data.Data(b"ICE")).tohex()) run()
def deploy_apps(deploy_config, force_remove=False, remove_repos=False): env = environment.BashEnvironment() # launch status thread threads = [] log.info('Starting status thread.') t = deploy.StatusThread() t.start() threads.append(t) # launch worker threads try: num_threads = int(deploy_config.get('global', 'max-deploy-threads')) except: log.debug('Missing max-deploy-threads section. Setting to 1.') num_threads = 1 log.info('Starting %s deploy threads.' % num_threads) for i in range(num_threads): t = deploy.WorkerThread() t.start() threads.append(t) # create final deploy directory location if it doesn't exist deploy_dir = deploy_config.get('global', 'final-deploy-directory') deploy_dir = os.path.expanduser(deploy_dir) deploy_dir = os.path.abspath(deploy_dir) if os.path.exists(deploy_dir): log.debug('Final deploy directory already exists: %s' % deploy_dir) else: log.debug('Creating final deploy directory: %s' % deploy_dir) os.makedirs(deploy_dir) # identify data and application sections in the config file all_sect = deploy_config.sections() req_sect = ['dependencies', 'global'] data_sect = [x for x in all_sect if 'data-' in x] app_sect = list(set(all_sect) - (set(req_sect) | set(data_sect))) log.debug('All config sections: %s' % all_sect) log.debug('Required config sections: %s' % req_sect) log.debug('Data config sections: %s' % data_sect) log.debug('Application config sections: %s' % app_sect) log.info('Running deploy for data and apps without dependencies.') # locate the python and r executables that we should use for the deploy # process (if required) custom_py_exe = get_executable_path(log, deploy_config, app_sect, 'python', 'python') custom_r_exe = get_executable_path(log, deploy_config, app_sect, 'r', 'R') # create application objects for all apps to deploy all_apps_to_deploy = [] remaining_apps_to_deploy = [] for app_name in app_sect: a = application.Application(app_name, env, deploy_config, custom_py_exe, custom_r_exe, remove_repos) remaining_apps_to_deploy.append(a) all_apps_to_deploy.append(a) # create and schedule all data objects for data_name in data_sect: d = data.Data(data_name, env, deploy_config) deploy.WORK_Q.put(d) # immediately schedule all applications that do not contain dependencies for app in list(remaining_apps_to_deploy): if not app.deps: log.debug('Putting %s in the queue to deploy.' % app.name) deploy.WORK_Q.put(app) remaining_apps_to_deploy.remove(app) remaining_names = [app.name for app in remaining_apps_to_deploy] log.info('Launched initial deploy, remaining apps: %s' % remaining_names) # schedule applications with dependencies once all of an applications # dependencies have completed successfully log.info('Deploying remaining apps.') while remaining_apps_to_deploy: for app in list(remaining_apps_to_deploy): all_deps_complete = True all_deps_successful = True for dep in app.deps: if not is_app_complete(dep, all_apps_to_deploy): log.debug('%s dependencies remaining:%s' % (app.name, app.deps)) all_deps_complete = False if not is_app_successful(dep, all_apps_to_deploy): log.debug('%s dependencies not yet successful:%s' % (app.name, app.deps)) all_deps_successful = False if dep not in app_sect: log.error('Application will never complete, dependency' + \ 'does not exist: %s' % dep) app.success = False app.complete = True deploy.FAILED_Q.put(app) remaining_apps_to_deploy.remove(app) if not app.complete: if all_deps_complete and all_deps_successful: log.debug('Putting %s in the queue to deploy.' % app.name) deploy.WORK_Q.put(app) remaining_apps_to_deploy.remove(app) if all_deps_complete and (not all_deps_successful): app.success = False app.complete = True log.error('Dependencies failed for %s.' % app.name) deploy.FAILED_Q.put(app) remaining_apps_to_deploy.remove(app) remaining_names = [app.name for app in remaining_apps_to_deploy] log.debug('Applications waiting on dependencies: %s' % remaining_names) log.debug('Control thread sleeping: %s seconds' % SLEEP_SECS) time.sleep(SLEEP_SECS) # wait for everything to complete deploy.WORK_Q.join() deploy.DONE = True for t in threads: t.join() summary = '\n\n' summary += 'DEPLOYMENT SUMMARY\n\n' # print out successful deployments first = True summary += 'Packages deployed successfully:\n' while not deploy.COMPLETE_Q.empty(): item = deploy.COMPLETE_Q.get(False) if item: if not first: summary += ', %s' % item.name else: summary += '%s' % item.name first = False summary += '\n' # print out skipped deployments first = True summary += '\nPackages skipped (assumed successful):\n' while not deploy.SKIPPED_Q.empty(): item = deploy.SKIPPED_Q.get(False) if item: if not first: summary += ', %s' % item.name else: summary += '%s' % item.name first = False summary += '\n' # print out failed applications at the end and perform cleanup failed_items = False first = True failed_list = [] summary += '\nPackages failed to deploy:\n' while not deploy.FAILED_Q.empty(): item = deploy.FAILED_Q.get(False) if item: failed_dir = util.remove_directory(item.deploy_dir, force_remove) if failed_dir: failed_list.append(failed_dir) if not first: summary += ', %s' % item.name else: summary += '%s' % item.name first = False failed_items = True summary += '\n\n' if failed_list: summary += 'Directories of failed applications must be removed ' + \ 'manually or --force-remove-failed-dirs must be specified:' summary += '\n' for failed_dir in failed_list: summary += failed_dir summary += '\n' summary += '\n' # build and write out activate.sh log.debug('Writing new environment variables to activate.sh') log.debug('Print environment: %s' % env.get_print_env()) try: append_bashrc = deploy_config.get('global', 'append-environment-to-bashrc') if append_bashrc == 'yes': append_bashrc = True else: append_bashrc = False except: log.debug( 'Did not find append-environment-to-bashrc option, skipping.') append_bashrc = False try: append_bashprofile = deploy_config.get( 'global', 'append-environment-to-bashprofile') if append_bashprofile == 'yes': append_bashprofile = True else: append_bashprofile = False except: log.debug( 'Did not find append-environment-to-bashprofile option, skipping.') append_bashprofile = False generate_activate_file(env.get_print_env(), deploy_dir, append_bashrc, append_bashprofile) # run any custom finalization code, in QIIME's case, this is where # the QIIME config file is generated and written rc = custom.custom_finalize(custom_py_exe, deploy_dir, all_apps_to_deploy, log) sys.stdout.write(summary) if failed_items: rc = 1 return rc
#!/bin/python3 import lib.data as data in1 = data.Data(b"1c0111001f010100061a024b53535009181c").fromhex() in2 = data.Data(b"686974207468652062756c6c277320657965").fromhex() def run(): print((in1 ^ in2).tohex()) run()
#!/bin/python3 import lib.data as data d = data.Data( b"49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d" ).fromhex() def run(): print(d.tob64()) run()
#!/bin/python3 import lib.data as data import lib.english as english in1 = data.Data( b"1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736" ).fromhex() def run(): top = english.findhigh([in1 ^ [x] for x in range(256)]) print("Best Score using XOR " + str(top[2]) + ":") print(str(top[0]) + " " + str(top[1])) run()
def findkey(keysize): trans = in1.transpose(keysize) key = data.Data(keysize) for i in range(keysize): key[i] = english.findhigh([trans[i] ^ [x] for x in range(256)])[2] return key
#!/bin/python3 from lib.data import Data from lib import data from Crypto.Cipher import AES key = data.Data(b"YELLOW SUBMARINE") in1 = data.fromfile("data/d7.txt").fromb64() def run(): cipher = AES.new(bytes(key), AES.MODE_ECB) out1 = cipher.decrypt(bytes(in1)) out2 = Data(out1[0:-out1[-1]]) # Remove padding print(out2.toascii()) run()