-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbitpeek.py
More file actions
100 lines (84 loc) Β· 3.67 KB
/
bitpeek.py
File metadata and controls
100 lines (84 loc) Β· 3.67 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import hashlib
import platform
import os
# Base58 setup
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[char]
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 clear_screen():
os.system("cls" if platform.system() == "Windows" else "clear")
def print_colored(text, color="white"):
print(text)
def get_address_type(version_hex: str) -> str:
version_map = {
"00": "P2PKH (mainnet)",
"05": "P2SH (mainnet)",
"6f": "P2PKH (testnet)",
"c4": "P2SH (testnet)"
}
return version_map.get(version_hex.lower(), "Unknown or non-standard")
def enrich_base58_analysis(version, payload):
version_expl = {
"00": "Standard Bitcoin mainnet address (P2PKH). Used for typical personal wallets.",
"05": "Pay-to-Script-Hash mainnet (P2SH). Often used in multisig wallets.",
"6f": "Testnet address (P2PKH). For development and testing purposes.",
"c4": "Testnet P2SH address. Used in testnet multisig wallets."
}
risk_level = "Low"
if version in ("6f", "c4"):
risk_level = "Testnet (Not for real transactions)"
elif len(set(payload)) < 5:
risk_level = "β Low entropy β possibly malformed"
hex_length = len(payload) // 2
return {
"version_info": version_expl.get(version, "Unknown or custom address version."),
"hash_length": hex_length,
"unique_chars": len(set(payload)),
"risk": risk_level
}
def decode_base58_address(address: str):
try:
decoded = base58_decode(address)
hex_full = decoded.hex()
version = decoded[0:1].hex()
payload = decoded[1:-4].hex()
checksum = decoded[-4:].hex()
calculated_checksum = hashlib.sha256(
hashlib.sha256(decoded[:-4]).digest()
).digest()[:4].hex()
print_colored("\nBase58 decoded (hex): " + hex_full, "white")
print_colored(f"Version byte: {version}", "yellow")
print_colored(f"Address type: {get_address_type(version)}", "white")
print_colored(f"Payload (RIPEMD-160): {payload}", "white")
print_colored(f"Checksum (from address): {checksum}", "cyan")
print_colored(f"Recalculated checksum: {calculated_checksum}", "cyan")
if checksum == calculated_checksum:
print_colored("\nβ Checksum is VALID", "green")
else:
print_colored("\nβ Checksum is INVALID", "red")
return
extra = enrich_base58_analysis(version, payload)
print_colored("\nπ Additional analysis:", "magenta")
print_colored(f"- Type Info: {extra['version_info']}", "white")
print_colored(f"- Payload Hash Length: {extra['hash_length']} bytes", "white")
print_colored(f"- Unique Payload Characters: {extra['unique_chars']}", "white")
print_colored(f"- Risk Level: {extra['risk']}", "red" if "β " in extra['risk'] else "green")
except Exception as e:
print_colored(f"Error: {e}", "red")
def main():
clear_screen()
print_colored("π BitPeek: Bitcoin Address Inspector", "cyan")
print_colored("βββββββββββββββββββββββββββββββββββββ", "cyan")
address = input("Enter Bitcoin address (Base58): ").strip()
decode_base58_address(address)
if __name__ == "__main__":
main()