- // Handle entropy of zero
- if (entropyStr == "") {
- return {
- binaryStr: binLeadingZeros,
- hexStr: hexLeadingZeros || "0",
- cleanStr: leadingZeros,
- base: base,
- }
- }
- // If using hex, should always be multiples of 4 bits, which can get
- // out of sync if first number has leading 0 bits, eg 2 in hex is 0010
- // which would show up as 10, thus missing 2 bits it should have.
- if (base.asInt == 16) {
- var firstDigit = parseInt(entropyStr[0], 16);
- if (firstDigit >= 4 && firstDigit < 8) {
- binLeadingZeros += "0";
- }
- else if (firstDigit >= 2 && firstDigit < 4) {
- binLeadingZeros += "00";
- }
- else if (firstDigit >= 1 && firstDigit < 2) {
- binLeadingZeros += "000";
- }
- }
- // Convert entropy to different foramts
- var entropyInt = BigInteger.parse(entropyStr, base.asInt);
- var entropyBin = binLeadingZeros + entropyInt.toString(2);
- var entropyHex = hexLeadingZeros + entropyInt.toString(16);
- var entropyClean = leadingZeros + entropyStr;