Replacing String.join for StringBuilder in BrainKey.suggest() method
This commit is contained in:
parent
3d3e0c2616
commit
8f7a5549bd
3 changed files with 8 additions and 41 deletions
|
@ -9,19 +9,6 @@ import java.security.MessageDigest;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import org.bitcoinj.core.Base58;
|
||||
import org.bitcoinj.core.BitcoinSerializer;
|
||||
import org.bitcoinj.core.Block;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.StoredBlock;
|
||||
import org.bitcoinj.core.VerificationException;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.BlockStoreException;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||
import org.spongycastle.crypto.digests.SHA512Digest;
|
||||
|
||||
/**
|
||||
* Class used to encapsulate all BrainKey-related operations.
|
||||
|
@ -55,11 +42,14 @@ public class BrainKey {
|
|||
index = secureRandom.nextInt(DICT_WORD_COUNT - 1);
|
||||
suggestedBrainKey.add(wordArray[index].toUpperCase());
|
||||
}
|
||||
String result = String.join(" ", suggestedBrainKey.toArray(new String[suggestedBrainKey.size()]));
|
||||
System.out.println("result: '" + result + "'");
|
||||
return result;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(String word : suggestedBrainKey){
|
||||
stringBuilder.append(word);
|
||||
stringBuilder.append(" ");
|
||||
}
|
||||
System.out.println("Suggestion: '"+stringBuilder.toString().trim()+"'");
|
||||
return stringBuilder.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* BrainKey constructor that takes as argument a specific brain key word
|
||||
* sequence and generates the private key and address from that.
|
||||
|
|
|
@ -66,7 +66,7 @@ public class Main {
|
|||
|
||||
// test.testRandomNumberGeneration();
|
||||
|
||||
test.testBrainKeyOperations(false);
|
||||
test.testBrainKeyOperations(true);
|
||||
|
||||
// test.testBip39Opertion();
|
||||
}
|
||||
|
|
|
@ -543,29 +543,6 @@ public class Test {
|
|||
System.out.println("pub key compressed : " + Base58.encode(pubKey3));
|
||||
|
||||
// Address generation test
|
||||
RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest();
|
||||
SHA512Digest sha512Digest = new SHA512Digest();
|
||||
sha512Digest.update(pubKey2, 0, pubKey2.length);
|
||||
byte[] intermediate = new byte[512 / 8];
|
||||
sha512Digest.doFinal(intermediate, 0);
|
||||
ripemd160Digest.update(intermediate, 0, intermediate.length);
|
||||
byte[] output = new byte[160 / 8];
|
||||
ripemd160Digest.doFinal(output, 0);
|
||||
System.out.println("output after : " + Util.bytesToHex(output));
|
||||
String encoded = Base58.encode(output);
|
||||
System.out.println("base 58: " + encoded);
|
||||
|
||||
byte[] checksum = new byte[(160 / 8) + 4];
|
||||
|
||||
System.arraycopy(calculateChecksum(output), 0, checksum, checksum.length - 4, 4);
|
||||
|
||||
System.arraycopy(output, 0, checksum, 0, output.length);
|
||||
|
||||
System.out.println("BTS" + Base58.encode(checksum));
|
||||
|
||||
System.out.println("Compress Adress : " + brainKey.getAddress());
|
||||
System.out.println("Uncompress Adress : " + brainKey.getUncompressedAddress());
|
||||
|
||||
Address address = new Address(key);
|
||||
System.out.println("Block explorer's address: "+address);
|
||||
|
||||
|
|
Loading…
Reference in a new issue