Title: get the 12th word seed
Post by: Sanka555 on November 21, 2021, 09:09:20 AM
trying to "manually" get 12 seed words from a 128-bit number.
For me it is fed to the input as a string like "0101010000 ...."
to get the 12th control word I need to hash my 128bit ... and then it's simple. but i don't need to hash it as a string with characters. And as a byte array.
Can you please tell me how this is done correctly in JAVA?
(just String getBytes () and then DigestUtils.sha256Hex () dont work)
I would be very grateful for a piece of JAVA code that will get the 12th word from such a line :)
Title: Re: get the 12th word seed
Post by: BlackHatCoiner on November 21, 2021, 09:31:25 AM
You'll have to convert your string to bytes, hash the bytes and then add the first four bits of that hash in the end of your entropy. Then, with 132 bits, you can represent each 11 bits to a word based on bip-0039/english.txt (https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt). I would be very grateful for a piece of JAVA code that will get the 12th word from such a line Didn't the MnemonicCode() (https://bitcoinj.org/javadoc/0.15/index.html?org/bitcoinj/crypto/MnemonicCode.html) work from the other thread? It's supposed to receive as input the entropy and return the phrase. It's more practical to use your library's function than to re-write it.
Title: Re: get the 12th word seed
Post by: Sanka555 on November 21, 2021, 09:49:07 AM
You'll have to convert your string to bytes, hash the bytes and then add the first four bits of that hash in the end of your entropy. Then, with 132 bits, you can represent each 11 bits to a word based on bip-0039/english.txt (https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt). I would be very grateful for a piece of JAVA code that will get the 12th word from such a line Didn't the MnemonicCode() (https://bitcoinj.org/javadoc/0.15/index.html?org/bitcoinj/crypto/MnemonicCode.html) work from the other thread? It's supposed to receive as input the entropy and return the phrase. It's more practical to use your library's function than to re-write it. I'm not a programmer. I just need to fix a Java program :-\. I don’t understand how to use this function. I need a piece of ready-made code that accepts a line as input and outputs the 12th word. I was able to get the first 11))
Title: Re: get the 12th word seed
Post by: pooya87 on November 21, 2021, 10:14:18 AM
I'm not a programmer. I just need to fix a Java program
You should keep in mind that without programming knowledge and understanding of the algorithm, your final result has a high chance of having bugs or mistakes that could lead to loss of funds. I need a piece of ready-made code that accepts a line as input and outputs the 12th word. I was able to get the first 11))
You can use any of the deterministic wallets to generate a seed phrase or use the open source tools such as https://github.com/iancoleman/bip39 that happens to be written in JavaScript (which isn't that far from Java). For the 12th word you do pretty much the same thing. You take your remaining 7 bits and add 4 more bits from the checksum to it and get your final word.
Title: Re: get the 12th word seed
Post by: Sanka555 on November 21, 2021, 12:08:28 PM
I do not give up) 000000000000000111110111111111110000000000000001111101111111 111100000000000000011111011111111111000000000000000111110111 11111111 private String[] generateMnemonic2(String seedEntropy) { // System.out.println(seedEntropy); String[] mnemonicWords = new String[12]; for (int i = 0; i < 11; i++) { int mnemWord = Integer.parseInt(seedEntropy.substring(i * 11, i * 11 + 11), 2); mnemonicWords = English.getWord(mnemWord); } mnemonicWords[11]=seedEntropy.substring(121,128); //I keep my tail here temporarily String g=DigestUtils.sha256Hex(seedEntropy.getBytes()).substring(0,2); System.out.println(g);
String v=hexToBinary(g)+mnemonicWords[11]; System.out.println(v);
BigInteger sha256hex =new BigInteger(v,2); System.out.println(sha256hex.toString());
mnemonicWords[11] = English.getWord(sha256hex.intValue()); return mnemonicWords; } String hexToBinary(String hex) { int i = Integer.parseInt(hex, 16); String bin = Integer.toBinaryString(i); return bin; } (words are in the array, so you don't need to do +1) resulting in the 12th word java.lang.ArrayIndexOutOfBoundsException: 24447 maybe someone can fix the errors in my code? I would be very grateful :)
Title: Re: get the 12th word seed
Post by: BlackHatCoiner on November 21, 2021, 12:29:40 PM
To clear up my position. It's not that I don't want to help you. I just don't know Java and agree with the following; [...] if you give a man a fish he is hungry again in an hour. If you teach him to catch a fish you do him a good turn.
Title: Re: get the 12th word seed
Post by: Sanka555 on November 21, 2021, 12:42:10 PM
To clear up my position. It's not that I don't want to help you. I just don't know Java and agree with the following; [...] if you give a man a fish he is hungry again in an hour. If you teach him to catch a fish you do him a good turn. I am very grateful for your help and now I am trying to figure it out :). Perhaps I can figure it out. But suddenly someone can just fix the code ... ))
Title: Re: get the 12th word seed
Post by: n0nce on November 21, 2021, 12:45:50 PM
I'm not a programmer. I just need to fix a Java program :-\. I don’t understand how to use this function. I need a piece of ready-made code that accepts a line as input and outputs the 12th word. I was able to get the first 11))
I sincerely hope, that you will never actually use this code and store any funds on this. You can't just copy something together without being 100% sure what it's doing and how it's working..
Title: Re: get the 12th word seed
Post by: PawGo on November 21, 2021, 01:51:33 PM
You create several topics about the same issue. I have already wrote you how the algorithm works: https://medium.com/geekculture/cryptocurrency-911-how-does-12-word-seed-phrase-work-9d892de9732 If you cannot rewrite it into proper java code, it is better not to do it at all, as you may produce many bugs. But if you want to have it done, contact me and I may prepare software for you, you will not pay much :) Coming back to subject: if you have only 11 words, you may produce 128 12th words, so you may have 128 correct seeds. import org.bitcoinj.core.Utils; import org.bitcoinj.crypto.MnemonicCode;
import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.*;
public class Find12 {
private static final int TARGET_SIZE = 12; private static List<String> WORDS; private static MessageDigest SHA256; private static int CONCAT_LEN_BITS; private static int CONCAT_LEN_BITS_DIV_33; private static int CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33; private static int CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33__DIV8;
public static void main(String args[]) throws IOException { String[] input = new String[]{"faith","always","acquire","host","amused", "mercy","horn","service","series","stove","off"}; Find12 find12 = new Find12(); find12.findSeed(input); }
public Find12() throws IOException { WORDS = new MnemonicCode().getWordList(); try { SHA256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException var1) { throw new RuntimeException(var1); } this.CONCAT_LEN_BITS = 11 * TARGET_SIZE; this.CONCAT_LEN_BITS_DIV_33 = CONCAT_LEN_BITS/33; this.CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33 = CONCAT_LEN_BITS - CONCAT_LEN_BITS_DIV_33; this.CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33__DIV8 = CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33/8; }
private void findSeed(String[] input) { for(int i=0; i<WORDS.size(); i++){ List<String> seed = new ArrayList<>(Arrays.asList(input)); seed.add(WORDS.get(i)); if (checksumCheck(seed)){ System.out.println(Utils.SPACE_JOINER.join(seed)); } } }
private boolean checksumCheck(List<String> words){ boolean[] concatBits = new boolean[CONCAT_LEN_BITS]; int wordindex = 0;
int hash; for(Iterator checksumLengthBits = words.iterator(); checksumLengthBits.hasNext(); ++wordindex) { String entropyLengthBits = (String)checksumLengthBits.next(); int entropy = Collections.binarySearch(WORDS, entropyLengthBits); if(entropy < 0) { return false; } for(hash = 0; hash < 11; ++hash) { concatBits[wordindex * 11 + hash] = (entropy & 1 << 10 - hash) != 0; } }
byte[] var13 = new byte[CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33__DIV8];
for(hash = 0; hash < var13.length; ++hash) { for(int hashBits = 0; hashBits < 8; ++hashBits) { if(concatBits[hash * 8 + hashBits]) { var13[hash] = (byte)(var13[hash] | 1 << 7 - hashBits); } } }
byte[] var14 = hash(var13, 0, var13.length, SHA256); boolean[] var15 = bytesToBits(var14);
for(int i = 0; i < CONCAT_LEN_BITS_DIV_33; ++i) { if(concatBits[CONCAT_LEN_BITS_MINUS_CONCAT_LEN_BITS_DIV_33 + i] != var15[i]) { return false; } } return true; } private boolean[] bytesToBits(byte[] data) { boolean[] bits = new boolean[data.length * 8];
for(int i = 0; i < data.length; ++i) { for(int j = 0; j < 8; ++j) { bits[i * 8 + j] = (data[i] & 1 << 7 - j) != 0; } } return bits; } public byte[] hash(byte[] input, int offset, int length, MessageDigest sha256) { sha256.reset(); sha256.update(input, offset, length); return sha256.digest(); } }
Seed from the example (faith always acquire host amused mercy horn service series stove off) produces: faith always acquire host amused mercy horn service series stove off ability faith always acquire host amused mercy horn service series stove off across faith always acquire host amused mercy horn service series stove off ahead faith always acquire host amused mercy horn service series stove off alley faith always acquire host amused mercy horn service series stove off announce faith always acquire host amused mercy horn service series stove off armed faith always acquire host amused mercy horn service series stove off ask faith always acquire host amused mercy horn service series stove off avocado faith always acquire host amused mercy horn service series stove off axis faith always acquire host amused mercy horn service series stove off banana faith always acquire host amused mercy horn service series stove off beef faith always acquire host amused mercy horn service series stove off bind faith always acquire host amused mercy horn service series stove off bonus faith always acquire host amused mercy horn service series stove off breeze faith always acquire host amused mercy horn service series stove off buffalo faith always acquire host amused mercy horn service series stove off buyer faith always acquire host amused mercy horn service series stove off canoe faith always acquire host amused mercy horn service series stove off catalog faith always acquire host amused mercy horn service series stove off certain faith always acquire host amused mercy horn service series stove off champion faith always acquire host amused mercy horn service series stove off clap faith always acquire host amused mercy horn service series stove off cloud faith always acquire host amused mercy horn service series stove off coast faith always acquire host amused mercy horn service series stove off comic faith always acquire host amused mercy horn service series stove off corn faith always acquire host amused mercy horn service series stove off cream faith always acquire host amused mercy horn service series stove off crunch faith always acquire host amused mercy horn service series stove off damage faith always acquire host amused mercy horn service series stove off delay faith always acquire host amused mercy horn service series stove off desk faith always acquire host amused mercy horn service series stove off despair faith always acquire host amused mercy horn service series stove off disagree faith always acquire host amused mercy horn service series stove off donor faith always acquire host amused mercy horn service series stove off dumb faith always acquire host amused mercy horn service series stove off dutch faith always acquire host amused mercy horn service series stove off ecology faith always acquire host amused mercy horn service series stove off end faith always acquire host amused mercy horn service series stove off entry faith always acquire host amused mercy horn service series stove off erase faith always acquire host amused mercy horn service series stove off excess faith always acquire host amused mercy horn service series stove off fabric faith always acquire host amused mercy horn service series stove off faith faith always acquire host amused mercy horn service series stove off fence faith always acquire host amused mercy horn service series stove off film faith always acquire host amused mercy horn service series stove off flush faith always acquire host amused mercy horn service series stove off fold faith always acquire host amused mercy horn service series stove off frequent faith always acquire host amused mercy horn service series stove off garden faith always acquire host amused mercy horn service series stove off gauge faith always acquire host amused mercy horn service series stove off glimpse faith always acquire host amused mercy horn service series stove off gospel faith always acquire host amused mercy horn service series stove off guess faith always acquire host amused mercy horn service series stove off harvest faith always acquire host amused mercy horn service series stove off hedgehog faith always acquire host amused mercy horn service series stove off holiday faith always acquire host amused mercy horn service series stove off humble faith always acquire host amused mercy horn service series stove off illegal faith always acquire host amused mercy horn service series stove off indicate faith always acquire host amused mercy horn service series stove off inmate faith always acquire host amused mercy horn service series stove off invite faith always acquire host amused mercy horn service series stove off join faith always acquire host amused mercy horn service series stove off kitchen faith always acquire host amused mercy horn service series stove off label faith always acquire host amused mercy horn service series stove off lawsuit faith always acquire host amused mercy horn service series stove off lesson faith always acquire host amused mercy horn service series stove off live faith always acquire host amused mercy horn service series stove off love faith always acquire host amused mercy horn service series stove off manual faith always acquire host amused mercy horn service series stove off maximum faith always acquire host amused mercy horn service series stove off merry faith always acquire host amused mercy horn service series stove off minor faith always acquire host amused mercy horn service series stove off monkey faith always acquire host amused mercy horn service series stove off mushroom faith always acquire host amused mercy horn service series stove off negative faith always acquire host amused mercy horn service series stove off net faith always acquire host amused mercy horn service series stove off number faith always acquire host amused mercy horn service series stove off obtain faith always acquire host amused mercy horn service series stove off orange faith always acquire host amused mercy horn service series stove off output faith always acquire host amused mercy horn service series stove off panther faith always acquire host amused mercy horn service series stove off patient faith always acquire host amused mercy horn service series stove off permit faith always acquire host amused mercy horn service series stove off pill faith always acquire host amused mercy horn service series stove off plug faith always acquire host amused mercy horn service series stove off potato faith always acquire host amused mercy horn service series stove off pride faith always acquire host amused mercy horn service series stove off prosper faith always acquire host amused mercy horn service series stove off quit faith always acquire host amused mercy horn service series stove off rack faith always acquire host amused mercy horn service series stove off rather faith always acquire host amused mercy horn service series stove off reform faith always acquire host amused mercy horn service series stove off renew faith always acquire host amused mercy horn service series stove off retreat faith always acquire host amused mercy horn service series stove off river faith always acquire host amused mercy horn service series stove off rural faith always acquire host amused mercy horn service series stove off satisfy faith always acquire host amused mercy horn service series stove off scan faith always acquire host amused mercy horn service series stove off seminar faith always acquire host amused mercy horn service series stove off service faith always acquire host amused mercy horn service series stove off shoe faith always acquire host amused mercy horn service series stove off similar faith always acquire host amused mercy horn service series stove off slam faith always acquire host amused mercy horn service series stove off smooth faith always acquire host amused mercy horn service series stove off soft faith always acquire host amused mercy horn service series stove off speak faith always acquire host amused mercy horn service series stove off squeeze faith always acquire host amused mercy horn service series stove off stand faith always acquire host amused mercy horn service series stove off struggle faith always acquire host amused mercy horn service series stove off sugar faith always acquire host amused mercy horn service series stove off surface faith always acquire host amused mercy horn service series stove off system faith always acquire host amused mercy horn service series stove off test faith always acquire host amused mercy horn service series stove off thunder faith always acquire host amused mercy horn service series stove off token faith always acquire host amused mercy horn service series stove off tonight faith always acquire host amused mercy horn service series stove off tray faith always acquire host amused mercy horn service series stove off trend faith always acquire host amused mercy horn service series stove off twin faith always acquire host amused mercy horn service series stove off undo faith always acquire host amused mercy horn service series stove off uphold faith always acquire host amused mercy horn service series stove off utility faith always acquire host amused mercy horn service series stove off verb faith always acquire host amused mercy horn service series stove off voice faith always acquire host amused mercy horn service series stove off waste faith always acquire host amused mercy horn service series stove off wealth faith always acquire host amused mercy horn service series stove off where faith always acquire host amused mercy horn service series stove off wonder faith always acquire host amused mercy horn service series stove off wreck
|