Card generation algorithm
(function(){
const CARDS = " ,A,2,3,4,5,6,7,8,9,10,J,Q,K".split(",");
const FLOWER = ["♠", "♥", "♣", "♦"];
let allCards = [];
const allCards1 = [];
const allCards2 = [161, 180, 199, 218, 162, 205, 181, 200, 219, 163, 182, 220, 201, 177, 196, 215, 170, 178, 221, 197, 216, 171, 179, 198, 172, 217, 193, 212, 167, 186, 194, 173, 213, 168, 187, 195, 214, 188, 169, 209, 164, 183, 202, 210, 189, 165, 184, 203, 211, 166, 204, 185];
for ( let c = 10; c <= 13; c++ ) {
for( let v = 1; v <= 13; v++ ) {
allCards1.push( c * 16 + v );
}
}
function createCards (hash, times, cards, hashList) {
hashList.push(hash);
if (times <= 0) return
let h = hash;
allCards.forEach((c) => {
cards.push({card: c, hash: h});
h = h.substring(1) + h.charAt(0);
});
hash = String(CryptoJS.SHA256(hash));
times--;
createCards(hash, times, cards, hashList);
}
function create (hash, times) {
times = times || 12;
let cards = [];
let hashList = [];
createCards(hash, times, cards, hashList);
cards.sort(function (o1, o2) {
if (o1.hash < o2.hash) {
return -1;
} else if (o1.hash == o2.hash) {
return 0;
} else {
return 1;
}
})
return cards;
}
function createCardFram (card, index) {
let flowerIndex = (card & 240) / 16 - 10;
let flower = FLOWER[flowerIndex];
let point = CARDS[card % 16];
let style = flowerIndex % 2 === 0 ? "black" : "red";
let classNames = ["cardbox", style];
if (range && index >= range[0] && index < range[1]) {
classNames.push("active");
}
return '<div class="'+classNames.join(" ")+'"><div class="card"><div class="flower">'
+flower+'</div><div class="point">'
+point+'</div></div><div class="index">'
+index+'</div></div>';
}
let $button = document.getElementById("button");
let $signature = document.getElementById("signature");
let $issus = document.getElementById("issus");
let $cards = document.getElementById("cards");
function generate () {
let beginHash = String(CryptoJS.SHA256($signature.value));
let list = create(beginHash);
let cardsfram = list.map(function (item, index) {
return createCardFram(item.card, index);
});
$cards.innerHTML = cardsfram.join('');
}
$button.addEventListener("click", function(){
let query = '?s=' + $signature.value + '&i=' + $issus.value;
location.replace(location.href.replace(/\?*.*$/, query));
}, false)
if (issus) {
$issus.value = issus;
allCards = parseInt(issus) > 50105 ? allCards2 : allCards1;
}
if (signature) {
$signature.value = signature;
generate();
}
})();
Signature verification
#!/bin/bash
bj_issus='221629'
bj_slat='00000000000000000009e93621499e5a63d79a6293609ce52e95e93dd49cb1be'
bj_signature=''
echo '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDE9QKpw5CHZyf+OfcrT5MCeiCR
CLVZjDVUSPGzwXdoGAcRi/r9y7T8t4/byXNTLky0h9dUGKBowwN7bt7fgMKvWAtz
0Xf4ztfpsEoRHrzRs2r8khPUjihjrz0N+oPQ+ktAh7M95ZnQfgt/hNWFevGRd+SV
sGsWhO8VFrBYb7nS8wIDAQAB
-----END PUBLIC KEY-----' > pub.pem
base64 --decode <<<$bj_signature > signature.sign
echo -n $bj_issus | openssl dgst -sha256 -hmac $bj_slat -binary | openssl dgst -sha256 -verify pub.pem -signature signature.sign