コード例 #1
0
def main(args):
    # get args' values #
    logins, passwords = [], []
    login = args['l']
    login_dict_path = args['L']
    password = args['p']
    password_dict_path = args['P']
    num_threads = args['t']
    host = args['host']
    port = args['port']
    reverse = args['reverse']
    delay = args['delay']

    # Set brute force login(s)
    if login_dict_path:
        login_dict = open(login_dict_path, 'r')
        logins = [login.replace('\n', '') for login in login_dict]
    elif login:
        logins.append(login)

    # Set brute force password(s)
    if password_dict_path:
        password_dict = open(password_dict_path, 'r')
        passwords = [passwd.replace('\n', '') for passwd in password_dict]
    elif password:
        passwords.append(password)

    # Start brute force attack
    brute_force(host, port, logins, passwords, num_threads, delay, reverse)
コード例 #2
0
ファイル: test.py プロジェクト: CodeKontora/primality_tests
def test_on_first_44_prime_number():
    prime_numbers = [5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
                    67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131,
                    137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
    for num in prime_numbers:
        assert brute_force(num) == True
        assert Wilson_test(num) == True
        assert Fermat_test(num) == True
        assert Miller_Rabin_test(num) == True
コード例 #3
0
def main(args):
	logins, passwords = [], []
	login = args['l']
	login_dict_path = args['L']
	password = args['p']
	password_dict_path = args['P']
	num_threads = 3 
	url = args['target']
	method = args['m']
	reverse = args['reverse']
	
	
	# set brute force login(s) #
	if login_dict_path:
		login_dict = open(login_dict_path, 'r')
		logins = [login.replace('\n', '') for login in login_dict]
	elif login:
		logins.append(login)
	
	# set brute force password(s) #
	if password_dict_path:
		password_dict = open(password_dict_path, 'r')
		passwords = [passwd.replace('\n', '') for passwd in password_dict]
	elif password:
		passwords.append(password)

	# specify number of threads to use #
	if args['t']:
		num_threads = args['t']
	if login and password:
		num_threads = 1


	print('Starting brute force attack.')
	request_pattern = generate_request_pattern()
	request_pattern.url = url + request_pattern.query
	request_pattern.http_method = method
	if 'Cookie' not in request_pattern.headers.keys():
		print('Getting Cookie...')
		request_pattern.cookies = requests.get(request_pattern.url).cookies
		print('Done.')
	
	# brute force attack #
	bf.brute_force(request_pattern, logins, passwords, num_threads, reverse)
コード例 #4
0
    def test_brute_force_optmiization(self):

        print 'brute force optimized...'

        for (L, solutions) in self.TEST_DIGESTS.items():

            print "L=", L

            n = int( (sqrt(1 + 8 * len(L)) + 1) / 2 ) 
            (solution, iterations) = brute_force(list(L), n, 1)
            print 'found %s in %i iterations' % (solution, iterations)
            self.assertTrue(tuple(solution) in solutions)
コード例 #5
0
def bf(pattern):
    # account for errors (with regard to input from user)
    if text_to_search == "":
        result_label['text'] = "Please upload a .fna text file before proceeding."
    elif pattern_entry.get() == "" and pattern_from_file == "":
        result_label['text'] = "Please enter a search pattern or upload a .fna pattern file before proceeding."
    elif pattern_entry.get() != "" and pattern_from_file != "":
        result_label['text'] = "Please only enter a search pattern OR upload a .fna pattern file (do not do both)"
    else:
        if pattern_from_file != "":
            pattern = pattern_from_file
        start_time = time.time()
        result = brute_force(pattern, text_to_search)
        print("--- %s seconds ---" % (time.time() - start_time))
        result_label['text'] = "Brute Force Algoithm called with pattern " + pattern + "\nResults: " + result
コード例 #6
0
ファイル: test.py プロジェクト: CodeKontora/primality_tests
def test_on_negative_number():
    for num in range(1, -30, -1):
        assert brute_force(num) == False
        assert Wilson_test(num) == False
        assert Fermat_test(num) == False
        assert Miller_Rabin_test(num) == False
コード例 #7
0
ファイル: test.py プロジェクト: CodeKontora/primality_tests
def test_on_positive_number():
    for num in range(4, 1000, 1):
        assert brute_force(num) == Wilson_test(num) == Fermat_test(num) == Miller_Rabin_test(num)
コード例 #8
0
ファイル: test.py プロジェクト: CodeKontora/primality_tests
def test_on_even_number():
    for num in range(4, 30, 2):
        assert brute_force(num) == False
        assert Wilson_test(num) == False
        assert Fermat_test(num) == False
        assert Miller_Rabin_test(num) == False
コード例 #9
0
ファイル: test.py プロジェクト: CodeKontora/primality_tests
def test_on_searched_prime_number():
    prime_numbers = []
    for num in range(2, 51):
        prime_numbers.append(search_prime_number(bit_length=num))
    for num in prime_numbers:
        assert brute_force(num) == Fermat_test(num)
コード例 #10
0
    parser= ArgumentParser(description= "Regulartory Motifs")
    parser.add_argument("--input", default= "implanted.txt", help= "file of sequences")
    parser.add_argument("--k", type= int, default= 8, help= "k-mer length")
    parser.add_argument("--start", type= int, default= 0, help= "starting sequence")
    parser.add_argument("--end", type= int, default= 3, help= "ending sequence")
    parser.add_argument('--optimization', type= int, default= 0, help= "sets optimization level [0= bruteforce, 1= branchandbound")

    args= parser.parse_args()

    fh= open(args.input, "r")
    sequences= [line.replace('\n', '').upper() for line in fh.readlines()]
    fh.close()

    if args.optimization == 0:
    
        results= brute_force(sequences[args.start:args.end], args.k)
        if len(results):
            for result in results:
                (offset, pattern)= result
                print "Found motif %s at offset %s" % (pattern, offset)
        else:
            print "Could not find any motifs"

    elif args.optimization == 1:

        motif_search= MotifSearch(args.k)

        # list the sequence, position and pattern of each motif we found
        for (sequence, position) in zip(range(args.start, args.end), motif_search(sequences[args.start:args.end])):
             pattern= sequences[sequence][position:position + args.k]
             print "found motif", pattern, "at position", position, "in sequence", sequences[sequence]
コード例 #11
0
                        nargs='+',
                        default=[2, 2, 3, 3, 4, 5, 6, 7, 8, 10],
                        help='list of integers')

    args = parser.parse_args()
    optimization_level = args.optimization
    L = args.L

    print "Optmization Level: %s" % (optimization_level)
    print "L= %s" % (L)

    if optimization_level in (0, 1):

        n = int((sqrt(1 + 8 * len(L)) + 1) / 2)

        (X, iterations) = brute_force(L, n, optimization_level)

        output = "X = %s" % (X) if X else "No Solution"
        print "%s in %s iterations" % (output, iterations)

    elif optimization_level == 2:

        solutions = []
        partial_digest(L, solutions)
        print solutions
        for (iterations, X) in solutions:
            print "%s in %s iterations" % (X, iterations)

    else:
        print >> stderr, "invalid optimization level"
        exit(-1)
コード例 #12
0
    arr = i.read().splitlines()

arr.pop(0)
T = ''
T = T.join(arr)

with open(args.pattern, 'r') as p:
    brr = p.read().splitlines()

brr.pop(0)
P = ''
P = P.join(brr)

print("Running brute-force...")
start = timer()
pos, comp = brute_force(P, T)
bruteforce = timer() - start
if pos == -1:
    print("Could not find pattern in text")
else:
    print("Found pattern at position",
          pos + 1)  # adding 1 to pos because function returns 0-based index
print("Runtime was", round(bruteforce * 1000000), "microseconds. Performed",
      comp, "character comparisons")

print("\nRunning Knuth-Morris-Pratt...")
start = timer()
pos, comp = knuth_morris_pratt(T, P)
kmp = timer() - start
if pos == -1:
    print("Could not find pattern in text")
コード例 #13
0
ファイル: __init.py プロジェクト: Nikronic/Algorithm-Design
num_of_hospitals = [2, 2, 3, 4, 4]
capacities = 1

# timers
gsh_time = []  # galeshapley time
bruteforce_time = []  # brtute force time

for rc, hc in zip(num_of_residents, num_of_hospitals):
    res_pref, hos_pref, cap = random_prefs_generator(rc, hc, 1)

    start_time = time.time()
    groundtruth = extended_gale_shapley(hos_pref, res_pref, cap)
    gsh_time.append((time.time() - start_time))

    start_time = time.time()
    brute_force(rc, hc, groundtruth)
    bruteforce_time.append((time.time() - start_time))

for gsh, bf in zip(gsh_time, bruteforce_time):
    print("Gale shapley time ====>", gsh, "     Bruteforce time ====>", bf)

plt.plot(np.arange(1, 6), gsh_time, color='g', label='Gale-Shapley Time')
plt.plot(np.arange(1, 6),
         np.array(bruteforce_time) / 1000,
         color='r',
         linestyle='dashed',
         label='Bruteforce Time',
         alpha=0.5)
plt.xlabel('Average number of residents and hospitals')
plt.ylabel('Time consume in miliseconds')
plt.legend()