美文网首页
助记词ChecksumException

助记词ChecksumException

作者: 风生水起_2018 | 来源:发表于2019-04-23 16:26 被阅读0次
@Test(expected = MnemonicException.MnemonicChecksumException.class)
public void testBadChecksum() throws Exception {
   String code="bless cloud wheel regular tiny venue bird web grief security dignity zoo"; 
   List<String> words = WHITESPACE_SPLITTER.splitToList(code);
   mc.check(words);
 }
for (String word : words) {
    // Find the words index in the wordlist.
    int ndx;
    if (bip39Language.getLanguageType() == BIP39Language.Language.CHINESE_SIMPLIFIED) {
        ndx = bip39Language.wordList.indexOf(word);
    } else {
        ndx = Collections.binarySearch(this.bip39Language.wordList, word);
    }
    if (ndx < 0) {//该单词不在列表中
        System.out.println("该单词不在列表中 word: " + word + " " + ndx);
        throw new MnemonicException.MnemonicWordException(word);
    }
    System.out.println("单词:" + word + " 位置ndx:"+ndx+" word index:"+wordindex+" 它的11位如下...");
    // Set the next WORDS_LENGTH_BIT bits to the value of the index.
    int concatBitsIndex;
    for (int ii = 0; ii < WORDS_LENGTH_BIT; ++ii) {
        concatBitsIndex = (wordindex * WORDS_LENGTH_BIT) + ii;//11x15=165或者11x12=132
        //concatBits[concatBitsIndex] = (ndx & (1 << (10 - ii))) != 0;
        boolean bitBoolean=(ndx & (1 << (WORDS_LENGTH_BIT - 1 - ii))) != 0;
        System.out.println("    concatBitsIndex: " + concatBitsIndex + " " + bitBoolean);
        concatBits[concatBitsIndex] = bitBoolean;
    }
    ++wordindex;//最大到12、15
}

binarySearch无法对中文助记词排序,看英文文件是从a开始排序好的,中文没有规则,无法二分查找,只能看索引


image.png
public byte[] toEntropy(List<String> words) throws MnemonicChecksumException {
        int checksumLengthBits = concatLenBits / 33;
        int entropyLengthBits = concatLenBits - checksumLengthBits;
        // Extract original entropy as bytes.132/8=16字节
        byte[] entropy = new byte[entropyLengthBits / 8];
        for (int ii = 0; ii < entropy.length; ++ii)
            for (int jj = 0; jj < 8; ++jj)
                if (concatBits[(ii * 8) + jj])
                    entropy[ii] |= 1 << (7 - jj);

        // Take the digest of the entropy.
        byte[] hash = Sha256Hash.hash(entropy);
        boolean[] hashBits = bytesToBits(hash);

        // Check all the checksum bits.
        for (int i = 0; i < checksumLengthBits; ++i) {
            if (concatBits[entropyLengthBits + i] != hashBits[i]) {
                throw new MnemonicException.MnemonicChecksumException();
            }
        }
   }

我们只探讨主流的12位、15位助记词的场景,分成12、15份,每份都是11位
1)在128位后面追加4位校验码。 长度变为了132位,然后分成12份,每份11位值查表得到一个单词, 共记12个助记词。将每个包含11位部分的值与一个已经预先定义2048个单词的字典做对应.
这对助记词在english.txt里都存在,并不是随机取12就可以作为私钥了。concatBits、hashBits一个true、一个false,出现异常
2)15位看下面的图


image.png

相关文章

  • 助记词ChecksumException

    binarySearch无法对中文助记词排序,看英文文件是从a开始排序好的,中文没有规则,无法二分查找,只能看索引...

  • ETH钱包助记词、私钥、Keystore以及创建过程

    助记词 助记词拥有钱包的所有权,可以通过助记词随意转移该钱包下的资产而无需密码。助记词可以生成很多子钱包,目前大部...

  • 助记词

    助记词是明文私钥的另一种表现形式, 最早是由 BIP39 提案提出, 其目的是为了帮助用户记忆复杂的私钥 (64位...

  • OH MY GOD!

    de词根含义:god;助记词:deity,de(神)+ity(状态)=》神 the词根含义:god;助记词:ath...

  • HD Wallet 系列 - 助记词与种子

    原文地址:tpkeep.com 参考 bip39 定义了助记词的生成规则 定义了由助记词导出种子的规则 定义了助记...

  • 【HD-新钱包】BIP39生成助记词

    BIP39标准定义了钱包助记词和种子生成规则。 通过九个步骤即可生成钱包助记词和种子: > 步骤 1~6 生成助记...

  • 221021 助记词

    电梯每下降一层,你的心脏跳动一次。一些记忆被唤醒而其余被埋藏。太久了你已经分不清是墓地选择了你还是你自己把石碑放在...

  • 24个助记词怎么保存最安全

    长期保存比特币等加密货币的小伙伴一定知道助记词的重要性:掌握了助记词也就等用掌握了财富的控制权。因此助记词一定需要...

  • 五笔字根助记词

    字根表 助记词 为了方便学习与掌握,五笔字型输入法的发明人对每个键位上的字根均编写了一首助记词,每句助记词里面都包...

  • 区块链钱包技术要点

    [TOC] 私钥随机性(根种子),助记词的生成,keystore的生成 助记词的生成 使用BIP-39中定义的标准...

网友评论

      本文标题:助记词ChecksumException

      本文链接:https://www.haomeiwen.com/subject/dptbgqtx.html