Advertisement
Guest User

bbs

a guest
Nov 11th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const bbs = (m, s, n) => {
  2.   const res = [s];
  3.  
  4.   for (let i = 1; i < n; i++) {
  5.     res.push(Math.pow(res[i - 1], 2) % m);
  6.   }
  7.  
  8.   return res.map(e => e & 1);
  9. };
  10.  
  11. /**
  12.  *
  13.  * @param {Number} n
  14.  * @param {Number} s
  15.  * @param {Array<Number>} y
  16.  */
  17. const inv_bbs = (n, s, y) => {
  18.   const bin = y.reduce((str, e) => {
  19.     str += e.toString(2);
  20.     return str;
  21.   }, "");
  22.  
  23.   //   const maxlen = Math.ceil(Math.log2(n + 1));
  24.   //   const helper = Math.floor(Math.log2(maxlen));
  25.  
  26.   //   const xn = (y.length * 8) / 4;
  27.  
  28.   const seq = bbs(n, s, 32);
  29.  
  30.   return [...bin].map((e, index) => e ^ seq[index]).join("");
  31.  
  32.   //   return maxlen;
  33. };
  34.  
  35. console.log(bbs(407 * 588, 3164, 8));
  36.  
  37. console.log(inv_bbs(30353, 17849, [214, 190, 100]));
  38.  
  39. console.log(inv_bbs(243793, 48914, [16, 182, 219, 83]));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement