From 8f7a5549bdad5b2231bc9d39ee90acfe20ef808e Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Wed, 23 Nov 2016 22:20:51 -0500 Subject: [PATCH] Replacing String.join for StringBuilder in BrainKey.suggest() method --- .../com/luminiasoft/bitshares/BrainKey.java | 24 ++++++------------- .../java/com/luminiasoft/bitshares/Main.java | 2 +- .../java/com/luminiasoft/bitshares/Test.java | 23 ------------------ 3 files changed, 8 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/luminiasoft/bitshares/BrainKey.java b/src/main/java/com/luminiasoft/bitshares/BrainKey.java index 3e20213..1aaa4e0 100644 --- a/src/main/java/com/luminiasoft/bitshares/BrainKey.java +++ b/src/main/java/com/luminiasoft/bitshares/BrainKey.java @@ -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. diff --git a/src/main/java/com/luminiasoft/bitshares/Main.java b/src/main/java/com/luminiasoft/bitshares/Main.java index 1ae5e7a..2e57f7e 100644 --- a/src/main/java/com/luminiasoft/bitshares/Main.java +++ b/src/main/java/com/luminiasoft/bitshares/Main.java @@ -66,7 +66,7 @@ public class Main { // test.testRandomNumberGeneration(); - test.testBrainKeyOperations(false); + test.testBrainKeyOperations(true); // test.testBip39Opertion(); } diff --git a/src/main/java/com/luminiasoft/bitshares/Test.java b/src/main/java/com/luminiasoft/bitshares/Test.java index 5f3ceaa..605d21a 100644 --- a/src/main/java/com/luminiasoft/bitshares/Test.java +++ b/src/main/java/com/luminiasoft/bitshares/Test.java @@ -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);