Skip to content

Commit

Permalink
v 0.13.3, fix for POOL worker, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Sep 18, 2021
1 parent 4f0e606 commit ddf2f1f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 21 deletions.
7 changes: 4 additions & 3 deletions examples/example_13.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
POOL
bc1q0v5q36eaculyrykjnjsyuey6ctd3802ft4jdcc
# correct seed: brother canal medal remove pitch hill
1CEC5GLy2HkCWfNRUECsG3Bh3hTumF5yth
#known position, known candidates
6
brother
window master canal cat
?
black master remove cat
pitch
hill
remove pitch
cat hill
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>lostword</artifactId>
<version>0.13.2</version>
<version>0.13.3</version>
<packaging>jar</packaging>

<dependencies>
Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
<version>30.0-jre</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/pawelgorny/lostword/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,8 @@ public List<ChildNumber> getKeyPath() {
public String getEthereumAddress() {
return ethereumAddress;
}

public String getDerivationPathFull() {
return derivationPathFull;
}
}
56 changes: 46 additions & 10 deletions src/main/java/com/pawelgorny/lostword/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.bouncycastle.crypto.params.KeyParameter;
import org.web3j.crypto.Keys;

import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -27,7 +29,8 @@ public class Worker {
protected static Result RESULT = null;
protected final Configuration configuration;
protected int THREADS = 2;
protected final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
protected final SimpleDateFormat SDTF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
protected final SimpleDateFormat SDTCF = new SimpleDateFormat("yyyyMMdd_HHmmss");
protected static final int STATUS_PERIOD = 1000 * 60;

protected final HMac SHA_512_DIGEST;
Expand All @@ -36,8 +39,11 @@ public class Worker {
private final byte[] BITCOIN_SEED_BYTES = "Bitcoin seed".getBytes();
private final long CREATION_SECONDS = Utils.currentTimeSeconds();

private final int CONCAT_LEN_BITS;

public Worker(Configuration configuration) {
this.configuration = configuration;
this.CONCAT_LEN_BITS = 11 * configuration.getSIZE();
int procs = Runtime.getRuntime().availableProcessors();
if (procs > 1) {
if (procs % 2 == 1) {
Expand Down Expand Up @@ -70,7 +76,7 @@ public void run() throws InterruptedException, MnemonicException {
worker = new WorkerPermutation(configuration);
break;
}
System.out.println("--- Starting worker --- "+SDF.format(new Date())+" ---");
System.out.println("--- Starting worker --- "+ SDTF.format(new Date())+" ---");
if (WORK.PERMUTATION.equals(configuration.getWork())){
worker.run();
System.out.println();
Expand All @@ -84,8 +90,26 @@ public void run() throws InterruptedException, MnemonicException {
if (RESULT == null) {
System.out.println("Result not found!");
} else {
System.out.println("Found result!");
System.out.println("Result found!");
System.out.println(RESULT.toString());
resultToFile();
}
}

private void resultToFile() {
try {
FileWriter fileWriter = new FileWriter(this.configuration.getWork().name() + "_result_" + SDTCF.format(new Date()) + ".txt", false);
fileWriter.write(RESULT.toStringFile());
if (!configuration.getTargetAddress().isEmpty()){
fileWriter.write("\r\n");
fileWriter.write(configuration.getTargetAddress());
fileWriter.write("\r\n");
fileWriter.write(configuration.getDerivationPathFull());
}
fileWriter.write("\r\n");
fileWriter.close();
} catch (IOException e) {
System.out.println("Cannot write to file: " + e.getLocalizedMessage());
}
}

Expand Down Expand Up @@ -163,8 +187,7 @@ protected boolean checksumCheck(final List<String> mnemonic, MessageDigest sha25
}

public boolean checksumCheckBcJ(List<String> words, MessageDigest sha256){
int concatLenBits = words.size() * 11;
boolean[] concatBits = new boolean[concatLenBits];
boolean[] concatBits = new boolean[CONCAT_LEN_BITS];
int wordindex = 0;

int hash;
Expand All @@ -179,8 +202,8 @@ public boolean checksumCheckBcJ(List<String> words, MessageDigest sha256){
}
}

int var11 = concatLenBits / 33;
int var12 = concatLenBits - var11;
int var11 = CONCAT_LEN_BITS / 33;
int var12 = CONCAT_LEN_BITS - var11;
byte[] var13 = new byte[var12 / 8];

for(hash = 0; hash < var13.length; ++hash) {
Expand Down Expand Up @@ -287,7 +310,7 @@ protected void processPosition(int position) throws InterruptedException {
for (int bipPosition = 0; RESULT == null && bipPosition < WORDS_TO_WORK.size(); bipPosition++) {
SEED.set(WORKING_POSITION, WORDS_TO_WORK.get(bipPosition));
if (check(SEED, LOCAL_SHA_512_DIGEST, LOCAL_SHA_256_DIGEST)) {
RESULT = new Result(1 + WORKING_POSITION, WORDS_TO_WORK.get(bipPosition));
RESULT = new Result(1 + WORKING_POSITION, WORDS_TO_WORK.get(bipPosition), SEED);
}
}
} catch (Exception e) {
Expand All @@ -310,18 +333,31 @@ public Result(List<String> seed){
this.seed = seed;
}

public Result(int position, String word) {
public Result(int position, String word, List<String> seed) {
this.position = position;
this.word = word;
this.seed = seed;
}

@Override
public String toString() {
if (seed==null){
if (word!=null && !word.isEmpty()){
return "position=" + position + ", word='" + word + '\'';
}else {
return Utils.SPACE_JOINER.join(seed);
}
}

public String toStringFile(){
if (seed==null){
return "position=" + position + ", word='" + word + '\'';
}else {
String out = Utils.SPACE_JOINER.join(seed);
if (word!=null && !word.isEmpty()){
out = "position=" + position + ", word='" + word + '\'' + "\r\n" + out;
}
return out;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void checkUnknown(int position) throws InterruptedException {

for (int w0=configuration.getKnownStart(); RESULT==null && w0<DICTIONARY_SIZE; w0++){
String processedWord = Configuration.MNEMONIC_CODE.getWordList().get(w0);
System.out.println("Processing word "+(w0+1)+"/"+DICTIONARY_SIZE+" on position "+(position+1)+"! '"+processedWord+"' "+SDF.format(new Date()));
System.out.println("Processing word "+(w0+1)+"/"+DICTIONARY_SIZE+" on position "+(position+1)+"! '"+processedWord+"' "+ SDTF.format(new Date()));
mnemonic.set(position, processedWord);
final CountDownLatch latch = new CountDownLatch(THREADS);
final ExecutorService executorService = Executors.newFixedThreadPool(THREADS);
Expand Down Expand Up @@ -113,7 +113,7 @@ private void processSeed(final List<String> seed, int depth, int positionStartSe
return;
}
if (reporter && (System.currentTimeMillis()-start > STATUS_PERIOD)){
System.out.println(SDF.format(new Date())+ " Alive!");
System.out.println(SDTF.format(new Date())+ " Alive!");
start = System.currentTimeMillis();
}
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public WorkerPermutation(Configuration configuration) {
}catch (Exception e){
System.out.println(e.getLocalizedMessage());
}
fileName = "PERMUTATATIONS_"+(System.currentTimeMillis())+".txt";
fileName = "PERMUTATIONS_"+(System.currentTimeMillis())+".txt";
System.out.println("Saving to file: "+fileName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private boolean checkElements(String[] input) {
System.out.println(e.getLocalizedMessage());
}
if (System.currentTimeMillis()-start > STATUS_PERIOD){
System.out.println(SDF.format(new Date())+ " Alive!");
System.out.println(SDTF.format(new Date())+ " Alive!");
start = System.currentTimeMillis();
}
return (RESULT!=null);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/pawelgorny/lostword/WorkerPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ private void check() throws MnemonicException, InterruptedException {
private void checkUnknown(int position) throws InterruptedException {
List<String> mnemonic = new ArrayList<>(configuration.getWORDS());
int nextPosition = getNextUnknown(1+position, configuration.getWORDS());
if (nextPosition == -1){
nextPosition = position;
}
List<List<String>> DICTIONARY = split(configuration.getWORDS_POOL().get(nextPosition));

final List<MessageDigest> SHA_256_DIGESTS= new ArrayList<>(THREADS);
Expand All @@ -60,7 +63,7 @@ private void checkUnknown(int position) throws InterruptedException {
int DIC_SIZE = configuration.getWORDS_POOL().get(position).size();
for (int w0=0; RESULT==null && w0<DIC_SIZE; w0++){
String processedWord = configuration.getWORDS_POOL().get(position).get(w0);
System.out.println("Processing word "+(w0+1)+"/"+DIC_SIZE+" on position "+(position+1)+"! '"+processedWord+"' "+SDF.format(new Date()));
System.out.println("Processing tree "+(w0+1)+"/"+DIC_SIZE+" from position "+(position+1)+"! '"+processedWord+"' "+ SDTF.format(new Date()));
mnemonic.set(position, processedWord);
final CountDownLatch latch = new CountDownLatch(THREADS);
final ExecutorService executorService = Executors.newFixedThreadPool(THREADS);
Expand Down Expand Up @@ -101,7 +104,7 @@ private void processSeed(final List<String> seed, int depth, int positionStartSe
return;
}
if (reporter && (System.currentTimeMillis()-start > STATUS_PERIOD)){
System.out.println(SDF.format(new Date())+ " Alive!");
System.out.println(SDTF.format(new Date())+ " Alive!");
start = System.currentTimeMillis();
}
}else{
Expand Down

0 comments on commit ddf2f1f

Please sign in to comment.