-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbitpeek_web.py
More file actions
155 lines (139 loc) Β· 4.46 KB
/
bitpeek_web.py
File metadata and controls
155 lines (139 loc) Β· 4.46 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
from flask import Flask, render_template_string, request
import hashlib
app = Flask(__name__)
alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
base58_map = {char: index for index, char in enumerate(alphabet)}
def base58_decode(s):
num = 0
for char in s:
num *= 58
num += base58_map.get(char, 0)
combined = num.to_bytes((num.bit_length() + 7) // 8, 'big')
n_pad = len(s) - len(s.lstrip('1'))
return b'\x00' * n_pad + combined
def get_address_type(version_hex):
types = {
"00": "P2PKH (mainnet)",
"05": "P2SH (mainnet)",
"6f": "P2PKH (testnet)",
"c4": "P2SH (testnet)"
}
return types.get(version_hex.lower(), "Unknown")
def enrich_analysis(version, payload):
version_info = {
"00": "Standard Bitcoin mainnet address (P2PKH).",
"05": "Pay-to-Script-Hash mainnet (P2SH).",
"6f": "Testnet address (P2PKH).",
"c4": "Testnet P2SH address."
}
unique_chars = len(set(payload))
risk = "Low" if version not in ("6f", "c4") else "Testnet only"
if unique_chars < 5:
risk = "β Low entropy β risky"
ripemd160_hash = payload # payload jau yra RIPEMD160 hash (20 baitΕ³ public key hash)
return version_info.get(version, "Unknown type"), len(payload) // 2, unique_chars, risk, ripemd160_hash
def analyze_address(address):
try:
decoded = base58_decode(address)
version = decoded[0:1].hex()
payload = decoded[1:-4].hex()
checksum = decoded[-4:].hex()
calc_checksum = hashlib.sha256(hashlib.sha256(decoded[:-4]).digest()).digest()[:4].hex()
if checksum != calc_checksum:
return {"error": f"β Invalid checksum. Expected {calc_checksum}, got {checksum}"}
addr_type = get_address_type(version)
info, length, unique, risk, ripemd = enrich_analysis(version, payload)
return {
"status": "β Address is valid",
"type": addr_type,
"version": version,
"length": f"{length} bytes",
"unique": unique,
"risk": risk,
"info": info,
"ripemd160": ripemd
}
except Exception as e:
return {"error": f"β Error: {e}"}
HTML_TEMPLATE = """
<!doctype html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<title>BitPeek Web</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background-color: #0d1f2d;
color: #ffffff;
padding: 2rem;
}
h2 {
color: #ffffff;
}
form {
margin-bottom: 1rem;
}
input[type=text] {
width: 60%; padding: 0.5rem; font-size: 1rem;
border: 1px solid #ccc; border-radius: 4px;
}
input[type=submit] {
padding: 0.5rem 1rem; font-size: 1rem;
background-color: #1e90ff; color: white;
border: none; border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #0066cc;
}
table {
border-collapse: collapse; margin-top: 1rem;
background-color: #1b2a38; color: #ffffff;
}
th, td {
text-align: left; padding: 8px 12px;
border: 1px solid #555;
}
th {
background-color: #243b53;
font-weight: bold;
}
.error {
color: #ff4c4c; font-weight: bold;
}
</style>
</head>
<body>
<h2>BitPeek β Bitcoin Address Analyzer</h2>
<form method=post>
<input type=text name=address placeholder="Enter Base58 Bitcoin Address">
<input type=submit value=Analyze>
</form>
{% if result.error %}
<p class="error">{{ result.error }}</p>
{% elif result.status %}
<table>
<tr><th>Status</th><td>{{ result.status }}</td></tr>
<tr><th>Type</th><td>{{ result.type }}</td></tr>
<tr><th>Version byte</th><td>{{ result.version }}</td></tr>
<tr><th>Payload length</th><td>{{ result.length }}</td></tr>
<tr><th>Unique characters</th><td>{{ result.unique }}</td></tr>
<tr><th>Risk level</th><td>{{ result.risk }}</td></tr>
<tr><th>Info</th><td>{{ result.info }}</td></tr>
<tr><th>RIPEMD-160 hash</th><td>{{ result.ripemd160 }}</td></tr>
</table>
{% endif %}
</body>
</html>
"""
@app.route('/', methods=['GET', 'POST'])
def index():
result = {}
if request.method == 'POST':
address = request.form['address']
result = analyze_address(address)
return render_template_string(HTML_TEMPLATE, result=result)
if __name__ == '__main__':
app.run(debug=True)