Skip to content

Commit

Permalink
0.5.1 - performance improvements, fix for END worker
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Sep 14, 2021
1 parent 57b83ae commit 7ae593e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 40 deletions.
8 changes: 8 additions & 0 deletions examples/example_ROTATE.conf2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#this solver tries to modify each character (separately)
#works sucessfully when only one character is wrong
#1st line: type of work
ROTATE
#target: L5EZftvrYaSudiozVRzTqLcHLNDoVn7H5HSfM9BAN6tMJX8oTWz6
#2nd line: WIF with misspelled letter (Z/z on 16 position)
L5EZftvrYaSudioZVRzTqLcHLNDoVn7H5HSfM9BAN6tMJX8oTWz6
1EUXSxuUVy2PC5enGXR1a3yxbEjNWMHuem
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

<groupId>com.pawelgorny</groupId>
<artifactId>wifSolver</artifactId>
<version>0.5.1</version>
<version>0.5.2</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.15.8</version>
<version>0.15.10</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
<version>30.0-jre</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/pawelgorny/wifsolver/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pawelgorny.wifsolver;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.params.MainNetParams;

Expand All @@ -21,14 +23,20 @@ public class Configuration {
private final String wifStatus;
private final WORK work;
private final Map<Integer, char[]> guess;
private Address address;
private byte[] addressHash;
private boolean compressed;

private EmailConfiguration emailConfiguration = null;

public Configuration(String targetAddress, String wif, String wifStatus, WORK work, Map<Integer, char[]> guess) {
this.targetAddress = targetAddress;
if (targetAddress != null) {
this.address = LegacyAddress.fromBase58(NETWORK_PARAMETERS, getTargetAddress());
this.addressHash = address.getHash();
}
this.wif = wif;
this.compressed = wif.length() == COMPRESSED_WIF_LENGTH;
this.compressed = wif.length() == COMPRESSED_WIF_LENGTH || (WORK.END.equals(work) && (wif.startsWith("L") || wif.startsWith("K")));
this.wifStatus = wifStatus;
this.work = work;
this.guess = guess.isEmpty()?null:guess;
Expand All @@ -50,6 +58,14 @@ public String getTargetAddress() {
return targetAddress;
}

public Address getAddress() {
return address;
}

public byte[] getAddressHash() {
return addressHash;
}

public String getWif() {
return wif;
}
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/com/pawelgorny/wifsolver/Worker.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.pawelgorny.wifsolver;

import org.bitcoinj.core.Base58;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.*;

import javax.mail.MessagingException;
import javax.mail.Transport;
Expand Down Expand Up @@ -115,13 +112,15 @@ protected String workThread(String suspect){
return null;
}
ECKey ecKey = DumpedPrivateKey.fromBase58(Configuration.getNetworkParameters(), suspect).getKey();
String foundAddress = this.configuration.isCompressed() ? LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey).toString()
:LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey.decompress()).toString();
String data = suspect + " -> " + foundAddress;
if (!this.configuration.isCompressed()) {
ecKey = ecKey.decompress();
}
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
String data = suspect + " -> " + foundAddress.toString();
addResult(data);
System.out.println(data);
resultToFilePartial(data);
if(foundAddress.equals(configuration.getTargetAddress())) {
if (foundAddress.equals(configuration.getAddress())) {
return suspect;
}
}catch (Exception ex){
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/com/pawelgorny/wifsolver/WorkerEnd.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.pawelgorny.wifsolver;

import org.bitcoinj.core.Base58;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.*;

import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -36,11 +33,11 @@ private static void increment58(int[] array) {

protected void run() throws InterruptedException {
String wif = configuration.getWif();
String address = configuration.getTargetAddress();

int len = 51;
if (wif.startsWith("L")||wif.startsWith("K")){
len = Configuration.COMPRESSED_WIF_LENGTH;
System.out.println("Looking for compressed address");
}
int missing = len - wif.length();
if (missing <= 0) {
Expand Down Expand Up @@ -81,7 +78,7 @@ protected void run() throws InterruptedException {
for (int anArr : arr) {
stringBuilderThread.append(Base58.ALPHABET[anArr]);
}
lastTested[tNr] = checksumCheck(Configuration.getChecksumChars(), stringBuilderThread.toString(), expectedLength, address, lastTested[tNr]);
lastTested[tNr] = checksumCheck(Configuration.getChecksumChars(), stringBuilderThread.toString(), expectedLength, configuration.getAddress(), lastTested[tNr]);
if (found) {
break;
}
Expand All @@ -101,7 +98,7 @@ protected void run() throws InterruptedException {
}
}

private String checksumCheck(int missing, String wif, int len, final String address, String lastTested) {
private String checksumCheck(int missing, String wif, int len, final Address targetAddress, String lastTested) {
StringBuilder sb = new StringBuilder(len);
sb.append(wif);
for (int m = 0; m < missing; m++) {
Expand All @@ -118,10 +115,12 @@ private String checksumCheck(int missing, String wif, int len, final String addr
}
if (encoded.startsWith(configuration.getWif())) {
ECKey ecKey = DumpedPrivateKey.fromBase58(Configuration.getNetworkParameters(), encoded).getKey();
String foundAddress = len == Configuration.COMPRESSED_WIF_LENGTH ? LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey).toString()
: LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey.decompress()).toString();
if (address != null) {
if (foundAddress.equals(address)) {
if (!configuration.isCompressed()) {
ecKey = ecKey.decompress();
}
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
if (targetAddress != null) {
if (foundAddress.equals(targetAddress)) {
found = true;
super.addResult(encoded + " -> " + foundAddress);
System.out.println(encoded + " -> " + foundAddress);
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/pawelgorny/wifsolver/WorkerJump.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.pawelgorny.wifsolver;

import org.bitcoinj.core.Base58;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.*;

import java.math.BigInteger;
import java.util.Date;
Expand Down Expand Up @@ -144,10 +141,10 @@ private boolean check(BigInteger privThread){
try {
ECKey ecKey = DumpedPrivateKey.fromBase58(Configuration.getNetworkParameters(), Base58.encode(bytes)).getKey();
String encoded = Base58.encode(bytes);
String foundAddress = configuration.isCompressed() ? LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey).toString()
:LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey.decompress()).toString();
Address foundAddress = configuration.isCompressed() ? LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey)
: LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey.decompress());
String data = encoded + " -> " + foundAddress;
if(configuration.getTargetAddress().equals(foundAddress)){
if (configuration.getAddress().equals(foundAddress)) {
super.addResult(data);
System.out.println(data);
RESULT = encoded;
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/pawelgorny/wifsolver/WorkerRotate.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.pawelgorny.wifsolver;

import org.bitcoinj.core.Base58;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.LegacyAddress;
import org.bitcoinj.core.*;

class WorkerRotate extends Worker {

Expand All @@ -29,24 +26,29 @@ protected void run() {
}catch (Exception e){
System.out.println("Initial "+configuration.getWif()+" incorrect, starting rotation");
}
mainLoop:
for (int c = 0; c < len; c++) {
for (int z=0; z< Base58.ALPHABET.length ;z++) {
stringBuilder.setCharAt(c, Base58.ALPHABET[z]);
test(stringBuilder.toString());
if (test(stringBuilder.toString())) {
break mainLoop;
}
stringBuilder.replace(0, len, configuration.getWif());
}
}
}

private void test(String suspect) {
private boolean test(String suspect) {
try {
ECKey ecKey = DumpedPrivateKey.fromBase58(Configuration.getNetworkParameters(), suspect).getKey();
String foundAddress = this.configuration.isCompressed() ? LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey).toString()
: LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey.decompress()).toString();
Address foundAddress = this.configuration.isCompressed() ? LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey)
: LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey.decompress());
if (configuration.getTargetAddress() != null) {
if (foundAddress.equals(configuration.getTargetAddress())) {
if (foundAddress.equals(configuration.getAddress())) {
super.addResult(suspect + " -> " + foundAddress);
System.out.println("Expected address found:");
System.out.println(suspect + " -> " + foundAddress);
return;
return true;
}
} else {
super.addResult(suspect + " -> " + foundAddress);
Expand All @@ -55,6 +57,7 @@ private void test(String suspect) {
} catch (Exception e) {

}
return false;
}

}

0 comments on commit 7ae593e

Please sign in to comment.