def main(argv): lines = files.read_lines(argv[0]) N_1 = mpz(lines[0]) N_2 = mpz(lines[1]) N_3 = mpz(lines[2]) lines = files.read_lines(argv[1]) C = mpz(lines[0]) E = int(lines[1]) p1, q1, i1 = number.factorize(N_1, 1) p2, q2, i2 = number.factorize(N_2, 1048576) p3, q3, i3 = number.factorize(mul(N_3, 24), 1) print print 'Factorization Demo' print print ' 1st:' print 'Iterations: ', i1 print ' p: ', p1 print ' q: ', q1 print print ' 2nd:' print 'Iterations: ', i2 print ' p: ', p2 print ' q: ', q2 print print ' 3rd:' print 'Iterations: ', i3 print ' p: ', div(p3, 6) print ' q: ', div(q3, 4) print print print ' Plaintext: ', encdec.rsa_decrypt(C, E, p1, q1, N_1) print
def main(argv): lines = files.read_lines(argv[0]) N = int(lines[0]) S = lines[1] K = int(lines[2]) print(caesar_cipher(S, K))
def main(argv): lines = files.read_lines(argv[0]) N, M, K = [int(i) for i in lines[0].split()] B = lines[1:] C = coin_on_the_table(N, M, K, B) print(-1 if C == 999999 else C)
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for i in range(T): A = lines[(2 * i) + 1] B = lines[(2 * i) + 2] print(merge(A, B))
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for i in range(T): A = lines[(2 * i) + 1] B = lines[(2 * i) + 2] if substring(A, B): print('YES') else: print('NO')
def main(argv): P, G, H = [int(i) for i in files.read_lines(argv[0])] # calculated = number.discrete_log_numbthy(P, G, H) calculated = number.discrete_log(P, G, H) print print "Discrete Log Demo" print print 'Successfully found x with a value of %s' % calculated print
def main(argv): lines = [line.decode('hex') for line in files.read_lines(argv[0])] print print 'AES Demo' print print encdec.aes_decrypt(lines[1], lines[0]) print encdec.aes_decrypt(lines[2], lines[0]) print print encdec.aes_decrypt(lines[4], lines[3], True) print encdec.aes_decrypt(lines[5], lines[3], True) print
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) C = 1 for _ in range(T): N = int(lines[C]) C += 1 G = [[ord(c) for c in line] for line in lines[C:C + N]] C += N print(grid_challenge(N, G))
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) count = 1 for _ in range(T): R, C = [int(i) for i in lines[count].split()] count += 1 G = lines[count:count + R] count += R r, c = [int(i) for i in lines[count].split()] count += 1 P = lines[count:count + r] count += r print('YES' if grid_search(R, C, G, r, c, P) else 'NO')
def test_various_cards(): effects = [''] + files.read_lines('input/effects.txt') NUM_CARDS = 53 SELECTED_CARDS = [ # Simple tests Acquirable("Apprentice", "0R", 0, "Hero", compound([ fetch_simple_effect(effects, 3, 1, False) ])), Acquirable("Hedron Link Device", "7R", 7, "Mechana Construct", compound([ fetch_simple_effect(effects, 21, None, False) ])), # Test multiple effects Acquirable("Arbiter of the Precipice", "4R", 1, "Void Hero", compound([ fetch_simple_effect(effects, 2, 2, False), fetch_simple_effect(effects, 6, 1, False) ])), # Test optional effects Acquirable("Seer of the Forked Path", "2R", 1, "Enlightened Hero", compound([ fetch_simple_effect(effects, 2, 1, False), fetch_simple_effect(effects, 7, 1, True) ])), # Test compound effects (and construct) Acquirable("Yggdrasil Staff", "4R", 2, "Lifebound Construct", compound([ fetch_simple_effect(effects, 5, 1, False), CompoundEffect("AND", [ fetch_simple_effect(effects, 3, -4, False), fetch_simple_effect(effects, 4, 3, False) ], True) ])), # Test defeatable (and with comma in name) Defeatable("Xeron, Duke of Lies", "6P", "Monster", compound([ fetch_simple_effect(effects, 4, 3, False), fetch_simple_effect(effects, 22, None, False) ])) ] card_dictionary = get_dict() assert len(card_dictionary.cards) == NUM_CARDS for card in SELECTED_CARDS: check_card_correct(card_dictionary, card)
def test_effects_not_reodered(): EXPECTED_EFFECTS = [ "Discard %d cards", "Draw %d cards", "Gain %d runes", "Gain %d honor", "Gain %d power", "Banish %d card in hand", "Banish %d card in center", "Banish %d card from discard pile", "Defeat monster of %d power or less without cost", "Pay %d less runes when acquiring a mechana construct this turn", "Acquire a hero with cost %d or less without cost. Place it on top of your deck", "First time you play a lifebound hero, gain %d honor", "Draw %d card when putting a Mechana Construct into play", "Banish this card to take an additional turn", "Pay %d less runes when acquiring a construct this turn", "First time you defeat a monster, gain %d honor", "Draw a card if you control 2 or more constructs", "Gain %d honor for each faction among Constructs you control", "Each opponent must destroy a construct", "Once per turn, when you acquire another Mechana Construct, put it directly into play", "Treat all constructs as mechana constructs", "Take a card at random from each opponent's hand and add that to your hand", "If you have played another lifebound hero, gain %d power", "Each opponent destroys all but one construct", "Gain %d power for each Mechana Construct in play that you control", "Copy the effect of a Hero", "Unbanishable. Acquire or defeat any card in the center without paying its cost." ] effects = files.read_lines('input/effects.txt') fail_message = """It looks like effects.txt has been changed. If it was just a minor change (rewording a description), just change it in this test. Be careful about reordering effects, though, because we reference effects by indices so you'll probably break a lot of things.""" assert effects == EXPECTED_EFFECTS, fail_message
def main(argv): cypher_texts = [common.hex_to_ascii(cypher_text) for cypher_text in files.read_lines(argv[0])] key = encdec.many_time_pad_crack(cypher_texts, len(cypher_texts[10])) plain_text = common.string_to_ascii('The secret message is: When using a stream cipher, never use the key more than once') new_key = common.xor(plain_text, cypher_texts[10]) print print 'Decrypt Many-time Pad Demo' print for i in xrange(len(cypher_texts)): print 'Message %2d = %s' % ((i + 1), common.ascii_to_string(common.xor(cypher_texts[i], key))) print print 'Make best guess and use to derive key' print for i in xrange(len(cypher_texts)): print 'Message %2d = %s' % ((i + 1), common.ascii_to_string(common.xor(cypher_texts[i], new_key))) print
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for line in lines[1:]: print(deletions(line))
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for line in lines[1:]: print(square_subsequences(line))
def main(argv): lines = files.read_lines(argv[0]) print(deletions(*lines))
def main(argv): lines = files.read_lines(argv[0]) a = lines[0] b = lines[1] print(xor_and_sum(a, b))
def main(argv): lines = files.read_lines(argv[0]) n = int(lines[0]) M = lines[1:] print('\n'.join(cavity_map(n, M)))
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for line in lines[1:]: print(anagramic_pairs(line))
def main(argv): lines = files.read_lines(argv[0]) M, N = [int(i) for i in lines[0].split()] A = lines[1:] R = perimeter(M, N, A) print(R if R > 0 else 'impossible')
def main(argv): lines = files.read_lines(argv[0]) topics = [int(val, 2) for val in lines[1:]] print('\n'.join(str(value) for value in max_topics(topics)))
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for line in lines[1:]: print(changes(line))
def main(argv): lines = files.read_lines(argv[0]) taxa = lines[0].split() trees = lines[1:] print quartet_distance(*trees)
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) for line in lines[1:]: print(greater_than(line))
def main(argv): lines = files.read_lines(argv[0]) N = int(lines[0]) R = [parse_record(line.split(',')) for line in lines[1:]] print(','.join(str(f) for f in fraud_prevention(R)))
def main(argv): lines = files.read_lines(argv[0]) T = int(lines[0]) print(len(gem_stones(lines[1:])))
def main(argv): alpha = [c for c in 'abcdefghijklmnopqrstuvwxyz'] lines = files.read_lines(argv[0]) for line in lines[1:]: print(palindrome(alpha, line))
def main(argv): lines = files.read_lines(argv[0]) edges = graphs.edges_from_adjacency_list(lines) nodes = graphs.nodes_from_edges(edges) print ', '.join(graphs.topological_sort(nodes, edges))