Snippets Project Page
Author: maroon
Added: 1y
Updated: Never
mIRC: v7.42
Hits: 387
Downloads: 3
Review: entropy
Size: 16.53KB
2 0
Login to vote.
BIP39
v1.0
Create a secure passphrase by converting a hex string of X groups of 32 bits into a 'sentence' of 3*X words. While this is using the BIP39 method to create the sentence, this has nothing to do with bitcoin wallets, so don't ask!
You can also use this to verbally confirm a fingerprint as a sentence of words, instead of speaking a long list of hex digits. And, you can use this to decode the sentence back to a hex string.
Download
JSON
▲ Review
▼ Source
/* { BIP39 by maroon $bip39(hex) -> list of words $bip39(-d[x],list of words) -> hex This script lets you can create a passphrase as a 'sentence' where each 'word' has 11 bits of entropy condensed into the first 4 letters of each word. For example, if you need to have a password with 128 bits of strength, you could have a string like 77add1d5f41223d5582fca736a5cb335 but this would be very hard to memorize. With this script, you could instead do: //echo -a $bip39(77add1d5f41223d5582fca736a5cb335) result: jeans hub install trial captain turkey gaze welcome inflict fancy coast hen ... and each of the first 11 words represent 11-bit chunks of this string for a total of 121 bits, and the remaining 7-of-128 bits are in the 12th word along with a 4-bit checksum. While it can be hard to memorize+remember 12 random words in the correct order, it's certainly much easier than memorizing 32 hex digits! If you're satisfied with a password having a smaller strength, then you can use the first 7 or 8 words instead, for 77 or 88 bits of strength. Because the first 4 letters of each word are guaranteed to be unique, you can choose to either use the entire word in your passphrase, or can choose to use the 1st 4 letters of words longer than 4, or the entire 3-letter word. This can also be used to communicate a hex 'fingerprint' using a sentence instead of many hex digits. If a fingerprint is the 160 bits of a string created by $sha1, instead of verifying 40 hex digits, this alias can transform them into a sentence of 15 words. With 2 people needing to have the same fingerprint, they can verify that they both have the same list of 15 words in the correct order. The words are designed to avoid words that sound or are spelled similarly. Another use for this script is when someone needing to accurately transfer a hex key/string to someone else, they can use $big39(hex) to transform the hex string into a list of words, and the next person can use $bip39(-d,list of words) to translate the sentence back to a hex string. If using -dx instead of -d, the list of words don't need to have more than 4 letters. For example, if the other person needs to have a 160-bit 2-factor-authentication key given to them, the method used by Google Authenticator is to transform the 160bit string into 32 base32 digits, and they need to accurately input the 32 alphanumeric digits into their program. With this method, you could translate the 160-bit string into 15 words, and the other user could instead input the 15 words into $bip39 or into their program, and it could then translate the 15 words back to the 160-bit string. The above example of translating a 128-bit hex string can be reversed by this next command, which decodes the 12 words back to the 128-bit hex string. Because the -x switch is used, no more than 4 letters of any word are needed. //echo -a $bip39(-dx,jean hub inst tria capt turk gaze welc infl fanc coas hen) Note: when decoding from a sentence to hex, $bip39 warns you if the checksum doesn't match, and it's up to you what that's supposed to mean. If your sentence does not decode to a hex string accompanied by the 'correct' checksum, the return string does return the hex string, but also returns 'invalid checksum' While this mimics the BIP39 protocol that's used by some bitcoins, this does not do any of the other 'wallet' related math. This is simply an update of the PGP word list script, because this creates a shorter 'sentence' due to having a larger word list. While the PGP word list can support any hex length, BIP39 supports ONLY string lengths being a multiple of 32 bits, so if you need to handle some other length, you'll need to decide how you want to pad it. While this has a 'checksum', it is simply used as filler for the 1 bit of slack space between 11*3 bits and a 32-bit uint32. It also uses the same word list for all words, unlike the PGP word list that has a separate list for the odd-vs-even words. This transforms a hex string of k*32 bits into a sentence containing 3*k words, where the final k/11 words is where the checksum is located, and those bits don't contribute to the security because the checksum bits are calculated from the input string. i.e. if your input string is 11*32=352 bits, the last 11 bits of the 'sentence' is a checksum, so the final 1 word of 11*3=33 words can be calculated by knowing the 1st 32 words. While the BIP39 protocol is defined ONLY for input bit-lengths 128-256, this script unofficially extends support to input string lengths as long as 16384 bits. However, this script retains the design that requires the input bit length to be a multiple of 32 and that the a checksum length matches the count of 32-bit words. Because BIP39 uses a checksum created from SHA256, and the bit length of the checksum matches the number of 32-bit chunks, it didn't need to arbitrarily limit the range to be 128-256 bits. So, I enabled the range to be as low as 1*32 bits, and as high as 256*32=8192 bits using the full SHA256 hash. To extend that range to be 512*32 bits, I simply switched the checksum to use SHA512 if the input had more than 256 32-bit chunks. } */ alias bip39 { if (-d* iswm $1) { var %switches $1 } else { var %cksum.length $len($1) / 8 , %ms 3 * %cksum.length if ( (!$regex($1,^[0-9a-fA-F]+$)) || (. isin %cksum.length) || (%cksum.length !isnum 1-512)) goto bip39syntax } hfree -w bip39 | hmake bip39 911 | .timer 1 0 hfree -w bip39 hadd bip39 list1 eNotlguW4yoMRLfSW+MXhxcMHgHJpFf/6spzclKFQQghJEGIoefRf0Ksra6vuBXB2At8056l8zGHRWhZSP69LYv2lExKZU6oZhdOaeyb7+FnLajSsGDsuWpS48+uRq8Nn4z8qtiS1jDQbq1rh/YTcrgkkTP/mrx5j+f/pFB0VnA38B16KnCFio3Iio9HqAYNTH9YwJ4jVC15FP7YfFhR+1mCxur54zOqXcM0VifeacHU3+IG03gOWdcK460W6Wp8t/IFx0d4DgxsozP5egahST8CcwhW0RrtE77azRlW2Qb/1n6Ix43uz1PulFk9tC8ae3riqJ6qW94P9PQDG/thUt/riev6y7u6lCRvuEP7WE+fMD9Oq/Qe4PpnI/W3FgKi638FdneNNg6+rhIMQut1mYfJZVU6LT0BP19tEUCnHWjEa3ayATux204pMxlFj2E+XNiZWX37F/5jbVvl4SFiq7rA+gx7/YTJ/yqMzBn88Ocsji435z6laK7nKTvWs5WlzzVkylohvaCCAWvVtTNj/wJ8/wvGnYmrfXiQ+Sns5W7fawD7lNC7mIfQe6SQB0xofcKrgOaozX7KHJjzeWw56/PSkMT+1vkTQ/wK0rM06VZDS8eQpTOGQ//mAR2Jt46gYiyGM44h6vpBvTDT/6UhZB7bEaciPlEwdTTCl3wUtVcdYSxaFuzA1pnHkgKJK8bcWMpDoKyhfaCyPLVlqMp3sTTPb7GOSyjVpbvOXh6VrwnIsehehLvoUwqavgMVNX0TtlTaLxree0dcrMaHLams9/TG2Ql1YsLTsfumWmCxVgLjFIjYXFcbw3HqCGDfYNsOKNxT2gcHIpSGofyMQ0EdxxkFSl7Blr4xXgDLqJBgzTByVUS8RspZHIsgi3fKxfFXf+lTaLmR5gejmM8g8uYOpSyA5ZePyh6tehRY5RCsHk+m+3JWJ+ND1bZVGi8caqP75MHyd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hLnD6sGtK5CuCm8d0oE86FhRDM9tQ4B0wFi12Ysec+92eDp1EwG4KfVkbpnOpzZ92PTXxId5VXLUZndk61R44lQHCo39d0jHzAHIRDTbh+rPxufmZVkRKZbJuuvHQhaFGcD3Uta+sPWrrCrweWh9eZagpfAj36whs5C8mTdvbYVb8KGNsAjeEjiM7gOZM1QJ5dR9UsRfWWklZgCa22l9MlWYOSFkM4ttwtknUeQ70qw78jjr4QWa9XT3EmwByjErKjLbS7efC8Xz4zW7Pzvw1jUz+aMRI/4510r8+Nxh47jJTMn1HeDcHbjHhCkygNTd8q3HVPg76HYQNiuzy3ZmTx2SO55Gam6STVNJaZiBlsniOrYXYPpfJAXUUJZGV3wyOuysZZ7z217Nw7PtWc021/Vb57MI4xKoRgdD83isbmEctME+ZX1eD4Dhqj/9w/Fmp4Wi3wVaCOlIykrBzou+AXxxv/6B4l5B7hZ6h94CedKRAQl3Y6AqL2j8Ni6OjaACg4/8Hy3+j7lMpM1JFJehtK7UApIi46Kx4kvPviNr0vAPJ21Fa2Da9J8hq2osJX+d/GwvNHKd8UE8oZTLJXLxKynoUGihdwLWtzevotjinuWU6OG3dfEH6leF4ANkn5p9G4ZP67tui4X6LLiiKyXDuVXSW3Cpsqv4iVml7IBW4L4RfIDkr6qwkGDQm9Wizoawc5aXC5mQDPoF/kXSvuTrG/3e+5bJwyf/kfqNYpGwlZ9fpPW3lP8BJvnbTw var %i 1 , %index 0 | while (%i isnum 1-4) { bset -tc &maroon.tmp 1 $hget(bip39,list $+ %i) | noop $decode(&maroon.tmp,bm) if ($decompress(&maroon.tmp,bm2) != 1) { var %err decompress failure | goto bip39syntax } var %tmp $bvar(&maroon.tmp,1-).text var %j 1 | while ($gettok(%tmp,%j,32) != $null) { hadd bip39 %index $v1 | inc %j | inc %index } hdel bip39 list $+ %i | inc %i } if ($hget(bip39,0).item != 2048) { var %err items $v1 s/b $v2 | goto bip39syntax } if (-d* iswm $1) { var %token 1 , %bits , %hex tokenize 32 $2- | var %ms $0 , %cksum.length %ms / 3 , %inputbytes $calc(%ms *4/3) if (. isin %cksum.length) goto bip39syntax while ($gettok($1-,%token,32) != $null) { var %word $remove($v1,*,?,&) | if ((x isin %switches) && ($len(%word) >= 4)) var %word $left(%word,4) $+ * var %item $hfind(bip39,%word,1,w).data | if (%item == $null) { var %err invalid word %word | goto bip39syntax } var %bits %bits $+ $base(%item,10,2,11) if ($len(%bits) >= 32) var %hex %hex $+ $base($left(%bits,32),2,16,8) , %bits $mid(%bits,33) inc %token } while ($len(%bits) >= 4) { var %hex %hex $+ $base($left(%bits,4),2,16) , %bits $mid(%bits,5) } bset -c &maroon.tmp 1 $regsubex(%hex,/(..)/g,$base(\t,16,10) $+ $chr(32)) bcopy -c &maroon.tmp2 1 &maroon.tmp 1 %inputbytes if (%inputbytes <= 1024) var %cksum $sha256(&maroon.tmp2,1) else var %cksum $sha512(&maroon.tmp2,1) var %cksum $regsubex(%cksum,/(..)/g,$base(\t,16,2,8)) var %hex2 %hex , %verify %bits , %hex $left(%hex,$calc(2*%inputbytes)) while ($len(%verify) < %cksum.length) { var %verify $base($right(%hex2,1),16,2,4) $+ %verify , %hex2 $left(%hex2,-1) } if (z $+ $left(%cksum,%cksum.length) != z $+ $right(%verify,%cksum.length)) var %hex %hex invalid checksum $v1 vs $v2 !return $lower(%hex) } bset -c &maroon.tmp 1 $regsubex($1,/(..)/g,$base(\t,16,10) $+ $chr(32)) var %ptr 1 , %last 0 , %bits , %words , %inputbytes $len($1) / 2 | while (1) { if (%last) var %newbits else var %newbits $base($bvar(&maroon.tmp,%ptr),10,2,8) , %ptr %ptr + 1 var %bits %bits $+ %newbits if ($len(%bits) < 11) { if (%last) { echo 4 -a should never see this break please tell how this happens | halt } if (%newbits != $null) { continue } if (%inputbytes <= 1024) var %cksum $sha256(&maroon.tmp,1) , %foo %inputbytes else var %cksum $sha512(&maroon.tmp,1) , %foo %inputbytes var %cksum $regsubex(%cksum,/(.{8})/g,$base(\t,16,2,32)) , %bits %bits $+ $left(%cksum,%cksum.length) , %last 1 } var %item $base($left(%bits,11),2,10) , %bits $mid(%bits,12) var %words %words $hget(bip39,%item) | if ($numtok(%words,32) = %ms) break } return %words :bip39syntax echo -sc info *$bip39(hex) *$bip39(-d[x],words list) hex multiple of 32bits <= 16384, word count multiple of 3. -x = uses only 1st 4 letters of words fail: %err halt }
Changelog:
0
0
Review: entropy
I really don't use or have any use for this snippet, but some might find it useful.
Good work!
I really don't use or have any use for this snippet, but some might find it useful.
Good work!