<commit_before>from halfHandshake import hmac4times


def isWPAPass(passPhrase, ssid, clientMac, APMac, Anonce, Snonce, mic, data):
    pke = "Pairwise key expansion" + '\x00' + min(APMac,clientMac)+max(APMac,clientMac)+min(Anonce,Snonce)+max(Anonce,Snonce)
    pmk = pbkdf2_bin(passPhrase, ssid, 4096, 32)
    ptk = hmac4times(pmk,pke)
    if ord(data[6]) & 0b00000010 == 2:
        calculatedMic = hmac.new(ptk[0:16],data,sha1).digest()[0:16]
    else:
        calculatedMic = hmac.new(ptk[0:16],data).digest()
    return mic == calculatedMic:

def perm(universo, longitud, comienzo=False):
	""" 
	Calcula permutaciones.
	universo = lista de caracteres que compondra las combinaciones.
	longitud = longitud que tendra cada permutacion.
	comienzo = permutacion desde la cual iniciar a calcular permutaciones.
	"""
	#inicializa numero de tabulaciones
	nt = 2
	continuee = False
	if comienzo:
		last = comienzo
		indexes = [lis.index(x) - 1 for x in last]
		indexes[-1] += 2
		continuee = True
	code = """def yield_perm():
	try:
		lis = '%s'
		n = n2 = %s
		continuee = %s
		indexes = %s
"""	% (universo, longitud, str(continuee), str(indexes if continuee else []))
	c = -1
	while n > 0:
		c += 1
		i = -1
		code += ("\t" * nt) + "if continuee:\n" + ("\t" * (nt + 1)) + "c{0} = indexes[{0}]; indexes[{0}] = -1\n".format(c)
		code += ("\t" * nt) + "else:\n" + ("\t" * (nt + 1)) + "c%d = -1\n" % (c)
		# code += ("\t" * nt) + "c%d = -1\n" % (c)
		code += ("\t" * nt) + ("while c%d < len(lis) - 1:\n" % c)
		nt += 1
		code += ("\t" * nt) + "c%d += 1\n" % c
		code += ('\t' * nt) + "d{0} = lis[c{0}]\n".format(c)
		n -= 1
	code += ('\t' * nt) + "comb = " + ("d%d + " * n2) % tuple(range(n2)) + "'\\n'\n"
	code += ('\t' * nt) + "yield comb\n"
	code += """	except KeyboardInterrupt:
			pass"""
	exec code
	return yield_perm()

<commit_msg>fix de funcion para generar permutaciones y modificada para aceptar especificación una combinacion final<commit_after>from cracker import hmac4times


def isWPAPass(passPhrase, ssid, clientMac, APMac, Anonce, Snonce, mic, data):
    pke = "Pairwise key expansion" + '\x00' + min(APMac,clientMac)+max(APMac,clientMac)+min(Anonce,Snonce)+max(Anonce,Snonce)
    pmk = pbkdf2_bin(passPhrase, ssid, 4096, 32)
    ptk = hmac4times(pmk,pke)
    if ord(data[6]) & 0b00000010 == 2:
        calculatedMic = hmac.new(ptk[0:16],data,sha1).digest()[0:16]
    else:
        calculatedMic = hmac.new(ptk[0:16],data).digest()
    return mic == calculatedMic

def perm(universo, longitud, inicio=False, fin=False):
	""" 
	Calcula permutaciones.
	universo = lista de caracteres que compondra las combinaciones.
	longitud = longitud que tendra cada permutacion.
	inicio = lista de posiciones desde la cual comenzara a iterar cada caracter. Sirve para especificar la permutacion desde la cual debe iniciar a calcular permutaciones.
	"""
	lis = universo
	nt = 2
	n = n2 = longitud
	if inicio:
		inicio = list(inicio)
		indexes = [x - 1 for x in inicio]
	if fin:
		fin = list(fin)
	code = """def yield_perm():
	try:
		lis = '%s'
		n = n2 = %s
		inicio = %s
		fin = %s
		indexes = %s
"""	% (universo, longitud, str(inicio), str(fin), str(indexes if inicio else []))
	c = -1
	while n > 0:
		c += 1
		i = -1
		code += ("\t" * nt) + "if inicio:\n" + ("\t" * (nt + 1)) + "c{0} = indexes[{0}]; indexes[{0}] = -1\n".format(c)
		code += ("\t" * nt) + "else:\n" + ("\t" * (nt + 1)) + "c%d = -1\n" % (c)
		code += ("\t" * nt) + ("while c%d < len(lis) - 1:\n" % c)
		nt += 1
		code += ("\t" * nt) + "c%d += 1\n" % c
		code += ('\t' * nt) + "d{0} = lis[c{0}]\n".format(c)
		n -= 1
	code += ('\t' * nt) + "comb = " + (("d%d + " * n2) % tuple(range(n2)))[:-2]  + "\n"
	code += ('\t' * nt) + "yield comb\n"
	contadores = (("c%d , " * n2) % tuple(range(n2)))[:-2]
	code += ('\t' * nt) + "if [" + contadores + "] == fin:\n"
	code += ('\t' * (nt + 1)) + "indexes = [" + (str(longitud) + ', ') * longitud  + "]\n"
	code += ('\t' * (nt + 1)) + "%s = indexes; break\n" % contadores
	code += ('\t' * (nt + 1)) + "break\n"
	code += """	except KeyboardInterrupt:\n\t\t\tpass"""
	exec code
	return yield_perm()

{'fraction_non_alphanumeric': 0.208251953125, 'fraction_numerical': 0.029052734375, 'mean_word_length': 3.2855648535564854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2833642', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1749, 'n_words': 438}