예제 #1
0
def guess_password(max_length, in_data, known_part):
    """Iterative brute-force password guessing.

    Arguments:
    max_length -- the maximum length of the password (int)
    in_data -- the encrypted data (numpy array)
    known_part -- A part of the decoded data which is known (string)

    returns -- False or the correct guess
    """

    # This is a fairly silly way to do this
    # Must be changed for longer passwords to avoid running out of RAM

    # pull all the possible strings
    guesses = collections.deque(string.printable)


    while(guesses):
        cur_guess = guesses.popleft()

        if(len(cur_guess) > max_length):
            return False

        # decrypt and recondtruct the message
        # decrypt_bytes in here is more useful to split each key for each threads

        # cuda version

        """ create an array of decrypted and reconstructed  so also reconstruct could be executed in parallel"""
        if(len(cur_guess) > Messages):
        # if there are enough key in the list then try to execute them in parallel during the reconstruct phase
            decrypted = [None] * Messages
            i = 0
            while (i < Messages):
                decrypted[i] = decrypt_cuda.decrypt_bytes(in_data, cur_guess)
                # pop another value from the list
                cur_guess = guesses.popleft()
                i = i + 1

            # call the parallelised version of reconstruct
            # reconstruct is an array containing all the reconstruct solution for each message
            reconstructed = decrypt_cuda.reconstruct_secret(decrypted)

            for j in range(len(reconstructed)):
                if(try_password(reconstructed[j], known_part)):
                    return cur_guess
                else:
                    if(len(cur_guess) < max_length):
                        for char in string.printable:
                            guesses.append(cur_guess + char)
        else:
            decrypted = decrypt_cuda.decrypt_bytes(in_data, cur_guess)
            reconstructed_m = reconstruct_secret(decrypted)
            if(try_password(reconstructed_m, known_part)):
                return cur_guess
            else:
                if(len(cur_guess) < max_length):
                    for char in string.printable:
                        guesses.append(cur_guess + char)
예제 #2
0
def guess_password(max_length, in_data, known_part):
    """Iterative brute-force password guessing.

    Arguments:
    max_length -- the maximum length of the password (int)
    in_data -- the encrypted data (numpy array)
    known_part -- A part of the decoded data which is known (string)

    returns -- False or the correct guess
    """

    # This is a fairly silly way to do this
    # Must be changed for longer passwords to avoid running out of RAM

    # pull all the possible strings
    guesses = collections.deque(string.printable)


    while(guesses):
        cur_guess = guesses.popleft()

        if(len(cur_guess) > max_length):
            return False

        # decrypt and recondtruct the message
        # decrypt_bytes in here is more useful to split each key for each threads

        # cuda version
        decrypted = decrypt_cuda.decrypt_bytes(in_data, cur_guess)

        # sequential version
        # decrypted = decrypt_bytes(in_data, cur_guess)
        reconstructed = reconstruct_secret(decrypted)

        if(try_password(reconstructed, known_part)):
            return cur_guess
        else:
            if(len(cur_guess) < max_length):
                for char in string.printable:
                    guesses.append(cur_guess + char)
예제 #3
0
def guess_password(max_length, in_data, known_part):
    """Iterative brute-force password guessing.

    Arguments:
    max_length -- the maximum length of the password (int)
    in_data -- the encrypted data (numpy array)
    known_part -- A part of the decoded data which is known (string)

    returns -- False or the correct guess
    """

    # This is a fairly silly way to do this
    # Must be changed for longer passwords to avoid running out of RAM

    # pull all the possible strings
    guesses = collections.deque(string.printable)


    while(guesses):

        # pop first NUM_KEY guesses if there are any
        if(len(guesses)<NUM_KEY):

            cur_guess = guesses.popleft()

            if(len(cur_guess) > max_length):
                return False

            # decrypt and recondtruct the message
            # decrypt_bytes in here is more useful to split each key for each threads

            # cuda version
            decrypted = decrypt_cuda.decrypt_bytes(in_data, cur_guess)

            # sequential version
            # decrypted = decrypt_bytes(in_data, cur_guess)
            reconstructed = reconstruct_secret(decrypted)

            if(try_password(reconstructed, known_part)):
                return cur_guess
            else:
                if(len(cur_guess) < max_length):
                    for char in string.printable:
                        guesses.append(cur_guess + char)

        else:
            # call another parallel class which parallelize also the keys
            cur_guesses = np.empty(NUM_KEY, dtype=np.uint32)
            # pop first NUM_KEY elements from guesses
            i = 0
            while (i < NUM_KEY):
                cur_guesses[i] = guesses.popleft()
                i = i + 1
            # return a list of decrypted messages
            decrypted_list = decrypt_cuda_v2.decrypt_bytes(in_data, cur_guesses)

            # in decrypted_list there is a long array made of all the decrypted values from 500 keys.
            # each len(in_data) position there is a new key

            #TODO: PROBLEM: HOW DO I RECOGNIZE WHICH KEY IS? according to i number
            for i in range(len(decrypted_list)/len(in_data)):
                reconstructed = reconstruct_secret(decrypted_list[(i*len(in_data)):((i+1) * len(in_data))])
                if(try_password(reconstructed, known_part)):
                    return cur_guesses[i]
                else:
                    if(len(cur_guesses[i]) < max_length):
                        for char in string.printable:
                            guesses.append(cur_guesses[i] + char)