UNPKG

pseudo-shuffle

Version:

Make the index look like it is shuffled according to the range so that it is not conflicted without the actual shuffle.

3 lines (2 loc) 783 B
function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/e(require("node-fe1-fpe")),r="psuedo-shuffle",i=function(e){var i=e.index,t=e.min,u=e.max,l=e.privateKey,a=e.publicKey;if(u-t<3)return i;if((u-t)%2==0){var f=Math.ceil(t+(u-t)/2);if(i===f)return u;i===u&&(i=f),--u}return i<t||i>u?i:n.default.encrypt(u-t+1,i-t,null!=l?l:r,null!=a?a:r)+t};exports.decode=function(e){var t=e.index,u=e.min,l=e.max,a=e.privateKey,f=e.publicKey;if(l-u<3)return t;var c=(l-u)%2==0;if(c){if(t>l-1)return Math.ceil(u+(l-u)/2);--l}return t<u||t>l?t:c&&t===i({index:Math.ceil(u+(l-u)/2),max:l,min:u,privateKey:null!=a?a:r,publicKey:null!=f?f:r})?l+1:n.default.decrypt(l-u+1,t-u,null!=a?a:r,null!=f?f:r)+u},exports.encode=i; //# sourceMappingURL=pseudo-shuffle.cjs.map