var PkBarcode;
const PkTrxId = 60010000001156;
const PkDate2 = 471119;
const PkRate = 515;
PkDigits = [
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C",
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P",
"Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
];
PkRadix = BigInt(36);
// Encoding Function
function getPkBase62FromBase10(numberString) {
PkNumCharArray = [...numberString];
PkBuf = new Array(numberString.length);
PkCharPos = numberString.length - 1;
PkNumberBigInt = BigInt(numberString);
while (PkNumberBigInt >= PkRadix) {
PkBuf[PkCharPos--] = PkDigits[Number(PkNumberBigInt % PkRadix)];
PkNumberBigInt /= PkRadix;
}
PkBuf[PkCharPos] = PkDigits[Number(PkNumberBigInt)];
return `${PkBuf.join("")}`;
}
// Decoding Function
function getPkBase10FromBase62(floatString) {
PkValue = BigInt(0);
for (PkChar of floatString) {
PkValue = PkValue * PkRadix;
PkCharCode = PkChar.charCodeAt(0);
PkChar >= "0" && PkChar <= "9" ? (PkValue += BigInt(PkCharCode - 48)) : "";
PkChar >= "A" && PkChar <= "Z" ? (PkValue += BigInt(PkCharCode - 65 + 10)) : "";
}
return PkValue.toString();
}
date = new Date();
tempMonth = date.getMonth();
PkMonth = tempMonth < 10 ? `0${tempMonth + 1}` : tempMonth + 1;
PkDay = date.getDate();
PkNumberString = `${PkTrxId}${PkDate2}${PkRate}`;
PkBarcode = getPkBase62FromBase10(PkNumberString);
console.log("encode", PkBarcode);
PkDecodedFloat = getPkBase10FromBase62("23EH5S27I0ZZY4KHGJ");
console.log("decode: ", PkDecodedFloat);
Example- 12345
Encode-123545
Decoode-63972005
0 Comments