Skip to content

Commit

Permalink
0.5.4 - minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Sep 20, 2021
1 parent e7a8850 commit c25a3ad
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.pawelgorny</groupId>
<artifactId>wifSolver</artifactId>
<version>0.5.3</version>
<version>0.5.4</version>
<packaging>jar</packaging>

<dependencies>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.6.4</version>
<version>1.6.7</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pawelgorny/wifsolver/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Configuration {

private final static NetworkParameters NETWORK_PARAMETERS = MainNetParams.get();
private final static int STATUS_PERIOD = 60 * 1000; //1 minute
private final static int CHECKSUM_CHARS = 4; //safe option, could be more
private final static int CHECKSUM_CHARS = 5;


private final String targetAddress;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/pawelgorny/wifsolver/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ private static void readEmailConfiguration(Configuration configuration, String f
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", host);
prop.put("mail.smtp.port", port);
prop.put("mail.smtp.ssl.trust", "*");
prop.put("mail.smtp.ssl.protocols", "TLSv1 TLSv1.1 TLSv1.2");
final String _username = username;
final String _password = new String(password);
Session mailSession = Session.getInstance(prop, new javax.mail.Authenticator() {
Expand Down
62 changes: 45 additions & 17 deletions src/main/java/com/pawelgorny/wifsolver/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.*;

class Worker {

Expand All @@ -21,6 +18,8 @@ class Worker {
private final Configuration configuration;
private final long timeId = System.currentTimeMillis();

protected boolean DUMMY_CHECKSUM = false;

public Worker(Configuration configuration) {
this.configuration = configuration;
}
Expand Down Expand Up @@ -101,34 +100,63 @@ private void sendEmail(String subject, String body){
Transport.send(message);
} catch (MessagingException e) {
System.err.println(e.getLocalizedMessage());
e.printStackTrace();
System.exit(0);
}
}


protected String workThread(String suspect){
try{
byte[] bytes = Base58.decode(suspect);
if (this.configuration.isCompressed() && bytes[33] != 1) {
return null;
ECKey ecKey = null;
if (this.configuration.isCompressed() || DUMMY_CHECKSUM) {
byte[] bytes = Base58.decode(suspect);
if (this.configuration.isCompressed() && bytes[33] != 1) {
return null;
}
if (DUMMY_CHECKSUM) {
ecKey = ECKey.fromPrivate(Arrays.copyOfRange(bytes, 1, bytes.length - 4), this.configuration.isCompressed());
}
}
ECKey ecKey = DumpedPrivateKey.fromBase58(Configuration.getNetworkParameters(), suspect).getKey();
if (!this.configuration.isCompressed()) {
ecKey = ecKey.decompress();
if (ecKey == null) {
ecKey = DumpedPrivateKey.fromBase58(Configuration.getNetworkParameters(), suspect).getKey();
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.getAddress())) {
return suspect;
if (configuration.getAddress() != null) {
if (Arrays.equals(configuration.getAddressHash(), ecKey.getPubKeyHash())) {
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
if (DUMMY_CHECKSUM) {
suspect = rewriteWIF(suspect);
}
String data = suspect + " -> " + foundAddress.toString();
addResult(data);
System.out.println(data);
return suspect;
}
} else {
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
if (DUMMY_CHECKSUM) {
suspect = rewriteWIF(suspect);
}
String data = suspect + " -> " + foundAddress.toString();
addResult(data);
System.out.println(data);
resultToFilePartial(data);
}
}catch (Exception ex){
//wif incorrect (checksum?)
}
return null;
}

private String rewriteWIF(String suspectFakeChecksum) {
byte[] bytes = Base58.decode(suspectFakeChecksum);
bytes = Arrays.copyOfRange(bytes, 1, bytes.length - 4);
return Base58.encodeChecked(128, bytes);
}


}

Expand Down
33 changes: 24 additions & 9 deletions src/main/java/com/pawelgorny/wifsolver/WorkerSearch.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 java.util.*;
import java.util.concurrent.CountDownLatch;
Expand All @@ -23,6 +20,7 @@ class WorkerSearch extends Worker {
private String RESULT = null;
private long start = 0;
private int THREADS = THREADS_MIN;
private long THREADS_WORK_LIMIT = new Double(Math.pow(58, 2)).longValue();

public WorkerSearch(Configuration configuration) {
super(configuration);
Expand All @@ -46,13 +44,23 @@ private static int findIx(char[] a, char v) {

@Override
protected void run() throws InterruptedException {
System.out.println("Using " + THREADS + " threads, (" + THREADS_WORK_LIMIT + "op/bulk)");
start = System.currentTimeMillis();
setLoop(0, null, false);
}

private void setLoop(int ix, StringBuilder ownWif, boolean inThread) throws InterruptedException {
if (ownWif == null){
ownWif = new StringBuilder(WIF);
for (int chIx = 0; chIx < Configuration.getChecksumChars(); chIx++) {
if (WIF.charAt(WIF.length() - chIx - 1) == Configuration.UNKNOWN_CHAR) {
ownWif.setCharAt(ownWif.length() - chIx - 1, '1');
super.DUMMY_CHECKSUM = true;
}
}
if (super.DUMMY_CHECKSUM) {
System.out.println("Using dummy checksum for the last " + Configuration.getChecksumChars() + " characters");
}
}
if (ix==GUESS_IX.size()){
if (!START_ZERO){
Expand Down Expand Up @@ -118,12 +126,13 @@ private void configureStartZero() {
for (int i=0; i<STARTER.length; i++){
STARTER[i] = 0;
}
START_ZERO = !START_ZERO;
}

private void configureHints() {
int guessIx = 0;
List<Integer> ranges = new ArrayList<>(0);
for (int c=0; c<configuration.getWif().length(); c++){
for (int c = 0; c < configuration.getWif().length() - Configuration.getChecksumChars(); c++) {
if (Configuration.UNKNOWN_CHAR == configuration.getWif().charAt(c)){
char[] hints = Base58.ALPHABET;
if (configuration.getGuess() != null && configuration.getGuess().get(guessIx) != null) {
Expand All @@ -135,19 +144,25 @@ private void configureHints() {
}
}
long count = 0;

int procs = Runtime.getRuntime().availableProcessors();
if (procs < 1) {
procs = THREADS_MIN;
}
if (procs > 2) {
THREADS_WORK_LIMIT = THREADS_WORK_LIMIT * 2;
}

for (int c=ranges.size()-1; c>=0; c--){
if (count == 0){
count = ranges.get(c);
}else {
count*=ranges.get(c);
}
if (count>=1_000_000 && ranges.get(c)>1){
if (count >= THREADS_WORK_LIMIT && ranges.get(c) > 1) {
THREADS_WORK_LIMIT = count;
THREAD_BREAK = c;
if (ranges.get(c) > THREADS_MIN) {
int procs = Runtime.getRuntime().availableProcessors();
if (procs < 1) {
procs = THREADS_MIN;
}
THREADS = Math.min(procs, ranges.get(c));
}
break;
Expand Down

0 comments on commit c25a3ad

Please sign in to comment.