-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfactordb.py
142 lines (120 loc) · 3.94 KB
/
factordb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/python
__license__ = """
Copyright (c) 2017, {ihebski (S0ld1er)/Bugs_BunnyTeam}
All rights reserved.
"""
WARNINGS = 0
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
WHITE = '\033[97m'
RED = '\033[96m'
LIGHT = '\033[95m'
try:
import re
import requests
from bs4 import BeautifulSoup
import sys
import os
except Exception as err:
print("[!] "+str(err))
sys.exit(0)
status = {"C": "Composite, no factors known",
"CF": "Composite, factors known",
"FF": "Composite, fully factored",
"P": "Definitely prime",
"Prp": "Probably prime",
"U": "Unknown",
"Unit": "Just for 1",
"N": "This number is not in database (and was not added due to your settings)",
"*": "Added to database during this request"}
baseUrl = "http://factordb.com/"
def banner():
print(bcolors.OKBLUE +
"___________ __ ________ ___. "+bcolors.ENDC)
print(bcolors.HEADER +
"\_ _____/____ _____/ |_ __________\______ \\_ |__ "+bcolors.ENDC)
print(bcolors.HEADER +
" | __) \__ \ _/ ___\ __\/ _ \_ __ \ | \| __ \ "+bcolors.ENDC)
print(bcolors.HEADER +
' | \ / __ \\ \___| | ( <_> ) | \/ ` \ \_\ \''+bcolors.ENDC)
print(bcolors.HEADER +
" \___ / (____ /\___ >__| \____/|__| /_______ /___ /" + bcolors.ENDC)
print(bcolors.OKBLUE +
" \/ \/ \/ \/ \/ " + bcolors.ENDC)
print(bcolors.LIGHT + "================> https://github.com/ihebski/factordb")
print(bcolors.OKBLUE +
"===========================================> by S0ld1er | Bugs_Bunny \n")
def usage():
scr = os.path.basename(sys.argv[0])
banner()
print(bcolors.WARNING + "Usage: python factordb.py {n} \n")
def interact(n):
myVars = []
r = requests.get(baseUrl+"index.php?query="+n)
html = r.content
mylist = []
soup = BeautifulSoup(html, "lxml")
tables = soup.findAll("table")
for table in tables:
if table.findParent("table") is None:
for row in table.findAll("tr"):
cells = row.findAll("td")
mylist.append(str(cells))
data = mylist[3]
data = data.split(",")
soup2 = BeautifulSoup(data[0], "lxml")
for row in soup2.findAll("td"):
status = row.text # Get the status
links = []
soupLinks = BeautifulSoup(data[2], "lxml")
for row in soupLinks.findAll("a"):
links.append(row["href"])
l = len(links)
myVars.append([status, links[l-2], links[l-1]])
return myVars
def get_prime(p):
r = requests.get(baseUrl+p)
html = r.content
soup = BeautifulSoup(html, "lxml")
try:
value = soup.find('input', {'name': 'query'}).get('value')
return value
except:
print("Fail")
def start(argv):
if len(sys.argv) < 2:
usage()
sys.exit()
else:
main(argv[0])
def main(n):
s, p, q = interact(n)[0]
if p == q:
banner()
print(bcolors.WHITE + "Status :"+s+" => "+status[s]+"\n")
print(bcolors.HEADER+"n : "+n + "\n")
print(bcolors.OKBLUE + "length : "+str(len(n))+"\n")
else:
P = get_prime(p)
Q = get_prime(q)
banner()
print(bcolors.WHITE + "Status :"+s+" => "+status[s]+"\n")
print(bcolors.RED +
" n: {n} \n length : {len} \n".format(n=n, len=len(n)))
print(bcolors.WARNING +
" p: {P} \n length : {len} \n".format(P=P, len=len(P)))
print(bcolors.OKGREEN +
" q: {Q} \n length : {len} \n".format(Q=Q, len=len(Q)))
if __name__ == '__main__':
try:
start(sys.argv[1:])
except KeyboardInterrupt as err:
print("\n[!] By... :)")
sys.exit(0)