github.com/qjfoidnh/BaiduPCS-Go@v0.0.0-20231011165705-caa18a3765f3/baidupcs/netdisksign/sign2.js (about) 1 function s(j, r) { 2 var a = []; 3 var p = []; 4 var o = ""; 5 var v = j.length; 6 for (var q = 0; q < 256; q++) { 7 a[q] = j.substr((q % v), 1).charCodeAt(0); 8 // console.log(q, q%v); 9 p[q] = q; 10 // console.log(q, a[q], p[q]); 11 } 12 for (var u = q = 0; q < 256; q++) { 13 u = (u + p[q] + a[q]) % 256; 14 var t = p[q]; 15 p[q] = p[u]; 16 p[u] = t; 17 } 18 // console.log(p) 19 for (var i = u = q = 0; q < r.length; q++) { 20 i = (i + 1) % 256; 21 u = (u + p[i]) % 256; 22 var t = p[i]; 23 p[i] = p[u]; 24 p[u] = t; 25 k = p[((p[i] + p[u]) % 256)]; 26 o += String.fromCharCode(r.charCodeAt(q) ^ k); 27 } 28 return o; 29 }; 30 31 function base64encode(t) { 32 var r, e, a, o, n, i, s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 33 for (a = t.length, 34 e = 0, 35 r = ""; a > e; ) { 36 if (o = 255 & t.charCodeAt(e++), 37 e == a) { 38 r += s.charAt(o >> 2), 39 r += s.charAt((3 & o) << 4), 40 r += "=="; 41 break 42 } 43 if (n = t.charCodeAt(e++), 44 e == a) { 45 r += s.charAt(o >> 2), 46 r += s.charAt((3 & o) << 4 | (240 & n) >> 4), 47 r += s.charAt((15 & n) << 2), 48 r += "="; 49 break 50 } 51 i = t.charCodeAt(e++), 52 r += s.charAt(o >> 2), 53 r += s.charAt((3 & o) << 4 | (240 & n) >> 4), 54 r += s.charAt((15 & n) << 2 | (192 & i) >> 6), 55 r += s.charAt(63 & i) 56 } 57 return r 58 } 59 60 var s1 = s("e8c7d729eea7b54551aa594f942decbe", "37dbe07ade9359c1aa70807e847f768c13360ad2"); 61 console.log(s1); 62 console.log(base64encode(s1));