├── Database ├── bitcoin.sql └── ethereum.sql ├── LICENSE ├── README.md ├── ScannerBTC ├── BTCsql.py ├── Start_BTCSQL.bat ├── btc.bf ├── btc.txt ├── secp256k1.dll ├── secp256k1.py └── secp256k1.so ├── ScannerETH ├── ETHsql.py ├── secp256k1.dll ├── secp256k1.py └── secp256k1.so ├── htdocs ├── balance.php ├── cog.gif ├── db.php └── indexbtc.php └── htdocsETH ├── cog.gif ├── eth_balance.php ├── eth_db.php └── indexeth.php /Database/bitcoin.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 5.2.0 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: Aug 16, 2022 at 10:59 PM 7 | -- Server version: 10.4.24-MariaDB 8 | -- PHP Version: 7.4.29 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | START TRANSACTION; 12 | SET time_zone = "+00:00"; 13 | 14 | 15 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 16 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 17 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 18 | /*!40101 SET NAMES utf8mb4 */; 19 | 20 | -- 21 | -- Database: `bitcoin` 22 | -- 23 | 24 | -- -------------------------------------------------------- 25 | 26 | -- 27 | -- Table structure for table `addresses` 28 | -- 29 | 30 | CREATE TABLE `addresses` ( 31 | `id` int(255) NOT NULL, 32 | `seed` varchar(255) DEFAULT NULL, 33 | `compressed` varchar(255) DEFAULT NULL, 34 | `uncompressed` varchar(255) DEFAULT NULL, 35 | `privatekey` varchar(255) DEFAULT NULL 36 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 37 | 38 | -- 39 | -- Indexes for dumped tables 40 | -- 41 | 42 | -- 43 | -- Indexes for table `addresses` 44 | -- 45 | ALTER TABLE `addresses` 46 | ADD PRIMARY KEY (`id`); 47 | 48 | -- 49 | -- AUTO_INCREMENT for dumped tables 50 | -- 51 | 52 | -- 53 | -- AUTO_INCREMENT for table `addresses` 54 | -- 55 | ALTER TABLE `addresses` 56 | MODIFY `id` int(255) NOT NULL AUTO_INCREMENT; 57 | COMMIT; 58 | 59 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 60 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 61 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 62 | -------------------------------------------------------------------------------- /Database/ethereum.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 5.2.0 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: Aug 16, 2022 at 10:59 PM 7 | -- Server version: 10.4.24-MariaDB 8 | -- PHP Version: 7.4.29 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | START TRANSACTION; 12 | SET time_zone = "+00:00"; 13 | 14 | 15 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 16 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 17 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 18 | /*!40101 SET NAMES utf8mb4 */; 19 | 20 | -- 21 | -- Database: `ethereum` 22 | -- 23 | 24 | -- -------------------------------------------------------- 25 | 26 | -- 27 | -- Table structure for table `addresses` 28 | -- 29 | 30 | CREATE TABLE `addresses` ( 31 | `id` int(255) NOT NULL, 32 | `Address` varchar(255) NOT NULL, 33 | `Privatekey` varchar(255) NOT NULL 34 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 35 | 36 | -- 37 | -- Indexes for dumped tables 38 | -- 39 | 40 | -- 41 | -- Indexes for table `addresses` 42 | -- 43 | ALTER TABLE `addresses` 44 | ADD PRIMARY KEY (`id`); 45 | 46 | -- 47 | -- AUTO_INCREMENT for dumped tables 48 | -- 49 | 50 | -- 51 | -- AUTO_INCREMENT for table `addresses` 52 | -- 53 | ALTER TABLE `addresses` 54 | MODIFY `id` int(255) NOT NULL AUTO_INCREMENT; 55 | COMMIT; 56 | 57 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 58 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 59 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Mizogg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Crypto-Database 2 | Bitcoin and Ethereum with SQL, Python, Xampp 3 | 4 | ![image](https://user-images.githubusercontent.com/88630056/184959992-fff9078c-c02f-4716-b70c-77dae8dcb0f4.png) 5 | 6 | https://www.apachefriends.org/download.html 7 | XAMPP for Windows 7.4.29, 8.0.19 & 8.1.6 8 | https://downloadsapachefriends.global.ssl.fastly.net/7.4.29/xampp-windows-x64-7.4.29-1-VC15-installer.exe?from_af=true 9 | 10 | XAMPP for Linux 7.4.29, 8.0.19 & 8.1.6 11 | https://downloadsapachefriends.global.ssl.fastly.net/7.4.29/xampp-linux-x64-7.4.29-1-installer.run?from_af=true 12 | 13 | Install once downloaded. 14 | 15 | ![image](https://user-images.githubusercontent.com/88630056/184960161-f89b7b4f-8f3b-4224-83cb-80c003f59767.png) 16 | 17 | 2. Delete The contents of C:\xampp\htdocs and replace with php files 18 | 19 | 3. Run Xmapp 20 | 21 | ![image](https://user-images.githubusercontent.com/88630056/184964846-205179dd-3900-48b9-9f4c-f6585429f519.png) 22 | 23 | Start Apache and MySQL open your webbrowser and go to http://localhost/phpmyadmin/ 24 | 25 | 4. Create new Database bitcoin 26 | 27 | 5.Table addresses 28 | With 5 Columns 29 | id int 255 primary 30 | seed var 255 31 | compressed var 255 32 | uncompressed var 255 33 | privatekey var 255 34 | 35 | 36 | Now database is ready we can store the data. We will use BTCsql.py 37 | 38 | pip install simplebloomfilter 39 | pip install bitarray==1.9.2 40 | pip install mysql-connector 41 | 42 | ![image](https://user-images.githubusercontent.com/88630056/184960476-99a3fb5d-97e7-45a8-abc0-144dbbac8d76.png) 43 | 1. bloomfilter database 44 | 2. btc txt database (mine has puzzles) 45 | 3. BTCsql.py the main orgram to scan and record results 46 | 4. Icelands library 47 | 5. easy start bat 48 | 49 | We can go to http://localhost/indexbtc.php to see the result or check what we have scanned. 50 | 51 | ![image](https://user-images.githubusercontent.com/88630056/184959731-c48faeb1-58c2-4e1b-8371-41712c2908c5.png) 52 | 53 | ## ETH Version 54 | 55 | ![image](https://user-images.githubusercontent.com/88630056/184963243-26753562-9ec1-488f-b977-13d3dfa6076f.png) 56 | 57 | ![image](https://user-images.githubusercontent.com/88630056/184963294-c929addf-3329-4b9f-8bbf-039aba66760f.png) 58 | 59 | Create Table ethereum 60 | With 3 Columns 61 | id int 255 primary 62 | Address var 255 63 | Privatekey var 255 64 | 65 | http://localhost/indexeth.php 66 | 67 | ![image](https://user-images.githubusercontent.com/88630056/184963443-8f1be9f7-b3be-463e-adc7-bc7693d298a4.png) 68 | -------------------------------------------------------------------------------- /ScannerBTC/BTCsql.py: -------------------------------------------------------------------------------- 1 | import secp256k1 2 | import mysql.connector 3 | from rich import print 4 | from bloomfilter import BloomFilter, ScalableBloomFilter, SizeGrowthRate 5 | from pathlib import Path 6 | import random 7 | 8 | mydb = mysql.connector.connect( 9 | host="localhost", 10 | user="root", 11 | password="", 12 | database="bitcoin" 13 | ) 14 | mycursor = mydb.cursor() 15 | 16 | with open("btc.txt","r") as m: #Your Address List mix of addresses .txt 17 | fill = m.read().split() 18 | fill= set(fill) 19 | 20 | bloombtc = Path(__file__).resolve() #Your Address List mix of addresses .bf 21 | ressbtc = bloombtc.parents[0] / 'btc.bf' 22 | with open(ressbtc, "rb") as fp: 23 | bloom_filter = BloomFilter.load(fp) 24 | 25 | def random_scan(): 26 | while True: 27 | dec =int(random.randrange(1073741823, 115792089237316195423570985008687907852837564279074904382605163141518161494336)) 28 | uaddr = secp256k1.privatekey_to_address(0, False, dec) 29 | caddr = secp256k1.privatekey_to_address(0, True, dec) 30 | HEX = "%064x" % dec 31 | sql = "INSERT INTO `addresses`( `seed`, `compressed`, `uncompressed`, `privatekey`) VALUES (%s, %s, %s, %s)" 32 | val = (dec, caddr, uaddr, HEX) 33 | mycursor.execute(sql,val) 34 | mydb.commit() 35 | print(uaddr, caddr, "record inserted.") 36 | if uaddr in fill or uaddr in bloom_filter: 37 | wifu = secp256k1.btc_pvk_to_wif(HEX, False) 38 | print('\nMatch Found UnCompressed') 39 | print('\nPrivatekey (dec): ', dec,'\nPrivatekey (hex): ', HEX, '\nPrivatekey UnCompressed: ', wifu, '\nPublic Address UnCompressed: ', uaddr) 40 | f=open("winner.txt","a") 41 | f.write('\nPrivatekey (dec): ' + str(dec)) 42 | f.write('\nPrivatekey (hex): ' + HEX) 43 | f.write('\nPrivatekey UnCompressed: ' + wifu) 44 | f.write('\nPublic Address UnCompressed: ' + uaddr) 45 | if caddr in fill or caddr in bloom_filter: 46 | wifc = secp256k1.btc_pvk_to_wif(HEX) 47 | print('\nMatch Found Compressed') 48 | print('\nPrivatekey (dec): ', dec,'\nPrivatekey (hex): ', HEX, '\nPrivatekey compressed: ', wifc, '\nPublic Address Compressed: ', caddr) 49 | f=open("winner.txt","a") 50 | f.write('\nPrivatekey (dec): ' + str(dec)) 51 | f.write('\nPrivatekey (hex): ' + HEX) 52 | f.write('\nPrivatekey compressed: ' + wifc) 53 | f.write('\nPublic Address Compressed: ' + caddr) 54 | 55 | 56 | 57 | def sequential_scan(): 58 | z=int(input("'start range Min 1-115792089237316195423570985008687907852837564279074904382605163141518161494335 -> ")) 59 | y=int(input("stop range Max 115792089237316195423570985008687907852837564279074904382605163141518161494336 -> ")) 60 | 61 | P = z 62 | while P>= 1 164 | result = Zero 165 | addend = P 166 | for bit in bits(k): 167 | if bit == 1: result=point_addition(result,addend) 168 | addend=point_doubling(addend) 169 | return result 170 | 171 | def _get_x_to_y(x_hex, is_even): 172 | ''' Input x_hex encoded as bytes and bool is_even. 32 bytes y of point output ''' 173 | res = (b'\x00') * 32 174 | secp256k1.get_x_to_y(x_hex.encode('utf8'), is_even, res) 175 | return res 176 | def get_x_to_y(x_hex, is_even): 177 | res = _get_x_to_y(x_hex, is_even) 178 | return bytes(bytearray(res)) 179 | 180 | def _point_increment(pubkey_bytes): 181 | res = (b'\x00') * 65 182 | secp256k1.point_increment(pubkey_bytes, res) 183 | return res 184 | def point_increment(pubkey_bytes): 185 | res = _point_increment(pubkey_bytes) 186 | return bytes(bytearray(res)) 187 | 188 | def _point_negation(pubkey_bytes): 189 | res = (b'\x00') * 65 190 | secp256k1.point_negation(pubkey_bytes, res) 191 | return res 192 | def point_negation(pubkey_bytes): 193 | res = _point_negation(pubkey_bytes) 194 | return bytes(bytearray(res)) 195 | 196 | def _point_doubling(pubkey_bytes): 197 | res = (b'\x00') * 65 198 | secp256k1.point_doubling(pubkey_bytes, res) 199 | return res 200 | def point_doubling(pubkey_bytes): 201 | res = _point_doubling(pubkey_bytes) 202 | return bytes(bytearray(res)) 203 | 204 | def init_P2_Group(pubkey_bytes): 205 | secp256k1.init_P2_Group(pubkey_bytes) 206 | 207 | def privatekey_to_coinaddress(coin_type, addr_type, iscompressed, pvk_int): 208 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 209 | if pvk_int < 0: pvk_int = N+pvk_int 210 | pass_int_value = fl(pvk_int).encode('utf8') 211 | res = secp256k1.privatekey_to_coinaddress(coin_type, addr_type, iscompressed, pass_int_value) 212 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 213 | secp256k1.free_memory(res) 214 | return addr 215 | 216 | def privatekey_to_address(addr_type, iscompressed, pvk_int): 217 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 218 | if pvk_int < 0: pvk_int = N+pvk_int 219 | pass_int_value = fl(pvk_int).encode('utf8') 220 | res = secp256k1.privatekey_to_address(addr_type, iscompressed, pass_int_value) 221 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 222 | secp256k1.free_memory(res) 223 | return addr 224 | 225 | def hash_to_address(addr_type, iscompressed, hash160_bytes): 226 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 227 | res = secp256k1.hash_to_address(addr_type, iscompressed, hash160_bytes) 228 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 229 | secp256k1.free_memory(res) 230 | return addr 231 | 232 | def pubkey_to_address(addr_type, iscompressed, pubkey_bytes): 233 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 234 | res = secp256k1.pubkey_to_address(addr_type, iscompressed, pubkey_bytes) 235 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 236 | secp256k1.free_memory(res) 237 | return addr 238 | 239 | def _privatekey_to_h160(addr_type, iscompressed, pvk_int): 240 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 241 | if pvk_int < 0: pvk_int = N+pvk_int 242 | pass_int_value = fl(pvk_int).encode('utf8') 243 | res = (b'\x00') * 20 244 | secp256k1.privatekey_to_h160(addr_type, iscompressed, pass_int_value, res) 245 | return res 246 | def privatekey_to_h160(addr_type, iscompressed, pvk_int): 247 | res = _privatekey_to_h160(addr_type, iscompressed, pvk_int) 248 | return bytes(bytearray(res)) 249 | 250 | def _privatekey_loop_h160(num, addr_type, iscompressed, pvk_int): 251 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 252 | if pvk_int < 0: pvk_int = N+pvk_int 253 | pass_int_value = fl(pvk_int).encode('utf8') 254 | res = (b'\x00') * (20 * num) 255 | secp256k1.privatekey_loop_h160(num, addr_type, iscompressed, pass_int_value, res) 256 | return res 257 | def privatekey_loop_h160(num, addr_type, iscompressed, pvk_int): 258 | if num <= 0: num = 1 259 | res = _privatekey_loop_h160(num, addr_type, iscompressed, pvk_int) 260 | return bytes(bytearray(res)) 261 | 262 | def _privatekey_loop_h160_sse(num, addr_type, iscompressed, pvk_int): 263 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 264 | if pvk_int < 0: pvk_int = N+pvk_int 265 | pass_int_value = fl(pvk_int).encode('utf8') 266 | res = (b'\x00') * (20 * num) 267 | secp256k1.privatekey_loop_h160_sse(num, addr_type, iscompressed, pass_int_value, res) 268 | return res 269 | def privatekey_loop_h160_sse(num, addr_type, iscompressed, pvk_int): 270 | if num <= 0: num = 1 271 | res = _privatekey_loop_h160_sse(num, addr_type, iscompressed, pvk_int) 272 | return bytes(bytearray(res)) 273 | 274 | def _pubkey_to_h160(addr_type, iscompressed, pubkey_bytes): 275 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 276 | res = (b'\x00') * 20 277 | secp256k1.pubkey_to_h160(addr_type, iscompressed, pubkey_bytes, res) 278 | return res 279 | def pubkey_to_h160(addr_type, iscompressed, pubkey_bytes): 280 | res = _pubkey_to_h160(addr_type, iscompressed, pubkey_bytes) 281 | return bytes(bytearray(res)) 282 | 283 | def _pub_endo1(pubkey_bytes): 284 | res = (b'\x00') * 65 285 | secp256k1.pub_endo1(pubkey_bytes, res) 286 | return res 287 | def pub_endo1(pubkey_bytes): 288 | res = _pub_endo1(pubkey_bytes) 289 | return bytes(bytearray(res)) 290 | 291 | def _pub_endo2(pubkey_bytes): 292 | res = (b'\x00') * 65 293 | secp256k1.pub_endo2(pubkey_bytes, res) 294 | return res 295 | def pub_endo2(pubkey_bytes): 296 | res = _pub_endo2(pubkey_bytes) 297 | return bytes(bytearray(res)) 298 | 299 | def b58py(data): 300 | B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" 301 | 302 | if data[0] == 0: 303 | return "1" + b58py(data[1:]) 304 | 305 | x = sum([v * (256 ** i) for i, v in enumerate(data[::-1])]) 306 | ret = "" 307 | while x > 0: 308 | ret = B58[x % 58] + ret 309 | x = x // 58 310 | 311 | return ret 312 | 313 | def b58_encode(inp_bytes): 314 | res = secp256k1.b58_encode(inp_bytes, len(inp_bytes)) 315 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 316 | secp256k1.free_memory(res) 317 | return addr 318 | 319 | def b58_decode(inp): 320 | res = secp256k1.b58_decode(inp.encode("utf-8")) 321 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 322 | secp256k1.free_memory(res) 323 | return addr 324 | 325 | def bech32_address_decode(addr, coin_type=0): 326 | ''' Input address in String format. Output h160 in hex string format 327 | [Note] p2wsh = bech32(sha256(21 + pubkey + ac)). So Decoding it not Needed ''' 328 | if len(addr) > 50: print('[Error] Bech32 p2wsh Not Supported. Result Truncated') 329 | h160 = (b'\x00') * 20 330 | secp256k1.bech32_address_decode(coin_type, addr.encode("utf-8"), h160) 331 | return bytes(bytearray(h160)).hex() 332 | 333 | def address_to_h160(p2pkh): 334 | ''' Input address in String format. Output h160 in hex string format''' 335 | h1 = b58_decode(p2pkh) 336 | return h1[2:-8] 337 | 338 | def btc_wif_to_pvk_hex(wif): 339 | pvk = '' 340 | if wif[0] == '5': 341 | pvk = b58_decode(wif)[2:-8] 342 | elif wif[0] in ['L', 'K']: 343 | pvk = b58_decode(wif)[2:-10] 344 | else: print('[Error] Incorrect WIF Key') 345 | return pvk 346 | 347 | def btc_wif_to_pvk_int(wif): 348 | pvk = '' 349 | pvk_hex = btc_wif_to_pvk_hex(wif) 350 | if pvk_hex != '': pvk = int(pvk_hex, 16) 351 | return pvk 352 | 353 | def btc_pvk_to_wif(pvk, is_compressed=True): 354 | ''' Input Privatekey can in any 1 of these [Integer] [Hex] [Bytes] form''' 355 | inp = '' 356 | suff = '01' if is_compressed == True else '' 357 | if type(pvk) in [int, str]: inp = bytes.fromhex('80' + fl(pvk) + suff) 358 | elif type(pvk) == bytes: inp = b'\x80' + fl(pvk) + bytes.fromhex(suff) 359 | else: print("[Error] Input Privatekey format [Integer] [Hex] [Bytes] allowed only") 360 | if inp != '': 361 | res = get_sha256(inp) 362 | res2 = get_sha256(res) 363 | return b58_encode(inp + res2[:4]) 364 | else: return inp 365 | 366 | def checksum(inp): 367 | ''' Input string output double sha256 checksum 4 bytes''' 368 | res = get_sha256(inp) 369 | res2 = get_sha256(res) 370 | return res2[:4] 371 | 372 | def fl(sstr, length=64): 373 | ''' Fill input to exact 32 bytes. If input is int or str the return is str. if input is bytes return is bytes''' 374 | if type(sstr) == int: fixed = hex(sstr)[2:].zfill(length) 375 | elif type(sstr) == str: fixed = sstr[2:].zfill(length) if sstr[:2].lower() == '0x' else sstr.zfill(length) 376 | elif type(sstr) == bytes: fixed = (b'\x00') * (32 - len(sstr)) + sstr 377 | else: print("[Error] Input format [Integer] [Hex] [Bytes] allowed only. Detected : ", type(sstr)) 378 | return fixed 379 | 380 | def pbkdf2_hmac_sha512_dll(words): 381 | seed_bytes = (b'\x00') * 64 382 | # words = 'good push broken people salad bar mad squirrel joy dismiss merge jeans token wear boring manual doll near sniff turtle sunset lend invest foil' 383 | secp256k1.pbkdf2_hmac_sha512_dll(seed_bytes, words.encode("utf-8"), len(words)) 384 | return seed_bytes 385 | 386 | def pbkdf2_hmac_sha512_list(words_list): 387 | ''' strength is [12, 18, 24]. words_list is a list of strings with each line having valid mnemonics''' 388 | wl = len(words_list) 389 | strength = len(words_list[0].split()) 390 | words = ' '.join(words_list) 391 | seed_bytes = (b'\x00') * (64 * wl) 392 | # words = 'good push broken people salad bar mad squirrel joy dismiss merge jeans token wear boring manual doll near sniff turtle sunset lend invest foil' 393 | secp256k1.pbkdf2_hmac_sha512_list(seed_bytes, words.encode("utf-8"), len(words), strength, wl) 394 | return seed_bytes 395 | 396 | def get_sha256(input_bytes): 397 | digest_bytes = (b'\x00') * 32 398 | if type(input_bytes) == str: input_bytes = input_bytes.encode("utf-8") 399 | # MiniKey example 400 | secp256k1.get_sha256(input_bytes, len(input_bytes), digest_bytes) 401 | return digest_bytes 402 | 403 | def create_baby_table(start_value, end_value): 404 | res = (b'\x00') * ((1+end_value-start_value) * 32) 405 | secp256k1.create_baby_table(start_value, end_value, res) 406 | return bytes(bytearray(res)) 407 | 408 | def _point_addition(pubkey1_bytes, pubkey2_bytes): 409 | res = (b'\x00') * 65 410 | secp256k1.point_addition(pubkey1_bytes, pubkey2_bytes, res) 411 | return res 412 | def point_addition(pubkey1_bytes, pubkey2_bytes): 413 | res = _point_addition(pubkey1_bytes, pubkey2_bytes) 414 | return bytes(bytearray(res)) 415 | 416 | def _point_subtraction(pubkey1_bytes, pubkey2_bytes): 417 | res = (b'\x00') * 65 418 | secp256k1.point_subtraction(pubkey1_bytes, pubkey2_bytes, res) 419 | return res 420 | def point_subtraction(pubkey1_bytes, pubkey2_bytes): 421 | res = _point_subtraction(pubkey1_bytes, pubkey2_bytes) 422 | return bytes(bytearray(res)) 423 | 424 | def _point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes): 425 | res = (b'\x00') * (65 * num) 426 | secp256k1.point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes, res) 427 | return res 428 | def point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes): 429 | ''' Continuously subtracting point2 into point1 in a loop of num times. 430 | Output is array of pubkeys P1-P2, P1-2P2, P1-3P2, P1-4P2....''' 431 | if num <= 0: num = 1 432 | res = _point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes) 433 | return bytes(bytearray(res)) 434 | 435 | def _point_loop_addition(num, pubkey1_bytes, pubkey2_bytes): 436 | res = (b'\x00') * (65 * num) 437 | secp256k1.point_loop_addition(num, pubkey1_bytes, pubkey2_bytes, res) 438 | return res 439 | def point_loop_addition(num, pubkey1_bytes, pubkey2_bytes): 440 | ''' Continuously adding point2 into point1 in a loop of num times. 441 | Output is array of pubkeys P1+P2, P1+2P2, P1+3P2, P1+4P2....''' 442 | if num <= 0: num = 1 443 | res = _point_loop_addition(num, pubkey1_bytes, pubkey2_bytes) 444 | return bytes(bytearray(res)) 445 | 446 | def _point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes): 447 | res = (b'\x00') * (65 * num) 448 | secp256k1.point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes, res) 449 | return res 450 | def point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes): 451 | ''' Adding two array of points of equal length. ''' 452 | if num <= 0: num = 1 453 | res = _point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes) 454 | return bytes(bytearray(res)) 455 | 456 | def _point_sequential_increment_P2(num, pubkey1_bytes): 457 | res = (b'\x00') * (65 * num) 458 | secp256k1.point_sequential_increment_P2(num, pubkey1_bytes, res) 459 | return res 460 | def point_sequential_increment_P2(num, pubkey1_bytes): 461 | ''' This is the fastest implementation to add point P2 in the given Point sequentially.''' 462 | if num <= 0: num = 1 463 | res = _point_sequential_increment_P2(num, pubkey1_bytes) 464 | return bytes(bytearray(res)) 465 | 466 | def _point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu): 467 | res = (b'\x00') * (65 * num) 468 | secp256k1.point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu, res) 469 | return res 470 | def point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu=os.cpu_count()): 471 | ''' This is the fastest multi CPU implementation to add point P2 in the given Point sequentially. Threads are Not optimised yet''' 472 | if num <= 0: num = 1 473 | res = _point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu) 474 | return bytes(bytearray(res)) 475 | 476 | def _point_sequential_increment(num, pubkey1_bytes): 477 | res = (b'\x00') * (65 * num) 478 | secp256k1.point_sequential_increment(num, pubkey1_bytes, res) 479 | return res 480 | def point_sequential_increment(num, pubkey1_bytes): 481 | ''' This is the fastest implementation using G''' 482 | if num <= 0: num = 1 483 | res = _point_sequential_increment(num, pubkey1_bytes) 484 | return bytes(bytearray(res)) 485 | 486 | def _point_sequential_decrement(num, pubkey1_bytes): 487 | res = (b'\x00') * (65 * num) 488 | secp256k1.point_sequential_decrement(num, pubkey1_bytes, res) 489 | return res 490 | def point_sequential_decrement(num, pubkey1_bytes): 491 | ''' This is the fastest implementation using -G.''' 492 | if num <= 0: num = 1 493 | res = _point_sequential_decrement(num, pubkey1_bytes) 494 | return bytes(bytearray(res)) 495 | 496 | def pubkey_to_ETH_address(pubkey_bytes): 497 | ''' 65 Upub bytes input. Output is 20 bytes ETH address lowercase with 0x as hex string''' 498 | xy = pubkey_bytes[1:] 499 | res = secp256k1.pubkeyxy_to_ETH_address(xy) 500 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 501 | secp256k1.free_memory(res) 502 | return '0x'+addr 503 | 504 | def _pubkey_to_ETH_address_bytes(xy): 505 | res = (b'\x00') * 20 506 | secp256k1.pubkeyxy_to_ETH_address_bytes(xy, res) 507 | return res 508 | def pubkey_to_ETH_address_bytes(pubkey_bytes): 509 | ''' 65 Upub bytes input. Output is 20 bytes ETH address lowercase without 0x''' 510 | xy = pubkey_bytes[1:] 511 | res = _pubkey_to_ETH_address_bytes(xy) 512 | return bytes(bytearray(res)) 513 | 514 | def privatekey_to_ETH_address(pvk_int): 515 | ''' Privatekey Integer value passed to function. Output is 20 bytes ETH address lowercase with 0x as hex string''' 516 | if pvk_int < 0: pvk_int = N+pvk_int 517 | pass_int_value = fl(pvk_int).encode('utf8') 518 | res = secp256k1.privatekey_to_ETH_address(pass_int_value) 519 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 520 | secp256k1.free_memory(res) 521 | return '0x'+addr 522 | 523 | def _privatekey_to_ETH_address_bytes(pass_int_value): 524 | res = (b'\x00') * 20 525 | secp256k1.privatekey_to_ETH_address_bytes(pass_int_value, res) 526 | return res 527 | def privatekey_to_ETH_address_bytes(pvk_int): 528 | ''' Privatekey Integer value passed to function. Output is 20 bytes ETH address lowercase without 0x''' 529 | if pvk_int < 0: pvk_int = N+pvk_int 530 | pass_int_value = fl(pvk_int).encode('utf8') 531 | res = _privatekey_to_ETH_address_bytes(pass_int_value) 532 | return bytes(bytearray(res)) 533 | 534 | def privatekey_group_to_ETH_address(pvk_int, m): 535 | ''' Starting Privatekey Integer value passed to function as pvk_int. 536 | Integer m is, how many times sequential increment is done from the starting key. 537 | Output is bytes 20*m of ETH address lowercase without 0x as hex string''' 538 | if m<=0: m = 1 539 | if pvk_int < 0: pvk_int = N+pvk_int 540 | start_pvk = fl(pvk_int).encode('utf8') 541 | res = secp256k1.privatekey_group_to_ETH_address(start_pvk, m) 542 | addrlist = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 543 | secp256k1.free_memory(res) 544 | return addrlist 545 | 546 | def _privatekey_group_to_ETH_address_bytes(start_pvk, m): 547 | res = (b'\x00') * (20 * m) 548 | secp256k1.privatekey_group_to_ETH_address_bytes(start_pvk, m, res) 549 | return res 550 | def privatekey_group_to_ETH_address_bytes(pvk_int, m): 551 | ''' Starting Privatekey Integer value passed to function as pvk_int. 552 | Integer m is, how many times sequential increment is done from the starting key. 553 | Output is bytes 20*m of ETH address lowercase without 0x''' 554 | if m<=0: m = 1 555 | if pvk_int < 0: pvk_int = N+pvk_int 556 | start_pvk = fl(pvk_int).encode('utf8') 557 | res = _privatekey_group_to_ETH_address_bytes(start_pvk, m) 558 | return bytes(bytearray(res)) 559 | 560 | def bloom_check_add_mcpu(bigbuff, num_items, sz, check_add, bloom_bits, bloom_hashes, bloom_filter): 561 | found_array = (b'\x00') * num_items 562 | # sz = 32; check_add = 0 for check and 1 for add 563 | secp256k1.bloom_check_add_mcpu(bigbuff, num_items, found_array, sz, check_add, bloom_bits, bloom_hashes, bloom_filter) 564 | return found_array 565 | 566 | def to_cpub(pub_hex): 567 | P = pub_hex 568 | if len(pub_hex) > 70: 569 | P = '02' + pub_hex[2:66] if int(pub_hex[66:],16)%2 == 0 else '03' + pub_hex[2:66] 570 | return P 571 | 572 | def point_to_cpub(pubkey_bytes): 573 | P = pubkey_bytes.hex() 574 | if len(P) > 70: 575 | P = '02' + P[2:66] if int(P[66:],16)%2 == 0 else '03' + P[2:66] 576 | return P 577 | 578 | def pub2upub(pub_hex): 579 | ''' Covert [C or U] pubkey to Point''' 580 | x = pub_hex[2:66] 581 | if len(pub_hex) < 70: 582 | y = get_x_to_y(x, int(pub_hex[:2],16)%2 == 0).hex() 583 | else: 584 | y = pub_hex[66:].zfill(64) 585 | return bytes.fromhex('04'+ x + y) 586 | 587 | def bloom_para(_items, _fp = 0.000001): 588 | _bits = math.ceil((_items * math.log(_fp)) / math.log(1 / pow(2, math.log(2)))) 589 | if _bits % 8: _bits = 8*(1 + (_bits//8)) 590 | _hashes = round((_bits / _items) * math.log(2)) 591 | return _bits, _hashes 592 | 593 | def Fill_in_bloom(inp_list, _fp = 0.000001): 594 | _bits, _hashes = bloom_para(len(inp_list), _fp) 595 | _bf = (b'\x00') * (_bits//8) 596 | for line in inp_list: 597 | if type(line) != bytes: tt = str(line).encode("utf-8") 598 | else: tt = line 599 | res = secp256k1.bloom_check_add(tt, len(tt), 1, _bits, _hashes, _bf) # 1 = Add 600 | del res 601 | return _bits, _hashes, _bf 602 | 603 | def dump_bloom_file(output_bloom_file_name, _bits, _hashes, _bf): 604 | with open(output_bloom_file_name, 'wb') as f: 605 | pickle.dump((_bits, _hashes, _bf), f) 606 | 607 | def read_bloom_file(bloom_file_name): 608 | '''It will return the 3 output as _bits, _hashes, _bf''' 609 | with open(bloom_file_name, 'rb') as f: 610 | return pickle.load(f) 611 | 612 | def check_in_bloom(this_line, _bits, _hashes, _bf): 613 | if type(this_line) != bytes: tt = str(this_line).encode("utf-8") 614 | else: tt = this_line 615 | if secp256k1.bloom_check_add(tt, len(tt), 0, _bits, _hashes, _bf) > 0: return True 616 | else: return False 617 | 618 | def prepare_bin_file_work(in_file, out_file, lower = False): 619 | use0x = False 620 | inp_list = [line.split()[0].lower() if lower else line.split()[0] for line in open(in_file,'r')] 621 | if inp_list[0][:2] == '0x': use0x = True 622 | 623 | with open(out_file, 'wb') as f: 624 | if use0x: 625 | inp_list = [line[2:] for line in inp_list] 626 | inp_list.sort() 627 | for line in inp_list: 628 | f.write(bytes.fromhex(line)) 629 | 630 | def prepare_bin_file(in_file, out_file, overwrite = False, lower = False): 631 | 632 | if os.path.isfile(out_file) == False: 633 | prepare_bin_file_work(in_file, out_file, lower) 634 | 635 | else: 636 | if not overwrite: 637 | print(f'[+] File {out_file} already exist. It will be used as it is...') 638 | 639 | else: 640 | print(f'[+] File {out_file} already exist. Overwriting it...') 641 | prepare_bin_file_work(in_file, out_file) 642 | 643 | def Load_data_to_memory(input_bin_file, verbose = False): 644 | '''input_bin_file is sorted h160 data of 20 bytes each element. 645 | ETH address can also work without 0x if sorted binary format''' 646 | secp256k1.Load_data_to_memory(input_bin_file.encode("utf-8"), verbose) 647 | 648 | 649 | def check_collision(h160): 650 | ''' h160 is the 20 byte hash to check for collision in data, already loaded in RAM. 651 | Use the function Load_data_to_memory before calling this check''' 652 | 653 | found = secp256k1.check_collision(h160) 654 | return found 655 | -------------------------------------------------------------------------------- /ScannerBTC/secp256k1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mizogg/Crypto-Database/8016974b32f8eaaa9112113f369e7f1dea1d5a97/ScannerBTC/secp256k1.so -------------------------------------------------------------------------------- /ScannerETH/ETHsql.py: -------------------------------------------------------------------------------- 1 | import secp256k1 2 | import mysql.connector 3 | from rich import print 4 | import random 5 | 6 | mydb = mysql.connector.connect( 7 | host="localhost", 8 | user="root", 9 | password="", 10 | database="ethereum" 11 | ) 12 | mycursor = mydb.cursor() 13 | def random_scan(): 14 | while True: 15 | dec =int(random.randrange(1, 115792089237316195423570985008687907852837564279074904382605163141518161494336)) 16 | addr = secp256k1.privatekey_to_ETH_address(dec) 17 | HEX = "%064x" % dec 18 | sql = "INSERT INTO `addresses`( `address`, `privatekey`) VALUES (%s, %s)" 19 | val = (addr, HEX) 20 | mycursor.execute(sql,val) 21 | mydb.commit() 22 | print(addr, HEX, "record inserted.") 23 | 24 | 25 | 26 | def sequential_scan(): 27 | z=int(input("'start range Min 1-115792089237316195423570985008687907852837564279074904382605163141518161494335 -> ")) 28 | y=int(input("stop range Max 115792089237316195423570985008687907852837564279074904382605163141518161494336 -> ")) 29 | 30 | P = z 31 | while P>= 1 164 | result = Zero 165 | addend = P 166 | for bit in bits(k): 167 | if bit == 1: result=point_addition(result,addend) 168 | addend=point_doubling(addend) 169 | return result 170 | 171 | def _get_x_to_y(x_hex, is_even): 172 | ''' Input x_hex encoded as bytes and bool is_even. 32 bytes y of point output ''' 173 | res = (b'\x00') * 32 174 | secp256k1.get_x_to_y(x_hex.encode('utf8'), is_even, res) 175 | return res 176 | def get_x_to_y(x_hex, is_even): 177 | res = _get_x_to_y(x_hex, is_even) 178 | return bytes(bytearray(res)) 179 | 180 | def _point_increment(pubkey_bytes): 181 | res = (b'\x00') * 65 182 | secp256k1.point_increment(pubkey_bytes, res) 183 | return res 184 | def point_increment(pubkey_bytes): 185 | res = _point_increment(pubkey_bytes) 186 | return bytes(bytearray(res)) 187 | 188 | def _point_negation(pubkey_bytes): 189 | res = (b'\x00') * 65 190 | secp256k1.point_negation(pubkey_bytes, res) 191 | return res 192 | def point_negation(pubkey_bytes): 193 | res = _point_negation(pubkey_bytes) 194 | return bytes(bytearray(res)) 195 | 196 | def _point_doubling(pubkey_bytes): 197 | res = (b'\x00') * 65 198 | secp256k1.point_doubling(pubkey_bytes, res) 199 | return res 200 | def point_doubling(pubkey_bytes): 201 | res = _point_doubling(pubkey_bytes) 202 | return bytes(bytearray(res)) 203 | 204 | def init_P2_Group(pubkey_bytes): 205 | secp256k1.init_P2_Group(pubkey_bytes) 206 | 207 | def privatekey_to_coinaddress(coin_type, addr_type, iscompressed, pvk_int): 208 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 209 | if pvk_int < 0: pvk_int = N+pvk_int 210 | pass_int_value = fl(pvk_int).encode('utf8') 211 | res = secp256k1.privatekey_to_coinaddress(coin_type, addr_type, iscompressed, pass_int_value) 212 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 213 | secp256k1.free_memory(res) 214 | return addr 215 | 216 | def privatekey_to_address(addr_type, iscompressed, pvk_int): 217 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 218 | if pvk_int < 0: pvk_int = N+pvk_int 219 | pass_int_value = fl(pvk_int).encode('utf8') 220 | res = secp256k1.privatekey_to_address(addr_type, iscompressed, pass_int_value) 221 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 222 | secp256k1.free_memory(res) 223 | return addr 224 | 225 | def hash_to_address(addr_type, iscompressed, hash160_bytes): 226 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 227 | res = secp256k1.hash_to_address(addr_type, iscompressed, hash160_bytes) 228 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 229 | secp256k1.free_memory(res) 230 | return addr 231 | 232 | def pubkey_to_address(addr_type, iscompressed, pubkey_bytes): 233 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 234 | res = secp256k1.pubkey_to_address(addr_type, iscompressed, pubkey_bytes) 235 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 236 | secp256k1.free_memory(res) 237 | return addr 238 | 239 | def _privatekey_to_h160(addr_type, iscompressed, pvk_int): 240 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 241 | if pvk_int < 0: pvk_int = N+pvk_int 242 | pass_int_value = fl(pvk_int).encode('utf8') 243 | res = (b'\x00') * 20 244 | secp256k1.privatekey_to_h160(addr_type, iscompressed, pass_int_value, res) 245 | return res 246 | def privatekey_to_h160(addr_type, iscompressed, pvk_int): 247 | res = _privatekey_to_h160(addr_type, iscompressed, pvk_int) 248 | return bytes(bytearray(res)) 249 | 250 | def _privatekey_loop_h160(num, addr_type, iscompressed, pvk_int): 251 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 252 | if pvk_int < 0: pvk_int = N+pvk_int 253 | pass_int_value = fl(pvk_int).encode('utf8') 254 | res = (b'\x00') * (20 * num) 255 | secp256k1.privatekey_loop_h160(num, addr_type, iscompressed, pass_int_value, res) 256 | return res 257 | def privatekey_loop_h160(num, addr_type, iscompressed, pvk_int): 258 | if num <= 0: num = 1 259 | res = _privatekey_loop_h160(num, addr_type, iscompressed, pvk_int) 260 | return bytes(bytearray(res)) 261 | 262 | def _privatekey_loop_h160_sse(num, addr_type, iscompressed, pvk_int): 263 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 264 | if pvk_int < 0: pvk_int = N+pvk_int 265 | pass_int_value = fl(pvk_int).encode('utf8') 266 | res = (b'\x00') * (20 * num) 267 | secp256k1.privatekey_loop_h160_sse(num, addr_type, iscompressed, pass_int_value, res) 268 | return res 269 | def privatekey_loop_h160_sse(num, addr_type, iscompressed, pvk_int): 270 | if num <= 0: num = 1 271 | res = _privatekey_loop_h160_sse(num, addr_type, iscompressed, pvk_int) 272 | return bytes(bytearray(res)) 273 | 274 | def _pubkey_to_h160(addr_type, iscompressed, pubkey_bytes): 275 | # type = 0 [p2pkh], 1 [p2sh], 2 [bech32] 276 | res = (b'\x00') * 20 277 | secp256k1.pubkey_to_h160(addr_type, iscompressed, pubkey_bytes, res) 278 | return res 279 | def pubkey_to_h160(addr_type, iscompressed, pubkey_bytes): 280 | res = _pubkey_to_h160(addr_type, iscompressed, pubkey_bytes) 281 | return bytes(bytearray(res)) 282 | 283 | def _pub_endo1(pubkey_bytes): 284 | res = (b'\x00') * 65 285 | secp256k1.pub_endo1(pubkey_bytes, res) 286 | return res 287 | def pub_endo1(pubkey_bytes): 288 | res = _pub_endo1(pubkey_bytes) 289 | return bytes(bytearray(res)) 290 | 291 | def _pub_endo2(pubkey_bytes): 292 | res = (b'\x00') * 65 293 | secp256k1.pub_endo2(pubkey_bytes, res) 294 | return res 295 | def pub_endo2(pubkey_bytes): 296 | res = _pub_endo2(pubkey_bytes) 297 | return bytes(bytearray(res)) 298 | 299 | def b58py(data): 300 | B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" 301 | 302 | if data[0] == 0: 303 | return "1" + b58py(data[1:]) 304 | 305 | x = sum([v * (256 ** i) for i, v in enumerate(data[::-1])]) 306 | ret = "" 307 | while x > 0: 308 | ret = B58[x % 58] + ret 309 | x = x // 58 310 | 311 | return ret 312 | 313 | def b58_encode(inp_bytes): 314 | res = secp256k1.b58_encode(inp_bytes, len(inp_bytes)) 315 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 316 | secp256k1.free_memory(res) 317 | return addr 318 | 319 | def b58_decode(inp): 320 | res = secp256k1.b58_decode(inp.encode("utf-8")) 321 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 322 | secp256k1.free_memory(res) 323 | return addr 324 | 325 | def bech32_address_decode(addr, coin_type=0): 326 | ''' Input address in String format. Output h160 in hex string format 327 | [Note] p2wsh = bech32(sha256(21 + pubkey + ac)). So Decoding it not Needed ''' 328 | if len(addr) > 50: print('[Error] Bech32 p2wsh Not Supported. Result Truncated') 329 | h160 = (b'\x00') * 20 330 | secp256k1.bech32_address_decode(coin_type, addr.encode("utf-8"), h160) 331 | return bytes(bytearray(h160)).hex() 332 | 333 | def address_to_h160(p2pkh): 334 | ''' Input address in String format. Output h160 in hex string format''' 335 | h1 = b58_decode(p2pkh) 336 | return h1[2:-8] 337 | 338 | def btc_wif_to_pvk_hex(wif): 339 | pvk = '' 340 | if wif[0] == '5': 341 | pvk = b58_decode(wif)[2:-8] 342 | elif wif[0] in ['L', 'K']: 343 | pvk = b58_decode(wif)[2:-10] 344 | else: print('[Error] Incorrect WIF Key') 345 | return pvk 346 | 347 | def btc_wif_to_pvk_int(wif): 348 | pvk = '' 349 | pvk_hex = btc_wif_to_pvk_hex(wif) 350 | if pvk_hex != '': pvk = int(pvk_hex, 16) 351 | return pvk 352 | 353 | def btc_pvk_to_wif(pvk, is_compressed=True): 354 | ''' Input Privatekey can in any 1 of these [Integer] [Hex] [Bytes] form''' 355 | inp = '' 356 | suff = '01' if is_compressed == True else '' 357 | if type(pvk) in [int, str]: inp = bytes.fromhex('80' + fl(pvk) + suff) 358 | elif type(pvk) == bytes: inp = b'\x80' + fl(pvk) + bytes.fromhex(suff) 359 | else: print("[Error] Input Privatekey format [Integer] [Hex] [Bytes] allowed only") 360 | if inp != '': 361 | res = get_sha256(inp) 362 | res2 = get_sha256(res) 363 | return b58_encode(inp + res2[:4]) 364 | else: return inp 365 | 366 | def checksum(inp): 367 | ''' Input string output double sha256 checksum 4 bytes''' 368 | res = get_sha256(inp) 369 | res2 = get_sha256(res) 370 | return res2[:4] 371 | 372 | def fl(sstr, length=64): 373 | ''' Fill input to exact 32 bytes. If input is int or str the return is str. if input is bytes return is bytes''' 374 | if type(sstr) == int: fixed = hex(sstr)[2:].zfill(length) 375 | elif type(sstr) == str: fixed = sstr[2:].zfill(length) if sstr[:2].lower() == '0x' else sstr.zfill(length) 376 | elif type(sstr) == bytes: fixed = (b'\x00') * (32 - len(sstr)) + sstr 377 | else: print("[Error] Input format [Integer] [Hex] [Bytes] allowed only. Detected : ", type(sstr)) 378 | return fixed 379 | 380 | def pbkdf2_hmac_sha512_dll(words): 381 | seed_bytes = (b'\x00') * 64 382 | # words = 'good push broken people salad bar mad squirrel joy dismiss merge jeans token wear boring manual doll near sniff turtle sunset lend invest foil' 383 | secp256k1.pbkdf2_hmac_sha512_dll(seed_bytes, words.encode("utf-8"), len(words)) 384 | return seed_bytes 385 | 386 | def pbkdf2_hmac_sha512_list(words_list): 387 | ''' strength is [12, 18, 24]. words_list is a list of strings with each line having valid mnemonics''' 388 | wl = len(words_list) 389 | strength = len(words_list[0].split()) 390 | words = ' '.join(words_list) 391 | seed_bytes = (b'\x00') * (64 * wl) 392 | # words = 'good push broken people salad bar mad squirrel joy dismiss merge jeans token wear boring manual doll near sniff turtle sunset lend invest foil' 393 | secp256k1.pbkdf2_hmac_sha512_list(seed_bytes, words.encode("utf-8"), len(words), strength, wl) 394 | return seed_bytes 395 | 396 | def get_sha256(input_bytes): 397 | digest_bytes = (b'\x00') * 32 398 | if type(input_bytes) == str: input_bytes = input_bytes.encode("utf-8") 399 | # MiniKey example 400 | secp256k1.get_sha256(input_bytes, len(input_bytes), digest_bytes) 401 | return digest_bytes 402 | 403 | def create_baby_table(start_value, end_value): 404 | res = (b'\x00') * ((1+end_value-start_value) * 32) 405 | secp256k1.create_baby_table(start_value, end_value, res) 406 | return bytes(bytearray(res)) 407 | 408 | def _point_addition(pubkey1_bytes, pubkey2_bytes): 409 | res = (b'\x00') * 65 410 | secp256k1.point_addition(pubkey1_bytes, pubkey2_bytes, res) 411 | return res 412 | def point_addition(pubkey1_bytes, pubkey2_bytes): 413 | res = _point_addition(pubkey1_bytes, pubkey2_bytes) 414 | return bytes(bytearray(res)) 415 | 416 | def _point_subtraction(pubkey1_bytes, pubkey2_bytes): 417 | res = (b'\x00') * 65 418 | secp256k1.point_subtraction(pubkey1_bytes, pubkey2_bytes, res) 419 | return res 420 | def point_subtraction(pubkey1_bytes, pubkey2_bytes): 421 | res = _point_subtraction(pubkey1_bytes, pubkey2_bytes) 422 | return bytes(bytearray(res)) 423 | 424 | def _point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes): 425 | res = (b'\x00') * (65 * num) 426 | secp256k1.point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes, res) 427 | return res 428 | def point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes): 429 | ''' Continuously subtracting point2 into point1 in a loop of num times. 430 | Output is array of pubkeys P1-P2, P1-2P2, P1-3P2, P1-4P2....''' 431 | if num <= 0: num = 1 432 | res = _point_loop_subtraction(num, pubkey1_bytes, pubkey2_bytes) 433 | return bytes(bytearray(res)) 434 | 435 | def _point_loop_addition(num, pubkey1_bytes, pubkey2_bytes): 436 | res = (b'\x00') * (65 * num) 437 | secp256k1.point_loop_addition(num, pubkey1_bytes, pubkey2_bytes, res) 438 | return res 439 | def point_loop_addition(num, pubkey1_bytes, pubkey2_bytes): 440 | ''' Continuously adding point2 into point1 in a loop of num times. 441 | Output is array of pubkeys P1+P2, P1+2P2, P1+3P2, P1+4P2....''' 442 | if num <= 0: num = 1 443 | res = _point_loop_addition(num, pubkey1_bytes, pubkey2_bytes) 444 | return bytes(bytearray(res)) 445 | 446 | def _point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes): 447 | res = (b'\x00') * (65 * num) 448 | secp256k1.point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes, res) 449 | return res 450 | def point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes): 451 | ''' Adding two array of points of equal length. ''' 452 | if num <= 0: num = 1 453 | res = _point_vector_addition(num, pubkeys1_bytes, pubkeys2_bytes) 454 | return bytes(bytearray(res)) 455 | 456 | def _point_sequential_increment_P2(num, pubkey1_bytes): 457 | res = (b'\x00') * (65 * num) 458 | secp256k1.point_sequential_increment_P2(num, pubkey1_bytes, res) 459 | return res 460 | def point_sequential_increment_P2(num, pubkey1_bytes): 461 | ''' This is the fastest implementation to add point P2 in the given Point sequentially.''' 462 | if num <= 0: num = 1 463 | res = _point_sequential_increment_P2(num, pubkey1_bytes) 464 | return bytes(bytearray(res)) 465 | 466 | def _point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu): 467 | res = (b'\x00') * (65 * num) 468 | secp256k1.point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu, res) 469 | return res 470 | def point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu=os.cpu_count()): 471 | ''' This is the fastest multi CPU implementation to add point P2 in the given Point sequentially. Threads are Not optimised yet''' 472 | if num <= 0: num = 1 473 | res = _point_sequential_increment_P2_mcpu(num, pubkey1_bytes, mcpu) 474 | return bytes(bytearray(res)) 475 | 476 | def _point_sequential_increment(num, pubkey1_bytes): 477 | res = (b'\x00') * (65 * num) 478 | secp256k1.point_sequential_increment(num, pubkey1_bytes, res) 479 | return res 480 | def point_sequential_increment(num, pubkey1_bytes): 481 | ''' This is the fastest implementation using G''' 482 | if num <= 0: num = 1 483 | res = _point_sequential_increment(num, pubkey1_bytes) 484 | return bytes(bytearray(res)) 485 | 486 | def _point_sequential_decrement(num, pubkey1_bytes): 487 | res = (b'\x00') * (65 * num) 488 | secp256k1.point_sequential_decrement(num, pubkey1_bytes, res) 489 | return res 490 | def point_sequential_decrement(num, pubkey1_bytes): 491 | ''' This is the fastest implementation using -G.''' 492 | if num <= 0: num = 1 493 | res = _point_sequential_decrement(num, pubkey1_bytes) 494 | return bytes(bytearray(res)) 495 | 496 | def pubkey_to_ETH_address(pubkey_bytes): 497 | ''' 65 Upub bytes input. Output is 20 bytes ETH address lowercase with 0x as hex string''' 498 | xy = pubkey_bytes[1:] 499 | res = secp256k1.pubkeyxy_to_ETH_address(xy) 500 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 501 | secp256k1.free_memory(res) 502 | return '0x'+addr 503 | 504 | def _pubkey_to_ETH_address_bytes(xy): 505 | res = (b'\x00') * 20 506 | secp256k1.pubkeyxy_to_ETH_address_bytes(xy, res) 507 | return res 508 | def pubkey_to_ETH_address_bytes(pubkey_bytes): 509 | ''' 65 Upub bytes input. Output is 20 bytes ETH address lowercase without 0x''' 510 | xy = pubkey_bytes[1:] 511 | res = _pubkey_to_ETH_address_bytes(xy) 512 | return bytes(bytearray(res)) 513 | 514 | def privatekey_to_ETH_address(pvk_int): 515 | ''' Privatekey Integer value passed to function. Output is 20 bytes ETH address lowercase with 0x as hex string''' 516 | if pvk_int < 0: pvk_int = N+pvk_int 517 | pass_int_value = fl(pvk_int).encode('utf8') 518 | res = secp256k1.privatekey_to_ETH_address(pass_int_value) 519 | addr = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 520 | secp256k1.free_memory(res) 521 | return '0x'+addr 522 | 523 | def _privatekey_to_ETH_address_bytes(pass_int_value): 524 | res = (b'\x00') * 20 525 | secp256k1.privatekey_to_ETH_address_bytes(pass_int_value, res) 526 | return res 527 | def privatekey_to_ETH_address_bytes(pvk_int): 528 | ''' Privatekey Integer value passed to function. Output is 20 bytes ETH address lowercase without 0x''' 529 | if pvk_int < 0: pvk_int = N+pvk_int 530 | pass_int_value = fl(pvk_int).encode('utf8') 531 | res = _privatekey_to_ETH_address_bytes(pass_int_value) 532 | return bytes(bytearray(res)) 533 | 534 | def privatekey_group_to_ETH_address(pvk_int, m): 535 | ''' Starting Privatekey Integer value passed to function as pvk_int. 536 | Integer m is, how many times sequential increment is done from the starting key. 537 | Output is bytes 20*m of ETH address lowercase without 0x as hex string''' 538 | if m<=0: m = 1 539 | if pvk_int < 0: pvk_int = N+pvk_int 540 | start_pvk = fl(pvk_int).encode('utf8') 541 | res = secp256k1.privatekey_group_to_ETH_address(start_pvk, m) 542 | addrlist = (ctypes.cast(res, ctypes.c_char_p).value).decode('utf8') 543 | secp256k1.free_memory(res) 544 | return addrlist 545 | 546 | def _privatekey_group_to_ETH_address_bytes(start_pvk, m): 547 | res = (b'\x00') * (20 * m) 548 | secp256k1.privatekey_group_to_ETH_address_bytes(start_pvk, m, res) 549 | return res 550 | def privatekey_group_to_ETH_address_bytes(pvk_int, m): 551 | ''' Starting Privatekey Integer value passed to function as pvk_int. 552 | Integer m is, how many times sequential increment is done from the starting key. 553 | Output is bytes 20*m of ETH address lowercase without 0x''' 554 | if m<=0: m = 1 555 | if pvk_int < 0: pvk_int = N+pvk_int 556 | start_pvk = fl(pvk_int).encode('utf8') 557 | res = _privatekey_group_to_ETH_address_bytes(start_pvk, m) 558 | return bytes(bytearray(res)) 559 | 560 | def bloom_check_add_mcpu(bigbuff, num_items, sz, check_add, bloom_bits, bloom_hashes, bloom_filter): 561 | found_array = (b'\x00') * num_items 562 | # sz = 32; check_add = 0 for check and 1 for add 563 | secp256k1.bloom_check_add_mcpu(bigbuff, num_items, found_array, sz, check_add, bloom_bits, bloom_hashes, bloom_filter) 564 | return found_array 565 | 566 | def to_cpub(pub_hex): 567 | P = pub_hex 568 | if len(pub_hex) > 70: 569 | P = '02' + pub_hex[2:66] if int(pub_hex[66:],16)%2 == 0 else '03' + pub_hex[2:66] 570 | return P 571 | 572 | def point_to_cpub(pubkey_bytes): 573 | P = pubkey_bytes.hex() 574 | if len(P) > 70: 575 | P = '02' + P[2:66] if int(P[66:],16)%2 == 0 else '03' + P[2:66] 576 | return P 577 | 578 | def pub2upub(pub_hex): 579 | ''' Covert [C or U] pubkey to Point''' 580 | x = pub_hex[2:66] 581 | if len(pub_hex) < 70: 582 | y = get_x_to_y(x, int(pub_hex[:2],16)%2 == 0).hex() 583 | else: 584 | y = pub_hex[66:].zfill(64) 585 | return bytes.fromhex('04'+ x + y) 586 | 587 | def bloom_para(_items, _fp = 0.000001): 588 | _bits = math.ceil((_items * math.log(_fp)) / math.log(1 / pow(2, math.log(2)))) 589 | if _bits % 8: _bits = 8*(1 + (_bits//8)) 590 | _hashes = round((_bits / _items) * math.log(2)) 591 | return _bits, _hashes 592 | 593 | def Fill_in_bloom(inp_list, _fp = 0.000001): 594 | _bits, _hashes = bloom_para(len(inp_list), _fp) 595 | _bf = (b'\x00') * (_bits//8) 596 | for line in inp_list: 597 | if type(line) != bytes: tt = str(line).encode("utf-8") 598 | else: tt = line 599 | res = secp256k1.bloom_check_add(tt, len(tt), 1, _bits, _hashes, _bf) # 1 = Add 600 | del res 601 | return _bits, _hashes, _bf 602 | 603 | def dump_bloom_file(output_bloom_file_name, _bits, _hashes, _bf): 604 | with open(output_bloom_file_name, 'wb') as f: 605 | pickle.dump((_bits, _hashes, _bf), f) 606 | 607 | def read_bloom_file(bloom_file_name): 608 | '''It will return the 3 output as _bits, _hashes, _bf''' 609 | with open(bloom_file_name, 'rb') as f: 610 | return pickle.load(f) 611 | 612 | def check_in_bloom(this_line, _bits, _hashes, _bf): 613 | if type(this_line) != bytes: tt = str(this_line).encode("utf-8") 614 | else: tt = this_line 615 | if secp256k1.bloom_check_add(tt, len(tt), 0, _bits, _hashes, _bf) > 0: return True 616 | else: return False 617 | 618 | def prepare_bin_file_work(in_file, out_file, lower = False): 619 | use0x = False 620 | inp_list = [line.split()[0].lower() if lower else line.split()[0] for line in open(in_file,'r')] 621 | if inp_list[0][:2] == '0x': use0x = True 622 | 623 | with open(out_file, 'wb') as f: 624 | if use0x: 625 | inp_list = [line[2:] for line in inp_list] 626 | inp_list.sort() 627 | for line in inp_list: 628 | f.write(bytes.fromhex(line)) 629 | 630 | def prepare_bin_file(in_file, out_file, overwrite = False, lower = False): 631 | 632 | if os.path.isfile(out_file) == False: 633 | prepare_bin_file_work(in_file, out_file, lower) 634 | 635 | else: 636 | if not overwrite: 637 | print(f'[+] File {out_file} already exist. It will be used as it is...') 638 | 639 | else: 640 | print(f'[+] File {out_file} already exist. Overwriting it...') 641 | prepare_bin_file_work(in_file, out_file) 642 | 643 | def Load_data_to_memory(input_bin_file, verbose = False): 644 | '''input_bin_file is sorted h160 data of 20 bytes each element. 645 | ETH address can also work without 0x if sorted binary format''' 646 | secp256k1.Load_data_to_memory(input_bin_file.encode("utf-8"), verbose) 647 | 648 | 649 | def check_collision(h160): 650 | ''' h160 is the 20 byte hash to check for collision in data, already loaded in RAM. 651 | Use the function Load_data_to_memory before calling this check''' 652 | 653 | found = secp256k1.check_collision(h160) 654 | return found 655 | -------------------------------------------------------------------------------- /ScannerETH/secp256k1.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mizogg/Crypto-Database/8016974b32f8eaaa9112113f369e7f1dea1d5a97/ScannerETH/secp256k1.so -------------------------------------------------------------------------------- /htdocs/balance.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /htdocs/cog.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mizogg/Crypto-Database/8016974b32f8eaaa9112113f369e7f1dea1d5a97/htdocs/cog.gif -------------------------------------------------------------------------------- /htdocs/db.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /htdocs/indexbtc.php: -------------------------------------------------------------------------------- 1 | 4 | $v){ 17 | if(!empty($v)) { 18 | 19 | $queryCases = array("with_any_one_of","with_the_exact_of","without","starts_with"); 20 | if(in_array($k,$queryCases)) { 21 | if(!empty($queryCondition)) { 22 | $queryCondition .= " AND "; 23 | } else { 24 | $queryCondition .= " WHERE "; 25 | } 26 | } 27 | switch($k) { 28 | case "with_any_one_of": 29 | $with_any_one_of = $v; 30 | $wordsAry = explode(" ", $v); 31 | $wordsCount = count($wordsAry); 32 | for($i=0;$i<$wordsCount;$i++) { 33 | if(!empty($_POST["search"]["search_in"])) { 34 | $queryCondition .= $_POST["search"]["search_in"] . " LIKE '%" . $wordsAry[$i] . "%'"; 35 | } else { 36 | $queryCondition .= "compressed LIKE '" . $wordsAry[$i] . "%' OR uncompressed LIKE '" . $wordsAry[$i] . "%'"; 37 | } 38 | if($i!=$wordsCount-1) { 39 | $queryCondition .= " OR "; 40 | } 41 | } 42 | break; 43 | case "with_the_exact_of": 44 | $with_the_exact_of = $v; 45 | if(!empty($_POST["search"]["search_in"])) { 46 | $queryCondition .= $_POST["search"]["search_in"] . " LIKE '%" . $v . "%'"; 47 | } else { 48 | $queryCondition .= "compressed LIKE '%" . $v . "%' OR uncompressed LIKE '%" . $v . "%'"; 49 | } 50 | break; 51 | case "without": 52 | $without = $v; 53 | if(!empty($_POST["search"]["search_in"])) { 54 | $queryCondition .= $_POST["search"]["search_in"] . " NOT LIKE '%" . $v . "%'"; 55 | } else { 56 | $queryCondition .= "compressed NOT LIKE '%" . $v . "%' AND uncompressed NOT LIKE '%" . $v . "%'"; 57 | } 58 | break; 59 | case "starts_with": 60 | $starts_with = $v; 61 | if(!empty($_POST["search"]["search_in"])) { 62 | $queryCondition .= $_POST["search"]["search_in"] . " LIKE '" . $v . "%'"; 63 | } else { 64 | $queryCondition .= "compressed LIKE '" . $v . "%' OR uncompressed LIKE '" . $v . "%'"; 65 | } 66 | break; 67 | case "search_in": 68 | $search_in = $_POST["search"]["search_in"]; 69 | break; 70 | } 71 | } 72 | } 73 | } 74 | $orderby = " ORDER BY id desc"; 75 | $sql = "SELECT * FROM addresses " . $queryCondition . "LIMIT 5"; 76 | $result = mysqli_query($conn,$sql); 77 | 78 | ?> 79 | 80 | 81 | 82 | 83 | 84 | 85 |
86 |
87 |
88 |
89 |
90 |
91 |

Advanced Search using Bitcoin Address

92 |