Beispiel #1
0
def BreaKeys(keyFiles, outLoc):
	pubKeys = []
	secKeys = {}
	for keyFile in keyFiles:
		for keyLine in keyFile:
			if keyLine[:7] != "ssh-rsa": continue
			pubKeys.append(GetKeyData(keyLine))	# Get pubkeys

	print "Found %d public keys" % len(pubKeys)
	if len(pubKeys) < 2:
		print "Not enough public keys, exiting"
		return

	if not debug: print "Searching for collisions..."
	for keyPair in choose(pubKeys,2):
		if gcd(keyPair[0]["n"], keyPair[1]["n"]) > 1:	# Share prime?
			if not debug: print "Found collison! Generating keys..."
			for key in CrackKeys(keyPair[0], keyPair[1]):
				if key["n"] not in secKeys:	# Not cracked?
					if debug: print "Cracking key %d:" % (key["n"] % 1000000)
					secKeys[key["n"]] = GenKey(key) # Privkey!

	if debug: print "%d private keys found:\n" % len(secKeys)
	for sk in secKeys.values():outLoc.write(sk + "\n\n")
	if outLoc != sys.stdout: outLoc.close()
	print "Done!"
	return
Beispiel #2
0
def cluster_permutations(list_of_words):
    permutations = []
    seed_combinations = choose(list_of_words, 2)
    for seed_comb in seed_combinations:
        corresponding_targs = [word for word in list_of_words if word not in seed_comb]
        permutations.append((list(seed_comb), corresponding_targs))
    return permutations
Beispiel #3
0
def Monomials(data, polyorder):
    n, m, l = data.shape
    psi_data = data
    if polyorder > 1:
        psi_data = np.append(psi_data,np.ones((1,m,l)),axis = 0)
        for i in np.arange(2,polyorder + 1):
            for j in choose(np.arange(n),i):
                prod = 1
                for k in j:
                    prod = prod*data[k,:,:]
                psi_data = np.append(psi_data,prod[np.newaxis,:,:],axis = 0)
    return psi_data
Beispiel #4
0
def break_keys(args):
	pubkeys = []
	keys = []

	for keyfile in args.keyfiles:
		for line in keyfile:
			if line[:7] != "ssh-rsa": continue
			else:
				pubkeys.append(Util.get_key_info(line))
				Util.log.debug("Adding keyfile {}".format(pubkeys[-1]["c"]))

	Util.log.info("SSH pubkeys found: {}".format(len(pubkeys)))

	for pk in pubkeys:
		Util.log.debug("Have key {}".format(pk["c"]))
	if len(pubkeys) < 2:
		exit(Util.log.error("Not enough keys to crack"))

	Util.log.info("Searching for collisions...")
	for pks in choose(pubkeys, 2):
		p = gcd(pks[0]["n"], pks[1]["n"])
		if p > 1:
			Util.log.info("Collision between {} and {}".format(
				pks[0]["c"], pks[1]["c"]))

			q1 = pks[0]["n"] / p
			q2 = pks[1]["n"] / p

			keys.append(Keypair(p, q1, pks[0]["e"], pks[0]["c"]))
			keys.append(Keypair(p, q2, pks[1]["e"], pks[1]["c"]))

	Util.log.info("{} private keys found".format(len(keys)))
	for key in keys:
		args.secrets.write(
			"Private Key for {}\n{}\n".format(key.comment, key.sk))

	Util.log.info("Done!")
Beispiel #5
0
# and how many we'll use for testing.

#train_size = [8000, 8000, 4500, 850, 425, 300,  50]  # larger training sets
train_size = [100, 50, 50, 100, 100, 50, 50]
test__size = [100, 100, 100, 800, 800, 100, 100]

#%% IMPORTS
import json
import numpy as np
from hw6 import preprocess
from sklearn.svm import SVC
from itertools import combinations as choose

#%% GENERATING ALL HANDS
cards = range(52)
hands = np.array(list(choose(cards, 5)), dtype=np.int8)

with open('trick.json') as f:
    trick = np.array(json.load(f), dtype=np.int8)

hands = [hands[trick == i] for i in range(1, 8)]

# You do not need to worry about how I created hands.
# But you should understand how the data in hands is stored.
# This should help you...
print('hands has type ', type(hands))
print('hands[0] has type ', type(hands[0]), '\n')

# hands[0] consists of one pairs
# hands[1] consists of two pairs
# ...
Beispiel #6
0
def abundant_sums(lim):
    return {sum(c) for c in choose(abundants(lim), 2) if sum(c) <= lim}