└── bit /bit: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // The string we are searching for 5 | const std::string search = "1kid"; 6 | 7 | // Generate a random secret key. A random 32 bytes. 8 | bc::ec_secret random_secret(std::default_random_engine& engine); 9 | // Extract the Bitcoin address from an EC secret. 10 | std::string bitcoin_address(const bc::ec_secret& secret); 11 | // Case insensitive comparison with the search string. 12 | bool match_found(const std::string& address); 13 | 14 | int main() 15 | { 16 | // random_device on Linux uses "/dev/urandom" 17 | // CAUTION: Depending on implementation this RNG may not be secure enough! 18 | // Do not use vanity keys generated by this example in production 19 | std::random_device random; 20 | std::default_random_engine engine(random()); 21 | 22 | // Loop continuously... 23 | while (true) 24 | { 25 | // Generate a random secret. 26 | bc::ec_secret secret = random_secret(engine); 27 | // Get the address. 28 | std::string address = bitcoin_address(secret); 29 | // Does it match our search string? (1kid) 30 | if (match_found(address)) 31 | { 32 | // Success! 33 | std::cout << "Found vanity address! " << address << std::endl; 34 | std::cout << "Secret: " << bc::encode_base16(secret) << std::endl; 35 | return 0; 36 | } 37 | } 38 | // Should never reach here! 39 | return 0; 40 | } 41 | 42 | bc::ec_secret random_secret(std::default_random_engine& engine) 43 | { 44 | // Create new secret... 45 | bc::ec_secret secret; 46 | // Iterate through every byte setting a random value... 47 | for (uint8_t& byte: secret) 48 | byte = engine() & 255; 49 | // Return result. 50 | return secret; 51 | } 52 | 53 | std::string bitcoin_address(const bc::ec_secret& secret) 54 | { 55 | // Convert secret to payment address 56 | bc::wallet::ec_private private_key(secret); 57 | bc::wallet::payment_address payaddr(private_key); 58 | // Return encoded form. 59 | return payaddr.encoded(); 60 | } 61 | 62 | bool match_found(const std::string& address) 63 | { 64 | auto addr_it = address.begin(); 65 | // Loop through the search string comparing it to the lower case 66 | // character of the supplied address. 67 | for (auto it = search.begin(); it != search.end(); ++it, ++addr_it) 68 | if (*it != std::tolower(*addr_it)) 69 | return false; 70 | // Reached end of search string, so address matches. 71 | return true; 72 | } 73 | --------------------------------------------------------------------------------