-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.17.0 printing seed with 2 words swapped (worker: SWAP)
- Loading branch information
PawelGorny
committed
Sep 22, 2022
1 parent
3722618
commit eb2731e
Showing
6 changed files
with
96 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.pawelgorny.lostword; | ||
|
||
import org.bitcoinj.core.Utils; | ||
import org.bitcoinj.crypto.MnemonicException; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.security.MessageDigest; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class WorkerSwap extends Worker { | ||
|
||
private MessageDigest SHA_256_DIGEST; | ||
private FileWriter fileWriter = null; | ||
private final String fileName; | ||
private int counter = 0; | ||
private final Set<String> result = new HashSet<>(); | ||
|
||
public WorkerSwap(Configuration configuration){ | ||
super(configuration); | ||
try { | ||
SHA_256_DIGEST = MessageDigest.getInstance("SHA-256"); | ||
}catch (Exception e){ | ||
System.out.println(e.getLocalizedMessage()); | ||
} | ||
fileName = "SWAPS_"+(System.currentTimeMillis())+".txt"; | ||
System.out.println("Saving to file: "+fileName); | ||
} | ||
|
||
@Override | ||
public void run() throws InterruptedException, MnemonicException { | ||
System.out.println("Input: " + Utils.SPACE_JOINER.join(configuration.getWORDS())); | ||
String[] words = new String[0]; | ||
words = configuration.getWORDS().toArray(words); | ||
printAllSwaps(configuration.getSIZE(), words); | ||
if (!result.isEmpty()){ | ||
for (String r : result){ | ||
System.out.println(r); | ||
} | ||
} | ||
if (fileName!=null){ | ||
if (fileWriter!=null) { | ||
try { | ||
fileWriter.flush(); | ||
fileWriter.close(); | ||
} catch (IOException e) { | ||
System.out.println(e.getLocalizedMessage()); | ||
} | ||
System.out.println("File " + fileName + " created, "+counter+" results"); | ||
} | ||
} | ||
} | ||
|
||
private void printAllSwaps(int size, String[] words) { | ||
|
||
List<String> mnemonic = Arrays.asList(words); | ||
if (checksumCheck(mnemonic, SHA_256_DIGEST)) { | ||
result.add(Utils.SPACE_JOINER.join(mnemonic)); | ||
} | ||
String[] WORDS = new String[size]; | ||
for (int i=0; i<size; i++){ | ||
for (int w=0; w<size; w++){ | ||
WORDS[w] = words[w]; | ||
} | ||
for (int j=0; j<size; j++){ | ||
swap(WORDS, i, j); | ||
mnemonic = Arrays.asList(WORDS); | ||
if (checksumCheck(mnemonic, SHA_256_DIGEST)) { | ||
result.add(Utils.SPACE_JOINER.join(mnemonic)); | ||
} | ||
swap(WORDS, j, i); | ||
} | ||
} | ||
|
||
} | ||
|
||
private void swap(String[] words, int i, int j) { | ||
String t = words[i]; | ||
words[i] = words[j]; | ||
words[j] = t; | ||
} | ||
|
||
|
||
} |