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) 995 B
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("node-fe1-fpe")):"function"==typeof define&&define.amd?define(["exports","node-fe1-fpe"],n):n((e||self).pseudoShuffle={},e.nodeFe1Fpe)}(this,function(e,n){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=/*#__PURE__*/i(n),f="psuedo-shuffle",u=function(e){var n=e.index,i=e.min,u=e.max,l=e.privateKey,r=e.publicKey;if(u-i<3)return n;if((u-i)%2==0){var o=Math.ceil(i+(u-i)/2);if(n===o)return u;n===u&&(n=o),--u}return n<i||n>u?n:t.default.encrypt(u-i+1,n-i,null!=l?l:f,null!=r?r:f)+i};e.decode=function(e){var n=e.index,i=e.min,l=e.max,r=e.privateKey,o=e.publicKey;if(l-i<3)return n;var d=(l-i)%2==0;if(d){if(n>l-1)return Math.ceil(i+(l-i)/2);--l}return n<i||n>l?n:d&&n===u({index:Math.ceil(i+(l-i)/2),max:l,min:i,privateKey:null!=r?r:f,publicKey:null!=o?o:f})?l+1:t.default.decrypt(l-i+1,n-i,null!=r?r:f,null!=o?o:f)+i},e.encode=u}); //# sourceMappingURL=pseudo-shuffle.umd.js.map