Skip to content

Instantly share code, notes, and snippets.

@jamolkhon
Last active November 19, 2022 14:44
Show Gist options
  • Save jamolkhon/2de9c01d67ffd9b8cd543b10abc5eddd to your computer and use it in GitHub Desktop.
Save jamolkhon/2de9c01d67ffd9b8cd543b10abc5eddd to your computer and use it in GitHub Desktop.
import org.web3j.crypto.Credentials
import org.web3j.crypto.Keys
import java.util.*
import java.util.concurrent.Executors
fun main(args: Array<String>) {
val threads = 4
val pool = Executors.newFixedThreadPool(threads)
val lock = object {}
for (i in 1..threads) {
pool.submit {
generate(lock)
}
}
Scanner(System.`in`).nextLine()
}
fun generate(lock: Any) {
val thread = Thread.currentThread().name
println("[$thread] Starting...")
var i = 1
while (true) {
val keyPair = Keys.createEcKeyPair()
val credentials = Credentials.create(keyPair)
val address = credentials.address
val prefix = address.substring(2, 6) // first four symbols after "0x"
val suffix = address.substring(address.length - 4) // last four symbols
if (isNice(prefix, suffix)) {
synchronized(lock) {
println("[$thread] 0x${prefix}...${suffix}")
println("[$thread] address: ${credentials.address}")
println("[$thread] private: ${keyPair.privateKey.toString(16)}")
println()
}
}
if (i % 10_000_000 == 0) {
println("[$thread] So far generated $i addresses")
println()
}
i++
}
}
fun isNice(prefix: String, suffix: String): Boolean {
return isNice(prefix) && isNice(suffix) // Use "prefix == suffix" for better looking ones like 0x2222...2222
}
fun isNice(part: String): Boolean = when (part) {
"0000" -> true
"1111" -> true
"2222" -> true
"3333" -> true
"4444" -> true
"5555" -> true
"6666" -> true
"7777" -> true
"8888" -> true
"9999" -> true
"AAAA" -> true
"BBBB" -> true
"CCCC" -> true
"DDDD" -> true
"EEEE" -> true
"FFFF" -> true
else -> false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment