js-confuser 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +43 -43
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -20
  3. package/.github/workflows/node.js.yml +28 -28
  4. package/.prettierrc +4 -4
  5. package/CHANGELOG.md +1015 -987
  6. package/CODE_OF_CONDUCT.md +131 -131
  7. package/CONTRIBUTING.md +52 -52
  8. package/LICENSE +21 -21
  9. package/Migration.md +72 -72
  10. package/README.md +86 -86
  11. package/dist/constants.js +43 -43
  12. package/dist/index.js +14 -23
  13. package/dist/obfuscator.js +31 -25
  14. package/dist/order.js +4 -4
  15. package/dist/presets.js +31 -31
  16. package/dist/templates/integrityTemplate.js +4 -4
  17. package/dist/templates/template.js +1 -2
  18. package/dist/transforms/astScrambler.js +1 -2
  19. package/dist/transforms/calculator.js +1 -2
  20. package/dist/transforms/controlFlowFlattening.js +60 -41
  21. package/dist/transforms/deadCode.js +1 -2
  22. package/dist/transforms/dispatcher.js +4 -5
  23. package/dist/transforms/extraction/duplicateLiteralsRemoval.js +1 -2
  24. package/dist/transforms/extraction/objectExtraction.js +1 -2
  25. package/dist/transforms/finalizer.js +1 -2
  26. package/dist/transforms/flatten.js +1 -2
  27. package/dist/transforms/identifier/globalConcealing.js +15 -2
  28. package/dist/transforms/identifier/movedDeclarations.js +8 -7
  29. package/dist/transforms/identifier/renameVariables.js +7 -7
  30. package/dist/transforms/lock/integrity.js +8 -9
  31. package/dist/transforms/lock/lock.js +1 -2
  32. package/dist/transforms/minify.js +11 -29
  33. package/dist/transforms/opaquePredicates.js +1 -2
  34. package/dist/transforms/pack.js +1 -2
  35. package/dist/transforms/plugin.js +18 -19
  36. package/dist/transforms/preparation.js +16 -16
  37. package/dist/transforms/renameLabels.js +1 -2
  38. package/dist/transforms/rgf.js +8 -9
  39. package/dist/transforms/shuffle.js +1 -2
  40. package/dist/transforms/string/encoding.js +1 -2
  41. package/dist/transforms/string/stringCompression.js +3 -4
  42. package/dist/transforms/string/stringConcealing.js +1 -2
  43. package/dist/transforms/string/stringEncoding.js +1 -2
  44. package/dist/transforms/variableMasking.js +1 -2
  45. package/dist/utils/NameGen.js +2 -2
  46. package/dist/utils/PredicateGen.js +1 -2
  47. package/dist/utils/ast-utils.js +87 -88
  48. package/dist/utils/function-utils.js +8 -8
  49. package/dist/utils/node.js +5 -6
  50. package/dist/utils/object-utils.js +4 -4
  51. package/dist/utils/random-utils.js +20 -20
  52. package/dist/utils/static-utils.js +1 -2
  53. package/dist/validateOptions.js +4 -7
  54. package/index.d.ts +17 -17
  55. package/package.json +61 -59
  56. package/src/constants.ts +168 -168
  57. package/src/index.ts +118 -118
  58. package/src/obfuscationResult.ts +49 -49
  59. package/src/obfuscator.ts +501 -497
  60. package/src/options.ts +407 -407
  61. package/src/order.ts +54 -54
  62. package/src/presets.ts +125 -125
  63. package/src/templates/bufferToStringTemplate.ts +57 -57
  64. package/src/templates/deadCodeTemplates.ts +1185 -1185
  65. package/src/templates/getGlobalTemplate.ts +76 -76
  66. package/src/templates/integrityTemplate.ts +64 -64
  67. package/src/templates/setFunctionLengthTemplate.ts +11 -11
  68. package/src/templates/stringCompressionTemplate.ts +20 -20
  69. package/src/templates/tamperProtectionTemplates.ts +120 -120
  70. package/src/templates/template.ts +224 -224
  71. package/src/transforms/astScrambler.ts +99 -99
  72. package/src/transforms/calculator.ts +99 -99
  73. package/src/transforms/controlFlowFlattening.ts +1716 -1680
  74. package/src/transforms/deadCode.ts +82 -82
  75. package/src/transforms/dispatcher.ts +450 -450
  76. package/src/transforms/extraction/duplicateLiteralsRemoval.ts +156 -158
  77. package/src/transforms/extraction/objectExtraction.ts +186 -186
  78. package/src/transforms/finalizer.ts +74 -74
  79. package/src/transforms/flatten.ts +421 -418
  80. package/src/transforms/identifier/globalConcealing.ts +315 -295
  81. package/src/transforms/identifier/movedDeclarations.ts +252 -251
  82. package/src/transforms/identifier/renameVariables.ts +328 -321
  83. package/src/transforms/lock/integrity.ts +117 -117
  84. package/src/transforms/lock/lock.ts +418 -418
  85. package/src/transforms/minify.ts +615 -629
  86. package/src/transforms/opaquePredicates.ts +100 -100
  87. package/src/transforms/pack.ts +239 -239
  88. package/src/transforms/plugin.ts +173 -173
  89. package/src/transforms/preparation.ts +349 -347
  90. package/src/transforms/renameLabels.ts +175 -175
  91. package/src/transforms/rgf.ts +322 -322
  92. package/src/transforms/shuffle.ts +82 -82
  93. package/src/transforms/string/encoding.ts +144 -144
  94. package/src/transforms/string/stringCompression.ts +128 -128
  95. package/src/transforms/string/stringConcealing.ts +312 -312
  96. package/src/transforms/string/stringEncoding.ts +80 -80
  97. package/src/transforms/string/stringSplitting.ts +77 -77
  98. package/src/transforms/variableMasking.ts +257 -257
  99. package/src/utils/IntGen.ts +33 -33
  100. package/src/utils/NameGen.ts +116 -116
  101. package/src/utils/PredicateGen.ts +61 -61
  102. package/src/utils/ast-utils.ts +663 -663
  103. package/src/utils/function-utils.ts +50 -50
  104. package/src/utils/gen-utils.ts +48 -48
  105. package/src/utils/node.ts +78 -78
  106. package/src/utils/object-utils.ts +21 -21
  107. package/src/utils/random-utils.ts +93 -93
  108. package/src/utils/static-utils.ts +66 -66
  109. package/src/validateOptions.ts +256 -259
  110. package/tsconfig.json +13 -14
  111. package/dist/probability.js +0 -1
  112. package/dist/transforms/functionOutlining.js +0 -230
  113. package/dist/utils/ControlObject.js +0 -125
@@ -1,1185 +1,1185 @@
1
- import Template from "./template";
2
-
3
- export const deadCodeTemplates = [
4
- new Template(`
5
- // Modified by bryanchow for namespace control and higher compressibility
6
- // See https://gist.github.com/1649353 for full revision history from original
7
-
8
- /*
9
- * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
10
- * in FIPS 180-2
11
- * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
12
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
13
- * Distributed under the BSD License
14
- * See http://pajhome.org.uk/crypt/md5 for details.
15
- * Also http://anmar.eu.org/projects/jssha2/
16
- */
17
-
18
- var sha256 = (function() {
19
-
20
- /*
21
- * Configurable variables. You may need to tweak these to be compatible with
22
- * the server-side, but the defaults work in most cases.
23
- */
24
- var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
25
- var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
26
-
27
- /*
28
- * These are the functions you'll usually want to call
29
- * They take string arguments and return either hex or base-64 encoded strings
30
- */
31
- function hex_sha256(s) { return rstr2hex(rstr_sha256(str2rstr_utf8(s))); }
32
- function b64_sha256(s) { return rstr2b64(rstr_sha256(str2rstr_utf8(s))); }
33
- function any_sha256(s, e) { return rstr2any(rstr_sha256(str2rstr_utf8(s)), e); }
34
- function hex_hmac_sha256(k, d)
35
- { return rstr2hex(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }
36
- function b64_hmac_sha256(k, d)
37
- { return rstr2b64(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }
38
- function any_hmac_sha256(k, d, e)
39
- { return rstr2any(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
40
-
41
- /*
42
- * Perform a simple self-test to see if the VM is working
43
- */
44
- function sha256_vm_test()
45
- {
46
- return hex_sha256("abc").toLowerCase() ==
47
- "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
48
- }
49
-
50
- /*
51
- * Calculate the sha256 of a raw string
52
- */
53
- function rstr_sha256(s)
54
- {
55
- return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8));
56
- }
57
-
58
- /*
59
- * Calculate the HMAC-sha256 of a key and some data (raw strings)
60
- */
61
- function rstr_hmac_sha256(key, data)
62
- {
63
- var bkey = rstr2binb(key);
64
- if(bkey.length > 16) bkey = binb_sha256(bkey, key.length * 8);
65
-
66
- var ipad = Array(16), opad = Array(16);
67
- for(var i = 0; i < 16; i++)
68
- {
69
- ipad[i] = bkey[i] ^ 0x36363636;
70
- opad[i] = bkey[i] ^ 0x5C5C5C5C;
71
- }
72
-
73
- var hash = binb_sha256(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
74
- return binb2rstr(binb_sha256(opad.concat(hash), 512 + 256));
75
- }
76
-
77
- /*
78
- * Convert a raw string to a hex string
79
- */
80
- function rstr2hex(input)
81
- {
82
- try { hexcase } catch(e) { hexcase=0; }
83
- var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
84
- var output = "";
85
- var x;
86
- for(var i = 0; i < input.length; i++)
87
- {
88
- x = input.charCodeAt(i);
89
- output += hex_tab.charAt((x >>> 4) & 0x0F)
90
- + hex_tab.charAt( x & 0x0F);
91
- }
92
- return output;
93
- }
94
-
95
- /*
96
- * Convert a raw string to a base-64 string
97
- */
98
- function rstr2b64(input)
99
- {
100
- try { b64pad } catch(e) { b64pad=''; }
101
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
102
- var output = "";
103
- var len = input.length;
104
- for(var i = 0; i < len; i += 3)
105
- {
106
- var triplet = (input.charCodeAt(i) << 16)
107
- | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
108
- | (i + 2 < len ? input.charCodeAt(i+2) : 0);
109
- for(var j = 0; j < 4; j++)
110
- {
111
- if(i * 8 + j * 6 > input.length * 8) output += b64pad;
112
- else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
113
- }
114
- }
115
- return output;
116
- }
117
-
118
- /*
119
- * Convert a raw string to an arbitrary string encoding
120
- */
121
- function rstr2any(input, encoding)
122
- {
123
- var divisor = encoding.length;
124
- var remainders = Array();
125
- var i, q, x, quotient;
126
-
127
- /* Convert to an array of 16-bit big-endian values, forming the dividend */
128
- var dividend = Array(Math.ceil(input.length / 2));
129
- for(i = 0; i < dividend.length; i++)
130
- {
131
- dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
132
- }
133
-
134
- /*
135
- * Repeatedly perform a long division. The binary array forms the dividend,
136
- * the length of the encoding is the divisor. Once computed, the quotient
137
- * forms the dividend for the next step. We stop when the dividend is zero.
138
- * All remainders are stored for later use.
139
- */
140
- while(dividend.length > 0)
141
- {
142
- quotient = Array();
143
- x = 0;
144
- for(i = 0; i < dividend.length; i++)
145
- {
146
- x = (x << 16) + dividend[i];
147
- q = Math.floor(x / divisor);
148
- x -= q * divisor;
149
- if(quotient.length > 0 || q > 0)
150
- quotient[quotient.length] = q;
151
- }
152
- remainders[remainders.length] = x;
153
- dividend = quotient;
154
- }
155
-
156
- /* Convert the remainders to the output string */
157
- var output = "";
158
- for(i = remainders.length - 1; i >= 0; i--)
159
- output += encoding.charAt(remainders[i]);
160
-
161
- /* Append leading zero equivalents */
162
- var full_length = Math.ceil(input.length * 8 /
163
- (Math.log(encoding.length) / Math.log(2)))
164
- for(i = output.length; i < full_length; i++)
165
- output = encoding[0] + output;
166
-
167
- return output;
168
- }
169
-
170
- /*
171
- * Encode a string as utf-8.
172
- * For efficiency, this assumes the input is valid utf-16.
173
- */
174
- function str2rstr_utf8(input)
175
- {
176
- var output = "";
177
- var i = -1;
178
- var x, y;
179
-
180
- while(++i < input.length)
181
- {
182
- /* Decode utf-16 surrogate pairs */
183
- x = input.charCodeAt(i);
184
- y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
185
- if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
186
- {
187
- x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
188
- i++;
189
- }
190
-
191
- /* Encode output as utf-8 */
192
- if(x <= 0x7F)
193
- output += String.fromCharCode(x);
194
- else if(x <= 0x7FF)
195
- output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
196
- 0x80 | ( x & 0x3F));
197
- else if(x <= 0xFFFF)
198
- output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
199
- 0x80 | ((x >>> 6 ) & 0x3F),
200
- 0x80 | ( x & 0x3F));
201
- else if(x <= 0x1FFFFF)
202
- output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
203
- 0x80 | ((x >>> 12) & 0x3F),
204
- 0x80 | ((x >>> 6 ) & 0x3F),
205
- 0x80 | ( x & 0x3F));
206
- }
207
- return output;
208
- }
209
-
210
- /*
211
- * Encode a string as utf-16
212
- */
213
- function str2rstr_utf16le(input)
214
- {
215
- var output = "";
216
- for(var i = 0; i < input.length; i++)
217
- output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
218
- (input.charCodeAt(i) >>> 8) & 0xFF);
219
- return output;
220
- }
221
-
222
- function str2rstr_utf16be(input)
223
- {
224
- var output = "";
225
- for(var i = 0; i < input.length; i++)
226
- output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
227
- input.charCodeAt(i) & 0xFF);
228
- return output;
229
- }
230
-
231
- /*
232
- * Convert a raw string to an array of big-endian words
233
- * Characters >255 have their high-byte silently ignored.
234
- */
235
- function rstr2binb(input)
236
- {
237
- var output = Array(input.length >> 2);
238
- for(var i = 0; i < output.length; i++)
239
- output[i] = 0;
240
- for(var i = 0; i < input.length * 8; i += 8)
241
- output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
242
- return output;
243
- }
244
-
245
- /*
246
- * Convert an array of big-endian words to a string
247
- */
248
- function binb2rstr(input)
249
- {
250
- var output = "";
251
- for(var i = 0; i < input.length * 32; i += 8)
252
- output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
253
- return output;
254
- }
255
-
256
- /*
257
- * Main sha256 function, with its support functions
258
- */
259
- function sha256_S (X, n) {return ( X >>> n ) | (X << (32 - n));}
260
- function sha256_R (X, n) {return ( X >>> n );}
261
- function sha256_Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
262
- function sha256_Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
263
- function sha256_Sigma0256(x) {return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));}
264
- function sha256_Sigma1256(x) {return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));}
265
- function sha256_Gamma0256(x) {return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));}
266
- function sha256_Gamma1256(x) {return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));}
267
- function sha256_Sigma0512(x) {return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));}
268
- function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}
269
- function sha256_Gamma0512(x) {return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7));}
270
- function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}
271
-
272
- var sha256_K = new Array
273
- (
274
- 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,
275
- -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
276
- 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,
277
- 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,
278
- -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,
279
- 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,
280
- 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,
281
- -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,
282
- 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,
283
- 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,
284
- -1866530822, -1538233109, -1090935817, -965641998
285
- );
286
-
287
- function binb_sha256(m, l)
288
- {
289
- var HASH = new Array(1779033703, -1150833019, 1013904242, -1521486534,
290
- 1359893119, -1694144372, 528734635, 1541459225);
291
- var W = new Array(64);
292
- var a, b, c, d, e, f, g, h;
293
- var i, j, T1, T2;
294
-
295
- /* append padding */
296
- m[l >> 5] |= 0x80 << (24 - l % 32);
297
- m[((l + 64 >> 9) << 4) + 15] = l;
298
-
299
- for(i = 0; i < m.length; i += 16)
300
- {
301
- a = HASH[0];
302
- b = HASH[1];
303
- c = HASH[2];
304
- d = HASH[3];
305
- e = HASH[4];
306
- f = HASH[5];
307
- g = HASH[6];
308
- h = HASH[7];
309
-
310
- for(j = 0; j < 64; j++)
311
- {
312
- if (j < 16) W[j] = m[j + i];
313
- else W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
314
- sha256_Gamma0256(W[j - 15])), W[j - 16]);
315
-
316
- T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
317
- sha256_K[j]), W[j]);
318
- T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
319
- h = g;
320
- g = f;
321
- f = e;
322
- e = safe_add(d, T1);
323
- d = c;
324
- c = b;
325
- b = a;
326
- a = safe_add(T1, T2);
327
- }
328
-
329
- HASH[0] = safe_add(a, HASH[0]);
330
- HASH[1] = safe_add(b, HASH[1]);
331
- HASH[2] = safe_add(c, HASH[2]);
332
- HASH[3] = safe_add(d, HASH[3]);
333
- HASH[4] = safe_add(e, HASH[4]);
334
- HASH[5] = safe_add(f, HASH[5]);
335
- HASH[6] = safe_add(g, HASH[6]);
336
- HASH[7] = safe_add(h, HASH[7]);
337
- }
338
- return HASH;
339
- }
340
-
341
- function safe_add (x, y)
342
- {
343
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
344
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
345
- return (msw << 16) | (lsw & 0xFFFF);
346
- }
347
-
348
- return {
349
- hex: hex_sha256,
350
- b64: b64_hmac_sha256,
351
- any: any_hmac_sha256,
352
- hex_hmac: hex_hmac_sha256,
353
- b64_hmac: b64_hmac_sha256,
354
- any_hmac: any_hmac_sha256
355
- };
356
-
357
- }());
358
-
359
- console.log(sha256)`),
360
- new Template(`
361
- /*! https://mths.be/utf8js v3.0.0 by @mathias */
362
- ;(function(root) {
363
-
364
- var stringFromCharCode = String.fromCharCode;
365
-
366
- // Taken from https://mths.be/punycode
367
- function ucs2decode(string) {
368
- var output = [];
369
- var counter = 0;
370
- var length = string.length;
371
- var value;
372
- var extra;
373
- while (counter < length) {
374
- value = string.charCodeAt(counter++);
375
- if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
376
- // high surrogate, and there is a next character
377
- extra = string.charCodeAt(counter++);
378
- if ((extra & 0xFC00) == 0xDC00) { // low surrogate
379
- output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
380
- } else {
381
- // unmatched surrogate; only append this code unit, in case the next
382
- // code unit is the high surrogate of a surrogate pair
383
- output.push(value);
384
- counter--;
385
- }
386
- } else {
387
- output.push(value);
388
- }
389
- }
390
- return output;
391
- }
392
-
393
- // Taken from https://mths.be/punycode
394
- function ucs2encode(array) {
395
- var length = array.length;
396
- var index = -1;
397
- var value;
398
- var output = '';
399
- while (++index < length) {
400
- value = array[index];
401
- if (value > 0xFFFF) {
402
- value -= 0x10000;
403
- output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
404
- value = 0xDC00 | value & 0x3FF;
405
- }
406
- output += stringFromCharCode(value);
407
- }
408
- return output;
409
- }
410
-
411
- function checkScalarValue(codePoint) {
412
- if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
413
- throw Error(
414
- 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
415
- ' is not a scalar value'
416
- );
417
- }
418
- }
419
- /*--------------------------------------------------------------------------*/
420
-
421
- function createByte(codePoint, shift) {
422
- return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
423
- }
424
-
425
- function encodeCodePoint(codePoint) {
426
- if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
427
- return stringFromCharCode(codePoint);
428
- }
429
- var symbol = '';
430
- if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
431
- symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
432
- }
433
- else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
434
- checkScalarValue(codePoint);
435
- symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
436
- symbol += createByte(codePoint, 6);
437
- }
438
- else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
439
- symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
440
- symbol += createByte(codePoint, 12);
441
- symbol += createByte(codePoint, 6);
442
- }
443
- symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
444
- return symbol;
445
- }
446
-
447
- function utf8encode(string) {
448
- var codePoints = ucs2decode(string);
449
- var length = codePoints.length;
450
- var index = -1;
451
- var codePoint;
452
- var byteString = '';
453
- while (++index < length) {
454
- codePoint = codePoints[index];
455
- byteString += encodeCodePoint(codePoint);
456
- }
457
- return byteString;
458
- }
459
-
460
- /*--------------------------------------------------------------------------*/
461
-
462
- function readContinuationByte() {
463
- if (byteIndex >= byteCount) {
464
- throw Error('Invalid byte index');
465
- }
466
-
467
- var continuationByte = byteArray[byteIndex] & 0xFF;
468
- byteIndex++;
469
-
470
- if ((continuationByte & 0xC0) == 0x80) {
471
- return continuationByte & 0x3F;
472
- }
473
-
474
- // If we end up here, it’s not a continuation byte
475
- throw Error('Invalid continuation byte');
476
- }
477
-
478
- function decodeSymbol() {
479
- var byte1;
480
- var byte2;
481
- var byte3;
482
- var byte4;
483
- var codePoint;
484
-
485
- if (byteIndex > byteCount) {
486
- throw Error('Invalid byte index');
487
- }
488
-
489
- if (byteIndex == byteCount) {
490
- return false;
491
- }
492
-
493
- // Read first byte
494
- byte1 = byteArray[byteIndex] & 0xFF;
495
- byteIndex++;
496
-
497
- // 1-byte sequence (no continuation bytes)
498
- if ((byte1 & 0x80) == 0) {
499
- return byte1;
500
- }
501
-
502
- // 2-byte sequence
503
- if ((byte1 & 0xE0) == 0xC0) {
504
- byte2 = readContinuationByte();
505
- codePoint = ((byte1 & 0x1F) << 6) | byte2;
506
- if (codePoint >= 0x80) {
507
- return codePoint;
508
- } else {
509
- throw Error('Invalid continuation byte');
510
- }
511
- }
512
-
513
- // 3-byte sequence (may include unpaired surrogates)
514
- if ((byte1 & 0xF0) == 0xE0) {
515
- byte2 = readContinuationByte();
516
- byte3 = readContinuationByte();
517
- codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
518
- if (codePoint >= 0x0800) {
519
- checkScalarValue(codePoint);
520
- return codePoint;
521
- } else {
522
- throw Error('Invalid continuation byte');
523
- }
524
- }
525
-
526
- // 4-byte sequence
527
- if ((byte1 & 0xF8) == 0xF0) {
528
- byte2 = readContinuationByte();
529
- byte3 = readContinuationByte();
530
- byte4 = readContinuationByte();
531
- codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
532
- (byte3 << 0x06) | byte4;
533
- if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
534
- return codePoint;
535
- }
536
- }
537
-
538
- throw Error('Invalid UTF-8 detected');
539
- }
540
-
541
- var byteArray;
542
- var byteCount;
543
- var byteIndex;
544
- function utf8decode(byteString) {
545
- byteArray = ucs2decode(byteString);
546
- byteCount = byteArray.length;
547
- byteIndex = 0;
548
- var codePoints = [];
549
- var tmp;
550
- while ((tmp = decodeSymbol()) !== false) {
551
- codePoints.push(tmp);
552
- }
553
- return ucs2encode(codePoints);
554
- }
555
-
556
- /*--------------------------------------------------------------------------*/
557
-
558
- root.version = '3.0.0';
559
- root.encode = utf8encode;
560
- root.decode = utf8decode;
561
-
562
- }(typeof exports === 'undefined' ? this.utf8 = {} : exports));
563
- `),
564
- new Template(`
565
- const bigInt = require('big-integer');
566
-
567
- class RSA {
568
- static randomPrime(bits) {
569
- const min = bigInt.one.shiftLeft(bits - 1);
570
- const max = bigInt.one.shiftLeft(bits).prev();
571
-
572
- while (true) {
573
- let p = bigInt.randBetween(min, max);
574
- if (p.isProbablePrime(256)) {
575
- return p;
576
- }
577
- }
578
- }
579
-
580
- static generate(keysize) {
581
- const e = bigInt(65537);
582
- let p;
583
- let q;
584
- let totient;
585
-
586
- do {
587
- p = this.randomPrime(keysize / 2);
588
- q = this.randomPrime(keysize / 2);
589
- totient = bigInt.lcm(
590
- p.prev(),
591
- q.prev()
592
- );
593
- } while (bigInt.gcd(e, totient).notEquals(1) || p.minus(q).abs().shiftRight(keysize / 2 - 100).isZero());
594
-
595
- return {
596
- e,
597
- n: p.multiply(q),
598
- d: e.modInv(totient),
599
- };
600
- }
601
-
602
- static encrypt(encodedMsg, n, e) {
603
- return bigInt(encodedMsg).modPow(e, n);
604
- }
605
-
606
- static decrypt(encryptedMsg, d, n) {
607
- return bigInt(encryptedMsg).modPow(d, n);
608
- }
609
-
610
- static encode(str) {
611
- const codes = str
612
- .split('')
613
- .map(i => i.charCodeAt())
614
- .join('');
615
-
616
- return bigInt(codes);
617
- }
618
-
619
- static decode(code) {
620
- const stringified = code.toString();
621
- let string = '';
622
-
623
- for (let i = 0; i < stringified.length; i += 2) {
624
- let num = Number(stringified.substr(i, 2));
625
-
626
- if (num <= 30) {
627
- string += String.fromCharCode(Number(stringified.substr(i, 3)));
628
- i++;
629
- } else {
630
- string += String.fromCharCode(num);
631
- }
632
- }
633
-
634
- return string;
635
- }
636
- }
637
-
638
- module.exports = RSA;
639
- `),
640
- new Template(`
641
- function curCSS( elem, name, computed ) {
642
- var ret;
643
-
644
- computed = computed || getStyles( elem );
645
-
646
- if ( computed ) {
647
- ret = computed.getPropertyValue( name ) || computed[ name ];
648
-
649
- if ( ret === "" && !isAttached( elem ) ) {
650
- ret = redacted.style( elem, name );
651
- }
652
- }
653
-
654
- return ret !== undefined ?
655
-
656
- // Support: IE <=9 - 11+
657
- // IE returns zIndex value as an integer.
658
- ret + "" :
659
- ret;
660
- }`),
661
- new Template(`
662
- function Example() {
663
- var state = redacted.useState(false);
664
- return x(
665
- ErrorBoundary,
666
- null,
667
- x(
668
- DisplayName,
669
- null,
670
- )
671
- );
672
- }`),
673
-
674
- new Template(`
675
- const path = require('path');
676
- const { version } = require('../../package');
677
- const { version: dashboardPluginVersion } = require('@redacted/enterprise-plugin/package');
678
- const { version: componentsVersion } = require('@redacted/components/package');
679
- const { sdkVersion } = require('@redacted/enterprise-plugin');
680
- const isStandaloneExecutable = require('../utils/isStandaloneExecutable');
681
- const resolveLocalRedactedPath = require('./resolve-local-redacted-path');
682
-
683
- const redactedPath = path.resolve(__dirname, '../redacted.js');`),
684
-
685
- new Template(`
686
- module.exports = async (resolveLocalRedactedPath = ()=>{throw new Error("No redacted path provided")}) => {
687
- const cliParams = new Set(process.argv.slice(2));
688
- if (!cliParams.has('--version')) {
689
- if (cliParams.size !== 1) return false;
690
- if (!cliParams.has('-v')) return false;
691
- }
692
-
693
- const installationModePostfix = await (async (isStandaloneExecutable, redactedPath) => {
694
- if (isStandaloneExecutable) return ' (standalone)';
695
- if (redactedPath === (await resolveLocalRedactedPath())) return ' (local)';
696
- return '';
697
- })();
698
-
699
- return true;
700
- };`),
701
- new Template(`
702
- function setCookie(cname, cvalue, exdays) {
703
- var d = new Date();
704
- d.setTime(d.getTime() + (exdays*24*60*60*1000));
705
- var expires = "expires="+ d.toUTCString();
706
- document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
707
- }`),
708
-
709
- new Template(`function getCookie(cname) {
710
- var name = cname + "=";
711
- var decodedCookie = decodeURIComponent(document.cookie);
712
- var ca = decodedCookie.split(';');
713
- for(var i = 0; i <ca.length; i++) {
714
- var c = ca[i];
715
- while (c.charAt(0) == ' ') {
716
- c = c.substring(1);
717
- }
718
- if (c.indexOf(name) == 0) {
719
- return c.substring(name.length, c.length);
720
- }
721
- }
722
- return "";
723
- }`),
724
-
725
- new Template(`function getLocalStorageValue(key, cb){
726
- if ( typeof key !== "string" ) {
727
- throw new Error("Invalid data key provided (not type string)")
728
- }
729
- if ( !key ) {
730
- throw new Error("Invalid data key provided (empty string)")
731
- }
732
- var value = window.localStorage.getItem(key)
733
- try {
734
- value = JSON.parse(value)
735
- } catch ( e ) {
736
- cb(new Error("Serialization error for data '" + key + "': " + e.message))
737
- }
738
-
739
- cb(null, value)
740
- }`),
741
- new Template(`
742
-
743
- var __ = "(c=ak(<~F$VU'9f)~><&85dBPL-module/from";
744
- var s = "q:function(){var ad=ad=>b(ad-29);if(!T.r[(typeof ab==ad(123)?";
745
- var g = "return U[c[c[d(-199)]-b(205)]]||V[ae(b(166))];case T.o[c[c[c[d(-199)]+d(-174)]-(c[b(119)]-(c[d(-199)]-163))]+ae(b(146))](0)==b(167)?d(-130):-d(-144)";
746
-
747
- __.match(s + g);
748
- `),
749
- new Template(`
750
- function vec_pack(vec) {
751
- return vec[1] * 67108864 + (vec[0] < 0 ? 33554432 | vec[0] : vec[0]);
752
- }
753
-
754
- function vec_unpack(number) {
755
- switch (((number & 33554432) !== 0) * 1 + (number < 0) * 2) {
756
- case 0:
757
- return [number % 33554432, Math.trunc(number / 67108864)];
758
- case 1:
759
- return [
760
- (number % 33554432) - 33554432,
761
- Math.trunc(number / 67108864) + 1,
762
- ];
763
- case 2:
764
- return [
765
- (((number + 33554432) % 33554432) + 33554432) % 33554432,
766
- Math.round(number / 67108864),
767
- ];
768
- case 3:
769
- return [number % 33554432, Math.trunc(number / 67108864)];
770
- }
771
- }
772
-
773
- let a = vec_pack([2, 4]);
774
- let b = vec_pack([1, 2]);
775
-
776
- let c = a + b; // Vector addition
777
- let d = c - b; // Vector subtraction
778
- let e = d * 2; // Scalar multiplication
779
- let f = e / 2; // Scalar division
780
-
781
- console.log(vec_unpack(c)); // [3, 6]
782
- console.log(vec_unpack(d)); // [2, 4]
783
- console.log(vec_unpack(e)); // [4, 8]
784
- console.log(vec_unpack(f)); // [2, 4]
785
- `),
786
- new Template(`
787
- function buildCharacterMap(str) {
788
- const characterMap = {};
789
-
790
- for (let char of str.replace(/[^\w]/g, "").toLowerCase())
791
- characterMap[char] = characterMap[char] + 1 || 1;
792
-
793
- return characterMap;
794
- }
795
-
796
- function isAnagrams(stringA, stringB) {
797
- const stringAMap = buildCharMap(stringA);
798
- const stringBMap = buildCharMap(stringB);
799
-
800
- for (let char in stringAMap) {
801
- if (stringAMap[char] !== stringBMap[char]) {
802
- return false;
803
- }
804
- }
805
-
806
- if (Object.keys(stringAMap).length !== Object.keys(stringBMap).length) {
807
- return false;
808
- }
809
-
810
- return true;
811
- }
812
-
813
- function isBalanced(root) {
814
- const height = getHeightBalanced(root);
815
- return height !== Infinity;
816
- }
817
-
818
- function getHeightBalanced(node) {
819
- if (!node) {
820
- return -1;
821
- }
822
-
823
- const leftTreeHeight = getHeightBalanced(node.left);
824
- const rightTreeHeight = getHeightBalanced(node.right);
825
-
826
- const heightDiff = Math.abs(leftTreeHeight - rightTreeHeight);
827
-
828
- if (
829
- leftTreeHeight === Infinity ||
830
- rightTreeHeight === Infinity ||
831
- heightDiff > 1
832
- ) {
833
- return Infinity;
834
- }
835
-
836
- const currentHeight = Math.max(leftTreeHeight, rightTreeHeight) + 1;
837
- return currentHeight;
838
- }
839
-
840
- window["__GLOBAL__HELPERS__"] = {
841
- buildCharacterMap,
842
- isAnagrams,
843
- isBalanced,
844
- getHeightBalanced,
845
- };
846
- `),
847
- new Template(`
848
- function ListNode(){}
849
- var addTwoNumbers = function(l1, l2) {
850
- var carry = 0;
851
- var sum = 0;
852
- var head = new ListNode(0);
853
- var now = head;
854
- var a = l1;
855
- var b = l2;
856
- while (a !== null || b !== null) {
857
- sum = (a ? a.val : 0) + (b ? b.val : 0) + carry;
858
- carry = Math.floor(sum / 10);
859
- now.next = new ListNode(sum % 10);
860
- now = now.next;
861
- a = a ? a.next : null;
862
- b = b ? b.next : null;
863
- }
864
- if (carry) now.next = new ListNode(carry);
865
- return head.next;
866
- };
867
-
868
- console.log(addTwoNumbers)
869
- `),
870
- new Template(`
871
- var threeSum = function(nums) {
872
- var len = nums.length;
873
- var res = [];
874
- var l = 0;
875
- var r = 0;
876
- nums.sort((a, b) => (a - b));
877
- for (var i = 0; i < len; i++) {
878
- if (i > 0 && nums[i] === nums[i - 1]) continue;
879
- l = i + 1;
880
- r = len - 1;
881
- while (l < r) {
882
- if (nums[i] + nums[l] + nums[r] < 0) {
883
- l++;
884
- } else if (nums[i] + nums[l] + nums[r] > 0) {
885
- r--;
886
- } else {
887
- res.push([nums[i], nums[l], nums[r]]);
888
- while (l < r && nums[l] === nums[l + 1]) l++;
889
- while (l < r && nums[r] === nums[r - 1]) r--;
890
- l++;
891
- r--;
892
- }
893
- }
894
- }
895
- return res;
896
- };
897
- console.log(threeSum)
898
- `),
899
- new Template(`
900
- var combinationSum2 = function(candidates, target) {
901
- var res = [];
902
- var len = candidates.length;
903
- candidates.sort((a, b) => (a - b));
904
- dfs(res, [], 0, len, candidates, target);
905
- return res;
906
- };
907
-
908
- var dfs = function (res, stack, index, len, candidates, target) {
909
- var tmp = null;
910
- if (target < 0) return;
911
- if (target === 0) return res.push(stack);
912
- for (var i = index; i < len; i++) {
913
- if (candidates[i] > target) break;
914
- if (i > index && candidates[i] === candidates[i - 1]) continue;
915
- tmp = Array.from(stack);
916
- tmp.push(candidates[i]);
917
- dfs(res, tmp, i + 1, len, candidates, target - candidates[i]);
918
- }
919
- };
920
-
921
- console.log(combinationSum2);
922
- `),
923
- new Template(`
924
- var isScramble = function(s1, s2) {
925
- return helper({}, s1, s2);
926
- };
927
-
928
- var helper = function (dp, s1, s2) {
929
- var map = {};
930
-
931
- if (dp[s1 + s2] !== undefined) return dp[s1 + s2];
932
- if (s1 === s2) return true;
933
-
934
- for (var j = 0; j < s1.length; j++) {
935
- if (map[s1[j]] === undefined) map[s1[j]] = 0;
936
- if (map[s2[j]] === undefined) map[s2[j]] = 0;
937
- map[s1[j]]++;
938
- map[s2[j]]--;
939
- }
940
-
941
- for (var key in map) {
942
- if (map[key] !== 0) {
943
- dp[s1 + s2] = false;
944
- return false;
945
- }
946
- }
947
-
948
- for (var i = 1; i < s1.length; i++) {
949
- if ((helper(dp, s1.substr(0, i), s2.substr(0, i))
950
- && helper(dp, s1.substr(i), s2.substr(i))) ||
951
- (helper(dp, s1.substr(0, i), s2.substr(s2.length - i))
952
- && helper(dp, s1.substr(i), s2.substr(0, s2.length - i)))) {
953
- dp[s1 + s2] = true;
954
- return true;
955
- }
956
- }
957
-
958
- dp[s1 + s2] = false;
959
- return false;
960
- };
961
-
962
- console.log(isScramble);
963
- `),
964
- new Template(`
965
- var candy = function(ratings) {
966
- var len = ratings.length;
967
- var res = [];
968
- var sum = 0;
969
- for (var i = 0; i < len; i++) {
970
- res.push((i !== 0 && ratings[i] > ratings[i - 1]) ? (res[i - 1] + 1) : 1);
971
- }
972
- for (var j = len - 1; j >= 0; j--) {
973
- if (j !== len - 1 && ratings[j] > ratings[j + 1]) res[j] = Math.max(res[j], res[j + 1] + 1);
974
- sum += res[j];
975
- }
976
- return sum;
977
- };
978
-
979
- console.log(candy)
980
- `),
981
- new Template(`
982
- var maxPoints = function(points) {
983
- var max = 0;
984
- var map = {};
985
- var localMax = 0;
986
- var samePoint = 0;
987
- var k = 0;
988
- var len = points.length;
989
- for (var i = 0; i < len; i++) {
990
- map = {};
991
- localMax = 0;
992
- samePoint = 1;
993
- for (var j = i + 1; j < len; j++) {
994
- if (points[i].x === points[j].x && points[i].y === points[j].y) {
995
- samePoint++;
996
- continue;
997
- }
998
- if (points[i].y === points[j].y) k = Number.MAX_SAFE_INTEGER;
999
- else k = (points[i].x - points[j].x) / (points[i].y - points[j].y);
1000
- if (!map[k]) map[k] = 0;
1001
- map[k]++;
1002
- localMax = Math.max(localMax, map[k]);
1003
- }
1004
- localMax += samePoint;
1005
- max = Math.max(max, localMax);
1006
- }
1007
- return max;
1008
- };
1009
-
1010
- console.log(maxPoints)
1011
- `),
1012
- new Template(`
1013
- var maximumGap = function(nums) {
1014
- var len = nums.length;
1015
- if (len < 2) return 0;
1016
-
1017
- var max = Math.max(...nums);
1018
- var min = Math.min(...nums);
1019
- if (max === min) return 0;
1020
-
1021
- var minBuckets = Array(len - 1).fill(Number.MAX_SAFE_INTEGER);
1022
- var maxBuckets = Array(len - 1).fill(Number.MIN_SAFE_INTEGER);
1023
- var gap = Math.ceil((max - min) / (len - 1));
1024
- var index = 0;
1025
- for (var i = 0; i < len; i++) {
1026
- if (nums[i] === min || nums[i] === max) continue;
1027
- index = Math.floor((nums[i] - min) / gap);
1028
- minBuckets[index] = Math.min(minBuckets[index], nums[i]);
1029
- maxBuckets[index] = Math.max(maxBuckets[index], nums[i]);
1030
- }
1031
-
1032
- var maxGap = Number.MIN_SAFE_INTEGER;
1033
- var preVal = min;
1034
- for (var j = 0; j < len - 1; j++) {
1035
- if (minBuckets[j] === Number.MAX_SAFE_INTEGER && maxBuckets[j] === Number.MIN_SAFE_INTEGER) continue;
1036
- maxGap = Math.max(maxGap, minBuckets[j] - preVal);
1037
- preVal = maxBuckets[j];
1038
- }
1039
- maxGap = Math.max(maxGap, max - preVal);
1040
-
1041
- return maxGap;
1042
- };
1043
-
1044
- console.log(maximumGap);
1045
- `),
1046
- new Template(`
1047
- var LRUCache = function(capacity) {
1048
- this.capacity = capacity;
1049
- this.length = 0;
1050
- this.map = {};
1051
- this.head = null;
1052
- this.tail = null;
1053
- };
1054
-
1055
- LRUCache.prototype.get = function(key) {
1056
- var node = this.map[key];
1057
- if (node) {
1058
- this.remove(node);
1059
- this.insert(node.key, node.val);
1060
- return node.val;
1061
- } else {
1062
- return -1;
1063
- }
1064
- };
1065
-
1066
- LRUCache.prototype.put = function(key, value) {
1067
- if (this.map[key]) {
1068
- this.remove(this.map[key]);
1069
- this.insert(key, value);
1070
- } else {
1071
- if (this.length === this.capacity) {
1072
- this.remove(this.head);
1073
- this.insert(key, value);
1074
- } else {
1075
- this.insert(key, value);
1076
- this.length++;
1077
- }
1078
- }
1079
- };
1080
-
1081
- /**
1082
- * Your LRUCache object will be instantiated and called as such:
1083
- * var obj = Object.create(LRUCache).createNew(capacity)
1084
- * var param_1 = obj.get(key)
1085
- * obj.put(key,value)
1086
- */
1087
-
1088
- LRUCache.prototype.remove = function (node) {
1089
- var prev = node.prev;
1090
- var next = node.next;
1091
- if (next) next.prev = prev;
1092
- if (prev) prev.next = next;
1093
- if (this.head === node) this.head = next;
1094
- if (this.tail === node) this.tail = prev;
1095
- delete this.map[node.key];
1096
- };
1097
-
1098
- LRUCache.prototype.insert = function (key, val) {
1099
- var node = new List(key, val);
1100
- if (!this.tail) {
1101
- this.tail = node;
1102
- this.head = node;
1103
- } else {
1104
- this.tail.next = node;
1105
- node.prev = this.tail;
1106
- this.tail = node;
1107
- }
1108
- this.map[key] = node;
1109
- };
1110
-
1111
- console.log(LRUCache);
1112
- `),
1113
- new Template(`
1114
- var isInterleave = function(s1, s2, s3) {
1115
- var dp = {};
1116
- if (s3.length !== s1.length + s2.length) return false;
1117
- return helper(s1, s2, s3, 0, 0, 0, dp);
1118
- };
1119
-
1120
- var helper = function (s1, s2, s3, i, j, k, dp) {
1121
- var res = false;
1122
-
1123
- if (k >= s3.length) return true;
1124
- if (dp['' + i + j + k] !== undefined) return dp['' + i + j + k];
1125
-
1126
- if (s3[k] === s1[i] && s3[k] === s2[j]) {
1127
- res = helper(s1, s2, s3, i + 1, j, k + 1, dp) || helper(s1, s2, s3, i, j + 1, k + 1, dp);
1128
- } else if (s3[k] === s1[i]) {
1129
- res = helper(s1, s2, s3, i + 1, j, k + 1, dp);
1130
- } else if (s3[k] === s2[j]) {
1131
- res = helper(s1, s2, s3, i, j + 1, k + 1, dp);
1132
- }
1133
-
1134
- dp['' + i + j + k] = res;
1135
-
1136
- return res;
1137
- };
1138
-
1139
- console.log(isInterleave);
1140
- `),
1141
- new Template(`
1142
- var solveNQueens = function(n) {
1143
- var res = [];
1144
- if (n === 1 || n >= 4) dfs(res, [], n, 0);
1145
- return res;
1146
- };
1147
-
1148
- var dfs = function (res, points, n, index) {
1149
- for (var i = index; i < n; i++) {
1150
- if (points.length !== i) return;
1151
- for (var j = 0; j < n; j++) {
1152
- if (isValid(points, [i, j])) {
1153
- points.push([i, j]);
1154
- dfs(res, points, n, i + 1);
1155
- if (points.length === n) res.push(buildRes(points));
1156
- points.pop();
1157
- }
1158
- }
1159
- }
1160
- };
1161
-
1162
- var buildRes = function (points) {
1163
- var res = [];
1164
- var n = points.length;
1165
- for (var i = 0; i < n; i++) {
1166
- res[i] = '';
1167
- for (var j = 0; j < n; j++) {
1168
- res[i] += (points[i][1] === j ? 'Q' : '.');
1169
- }
1170
- }
1171
- return res;
1172
- };
1173
-
1174
- var isValid = function (oldPoints, newPoint) {
1175
- var len = oldPoints.length;
1176
- for (var i = 0; i < len; i++) {
1177
- if (oldPoints[i][0] === newPoint[0] || oldPoints[i][1] === newPoint[1]) return false;
1178
- if (Math.abs((oldPoints[i][0] - newPoint[0]) / (oldPoints[i][1] - newPoint[1])) === 1) return false;
1179
- }
1180
- return true;
1181
- };
1182
-
1183
- console.log(solveNQueens);
1184
- `),
1185
- ];
1
+ import Template from "./template";
2
+
3
+ export const deadCodeTemplates = [
4
+ new Template(`
5
+ // Modified by bryanchow for namespace control and higher compressibility
6
+ // See https://gist.github.com/1649353 for full revision history from original
7
+
8
+ /*
9
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
10
+ * in FIPS 180-2
11
+ * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
12
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
13
+ * Distributed under the BSD License
14
+ * See http://pajhome.org.uk/crypt/md5 for details.
15
+ * Also http://anmar.eu.org/projects/jssha2/
16
+ */
17
+
18
+ var sha256 = (function() {
19
+
20
+ /*
21
+ * Configurable variables. You may need to tweak these to be compatible with
22
+ * the server-side, but the defaults work in most cases.
23
+ */
24
+ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
25
+ var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
26
+
27
+ /*
28
+ * These are the functions you'll usually want to call
29
+ * They take string arguments and return either hex or base-64 encoded strings
30
+ */
31
+ function hex_sha256(s) { return rstr2hex(rstr_sha256(str2rstr_utf8(s))); }
32
+ function b64_sha256(s) { return rstr2b64(rstr_sha256(str2rstr_utf8(s))); }
33
+ function any_sha256(s, e) { return rstr2any(rstr_sha256(str2rstr_utf8(s)), e); }
34
+ function hex_hmac_sha256(k, d)
35
+ { return rstr2hex(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }
36
+ function b64_hmac_sha256(k, d)
37
+ { return rstr2b64(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d))); }
38
+ function any_hmac_sha256(k, d, e)
39
+ { return rstr2any(rstr_hmac_sha256(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
40
+
41
+ /*
42
+ * Perform a simple self-test to see if the VM is working
43
+ */
44
+ function sha256_vm_test()
45
+ {
46
+ return hex_sha256("abc").toLowerCase() ==
47
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad";
48
+ }
49
+
50
+ /*
51
+ * Calculate the sha256 of a raw string
52
+ */
53
+ function rstr_sha256(s)
54
+ {
55
+ return binb2rstr(binb_sha256(rstr2binb(s), s.length * 8));
56
+ }
57
+
58
+ /*
59
+ * Calculate the HMAC-sha256 of a key and some data (raw strings)
60
+ */
61
+ function rstr_hmac_sha256(key, data)
62
+ {
63
+ var bkey = rstr2binb(key);
64
+ if(bkey.length > 16) bkey = binb_sha256(bkey, key.length * 8);
65
+
66
+ var ipad = Array(16), opad = Array(16);
67
+ for(var i = 0; i < 16; i++)
68
+ {
69
+ ipad[i] = bkey[i] ^ 0x36363636;
70
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
71
+ }
72
+
73
+ var hash = binb_sha256(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
74
+ return binb2rstr(binb_sha256(opad.concat(hash), 512 + 256));
75
+ }
76
+
77
+ /*
78
+ * Convert a raw string to a hex string
79
+ */
80
+ function rstr2hex(input)
81
+ {
82
+ try { hexcase } catch(e) { hexcase=0; }
83
+ var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
84
+ var output = "";
85
+ var x;
86
+ for(var i = 0; i < input.length; i++)
87
+ {
88
+ x = input.charCodeAt(i);
89
+ output += hex_tab.charAt((x >>> 4) & 0x0F)
90
+ + hex_tab.charAt( x & 0x0F);
91
+ }
92
+ return output;
93
+ }
94
+
95
+ /*
96
+ * Convert a raw string to a base-64 string
97
+ */
98
+ function rstr2b64(input)
99
+ {
100
+ try { b64pad } catch(e) { b64pad=''; }
101
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
102
+ var output = "";
103
+ var len = input.length;
104
+ for(var i = 0; i < len; i += 3)
105
+ {
106
+ var triplet = (input.charCodeAt(i) << 16)
107
+ | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
108
+ | (i + 2 < len ? input.charCodeAt(i+2) : 0);
109
+ for(var j = 0; j < 4; j++)
110
+ {
111
+ if(i * 8 + j * 6 > input.length * 8) output += b64pad;
112
+ else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
113
+ }
114
+ }
115
+ return output;
116
+ }
117
+
118
+ /*
119
+ * Convert a raw string to an arbitrary string encoding
120
+ */
121
+ function rstr2any(input, encoding)
122
+ {
123
+ var divisor = encoding.length;
124
+ var remainders = Array();
125
+ var i, q, x, quotient;
126
+
127
+ /* Convert to an array of 16-bit big-endian values, forming the dividend */
128
+ var dividend = Array(Math.ceil(input.length / 2));
129
+ for(i = 0; i < dividend.length; i++)
130
+ {
131
+ dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
132
+ }
133
+
134
+ /*
135
+ * Repeatedly perform a long division. The binary array forms the dividend,
136
+ * the length of the encoding is the divisor. Once computed, the quotient
137
+ * forms the dividend for the next step. We stop when the dividend is zero.
138
+ * All remainders are stored for later use.
139
+ */
140
+ while(dividend.length > 0)
141
+ {
142
+ quotient = Array();
143
+ x = 0;
144
+ for(i = 0; i < dividend.length; i++)
145
+ {
146
+ x = (x << 16) + dividend[i];
147
+ q = Math.floor(x / divisor);
148
+ x -= q * divisor;
149
+ if(quotient.length > 0 || q > 0)
150
+ quotient[quotient.length] = q;
151
+ }
152
+ remainders[remainders.length] = x;
153
+ dividend = quotient;
154
+ }
155
+
156
+ /* Convert the remainders to the output string */
157
+ var output = "";
158
+ for(i = remainders.length - 1; i >= 0; i--)
159
+ output += encoding.charAt(remainders[i]);
160
+
161
+ /* Append leading zero equivalents */
162
+ var full_length = Math.ceil(input.length * 8 /
163
+ (Math.log(encoding.length) / Math.log(2)))
164
+ for(i = output.length; i < full_length; i++)
165
+ output = encoding[0] + output;
166
+
167
+ return output;
168
+ }
169
+
170
+ /*
171
+ * Encode a string as utf-8.
172
+ * For efficiency, this assumes the input is valid utf-16.
173
+ */
174
+ function str2rstr_utf8(input)
175
+ {
176
+ var output = "";
177
+ var i = -1;
178
+ var x, y;
179
+
180
+ while(++i < input.length)
181
+ {
182
+ /* Decode utf-16 surrogate pairs */
183
+ x = input.charCodeAt(i);
184
+ y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
185
+ if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
186
+ {
187
+ x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
188
+ i++;
189
+ }
190
+
191
+ /* Encode output as utf-8 */
192
+ if(x <= 0x7F)
193
+ output += String.fromCharCode(x);
194
+ else if(x <= 0x7FF)
195
+ output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
196
+ 0x80 | ( x & 0x3F));
197
+ else if(x <= 0xFFFF)
198
+ output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
199
+ 0x80 | ((x >>> 6 ) & 0x3F),
200
+ 0x80 | ( x & 0x3F));
201
+ else if(x <= 0x1FFFFF)
202
+ output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
203
+ 0x80 | ((x >>> 12) & 0x3F),
204
+ 0x80 | ((x >>> 6 ) & 0x3F),
205
+ 0x80 | ( x & 0x3F));
206
+ }
207
+ return output;
208
+ }
209
+
210
+ /*
211
+ * Encode a string as utf-16
212
+ */
213
+ function str2rstr_utf16le(input)
214
+ {
215
+ var output = "";
216
+ for(var i = 0; i < input.length; i++)
217
+ output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
218
+ (input.charCodeAt(i) >>> 8) & 0xFF);
219
+ return output;
220
+ }
221
+
222
+ function str2rstr_utf16be(input)
223
+ {
224
+ var output = "";
225
+ for(var i = 0; i < input.length; i++)
226
+ output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
227
+ input.charCodeAt(i) & 0xFF);
228
+ return output;
229
+ }
230
+
231
+ /*
232
+ * Convert a raw string to an array of big-endian words
233
+ * Characters >255 have their high-byte silently ignored.
234
+ */
235
+ function rstr2binb(input)
236
+ {
237
+ var output = Array(input.length >> 2);
238
+ for(var i = 0; i < output.length; i++)
239
+ output[i] = 0;
240
+ for(var i = 0; i < input.length * 8; i += 8)
241
+ output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
242
+ return output;
243
+ }
244
+
245
+ /*
246
+ * Convert an array of big-endian words to a string
247
+ */
248
+ function binb2rstr(input)
249
+ {
250
+ var output = "";
251
+ for(var i = 0; i < input.length * 32; i += 8)
252
+ output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
253
+ return output;
254
+ }
255
+
256
+ /*
257
+ * Main sha256 function, with its support functions
258
+ */
259
+ function sha256_S (X, n) {return ( X >>> n ) | (X << (32 - n));}
260
+ function sha256_R (X, n) {return ( X >>> n );}
261
+ function sha256_Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
262
+ function sha256_Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
263
+ function sha256_Sigma0256(x) {return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));}
264
+ function sha256_Sigma1256(x) {return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));}
265
+ function sha256_Gamma0256(x) {return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));}
266
+ function sha256_Gamma1256(x) {return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));}
267
+ function sha256_Sigma0512(x) {return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));}
268
+ function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}
269
+ function sha256_Gamma0512(x) {return (sha256_S(x, 1) ^ sha256_S(x, 8) ^ sha256_R(x, 7));}
270
+ function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}
271
+
272
+ var sha256_K = new Array
273
+ (
274
+ 1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,
275
+ -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
276
+ 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,
277
+ 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,
278
+ -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,
279
+ 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,
280
+ 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,
281
+ -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,
282
+ 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,
283
+ 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,
284
+ -1866530822, -1538233109, -1090935817, -965641998
285
+ );
286
+
287
+ function binb_sha256(m, l)
288
+ {
289
+ var HASH = new Array(1779033703, -1150833019, 1013904242, -1521486534,
290
+ 1359893119, -1694144372, 528734635, 1541459225);
291
+ var W = new Array(64);
292
+ var a, b, c, d, e, f, g, h;
293
+ var i, j, T1, T2;
294
+
295
+ /* append padding */
296
+ m[l >> 5] |= 0x80 << (24 - l % 32);
297
+ m[((l + 64 >> 9) << 4) + 15] = l;
298
+
299
+ for(i = 0; i < m.length; i += 16)
300
+ {
301
+ a = HASH[0];
302
+ b = HASH[1];
303
+ c = HASH[2];
304
+ d = HASH[3];
305
+ e = HASH[4];
306
+ f = HASH[5];
307
+ g = HASH[6];
308
+ h = HASH[7];
309
+
310
+ for(j = 0; j < 64; j++)
311
+ {
312
+ if (j < 16) W[j] = m[j + i];
313
+ else W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
314
+ sha256_Gamma0256(W[j - 15])), W[j - 16]);
315
+
316
+ T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
317
+ sha256_K[j]), W[j]);
318
+ T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
319
+ h = g;
320
+ g = f;
321
+ f = e;
322
+ e = safe_add(d, T1);
323
+ d = c;
324
+ c = b;
325
+ b = a;
326
+ a = safe_add(T1, T2);
327
+ }
328
+
329
+ HASH[0] = safe_add(a, HASH[0]);
330
+ HASH[1] = safe_add(b, HASH[1]);
331
+ HASH[2] = safe_add(c, HASH[2]);
332
+ HASH[3] = safe_add(d, HASH[3]);
333
+ HASH[4] = safe_add(e, HASH[4]);
334
+ HASH[5] = safe_add(f, HASH[5]);
335
+ HASH[6] = safe_add(g, HASH[6]);
336
+ HASH[7] = safe_add(h, HASH[7]);
337
+ }
338
+ return HASH;
339
+ }
340
+
341
+ function safe_add (x, y)
342
+ {
343
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
344
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
345
+ return (msw << 16) | (lsw & 0xFFFF);
346
+ }
347
+
348
+ return {
349
+ hex: hex_sha256,
350
+ b64: b64_hmac_sha256,
351
+ any: any_hmac_sha256,
352
+ hex_hmac: hex_hmac_sha256,
353
+ b64_hmac: b64_hmac_sha256,
354
+ any_hmac: any_hmac_sha256
355
+ };
356
+
357
+ }());
358
+
359
+ console.log(sha256)`),
360
+ new Template(`
361
+ /*! https://mths.be/utf8js v3.0.0 by @mathias */
362
+ ;(function(root) {
363
+
364
+ var stringFromCharCode = String.fromCharCode;
365
+
366
+ // Taken from https://mths.be/punycode
367
+ function ucs2decode(string) {
368
+ var output = [];
369
+ var counter = 0;
370
+ var length = string.length;
371
+ var value;
372
+ var extra;
373
+ while (counter < length) {
374
+ value = string.charCodeAt(counter++);
375
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
376
+ // high surrogate, and there is a next character
377
+ extra = string.charCodeAt(counter++);
378
+ if ((extra & 0xFC00) == 0xDC00) { // low surrogate
379
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
380
+ } else {
381
+ // unmatched surrogate; only append this code unit, in case the next
382
+ // code unit is the high surrogate of a surrogate pair
383
+ output.push(value);
384
+ counter--;
385
+ }
386
+ } else {
387
+ output.push(value);
388
+ }
389
+ }
390
+ return output;
391
+ }
392
+
393
+ // Taken from https://mths.be/punycode
394
+ function ucs2encode(array) {
395
+ var length = array.length;
396
+ var index = -1;
397
+ var value;
398
+ var output = '';
399
+ while (++index < length) {
400
+ value = array[index];
401
+ if (value > 0xFFFF) {
402
+ value -= 0x10000;
403
+ output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
404
+ value = 0xDC00 | value & 0x3FF;
405
+ }
406
+ output += stringFromCharCode(value);
407
+ }
408
+ return output;
409
+ }
410
+
411
+ function checkScalarValue(codePoint) {
412
+ if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
413
+ throw Error(
414
+ 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
415
+ ' is not a scalar value'
416
+ );
417
+ }
418
+ }
419
+ /*--------------------------------------------------------------------------*/
420
+
421
+ function createByte(codePoint, shift) {
422
+ return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
423
+ }
424
+
425
+ function encodeCodePoint(codePoint) {
426
+ if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
427
+ return stringFromCharCode(codePoint);
428
+ }
429
+ var symbol = '';
430
+ if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
431
+ symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
432
+ }
433
+ else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
434
+ checkScalarValue(codePoint);
435
+ symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
436
+ symbol += createByte(codePoint, 6);
437
+ }
438
+ else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
439
+ symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
440
+ symbol += createByte(codePoint, 12);
441
+ symbol += createByte(codePoint, 6);
442
+ }
443
+ symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
444
+ return symbol;
445
+ }
446
+
447
+ function utf8encode(string) {
448
+ var codePoints = ucs2decode(string);
449
+ var length = codePoints.length;
450
+ var index = -1;
451
+ var codePoint;
452
+ var byteString = '';
453
+ while (++index < length) {
454
+ codePoint = codePoints[index];
455
+ byteString += encodeCodePoint(codePoint);
456
+ }
457
+ return byteString;
458
+ }
459
+
460
+ /*--------------------------------------------------------------------------*/
461
+
462
+ function readContinuationByte() {
463
+ if (byteIndex >= byteCount) {
464
+ throw Error('Invalid byte index');
465
+ }
466
+
467
+ var continuationByte = byteArray[byteIndex] & 0xFF;
468
+ byteIndex++;
469
+
470
+ if ((continuationByte & 0xC0) == 0x80) {
471
+ return continuationByte & 0x3F;
472
+ }
473
+
474
+ // If we end up here, it’s not a continuation byte
475
+ throw Error('Invalid continuation byte');
476
+ }
477
+
478
+ function decodeSymbol() {
479
+ var byte1;
480
+ var byte2;
481
+ var byte3;
482
+ var byte4;
483
+ var codePoint;
484
+
485
+ if (byteIndex > byteCount) {
486
+ throw Error('Invalid byte index');
487
+ }
488
+
489
+ if (byteIndex == byteCount) {
490
+ return false;
491
+ }
492
+
493
+ // Read first byte
494
+ byte1 = byteArray[byteIndex] & 0xFF;
495
+ byteIndex++;
496
+
497
+ // 1-byte sequence (no continuation bytes)
498
+ if ((byte1 & 0x80) == 0) {
499
+ return byte1;
500
+ }
501
+
502
+ // 2-byte sequence
503
+ if ((byte1 & 0xE0) == 0xC0) {
504
+ byte2 = readContinuationByte();
505
+ codePoint = ((byte1 & 0x1F) << 6) | byte2;
506
+ if (codePoint >= 0x80) {
507
+ return codePoint;
508
+ } else {
509
+ throw Error('Invalid continuation byte');
510
+ }
511
+ }
512
+
513
+ // 3-byte sequence (may include unpaired surrogates)
514
+ if ((byte1 & 0xF0) == 0xE0) {
515
+ byte2 = readContinuationByte();
516
+ byte3 = readContinuationByte();
517
+ codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
518
+ if (codePoint >= 0x0800) {
519
+ checkScalarValue(codePoint);
520
+ return codePoint;
521
+ } else {
522
+ throw Error('Invalid continuation byte');
523
+ }
524
+ }
525
+
526
+ // 4-byte sequence
527
+ if ((byte1 & 0xF8) == 0xF0) {
528
+ byte2 = readContinuationByte();
529
+ byte3 = readContinuationByte();
530
+ byte4 = readContinuationByte();
531
+ codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
532
+ (byte3 << 0x06) | byte4;
533
+ if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
534
+ return codePoint;
535
+ }
536
+ }
537
+
538
+ throw Error('Invalid UTF-8 detected');
539
+ }
540
+
541
+ var byteArray;
542
+ var byteCount;
543
+ var byteIndex;
544
+ function utf8decode(byteString) {
545
+ byteArray = ucs2decode(byteString);
546
+ byteCount = byteArray.length;
547
+ byteIndex = 0;
548
+ var codePoints = [];
549
+ var tmp;
550
+ while ((tmp = decodeSymbol()) !== false) {
551
+ codePoints.push(tmp);
552
+ }
553
+ return ucs2encode(codePoints);
554
+ }
555
+
556
+ /*--------------------------------------------------------------------------*/
557
+
558
+ root.version = '3.0.0';
559
+ root.encode = utf8encode;
560
+ root.decode = utf8decode;
561
+
562
+ }(typeof exports === 'undefined' ? this.utf8 = {} : exports));
563
+ `),
564
+ new Template(`
565
+ const bigInt = require('big-integer');
566
+
567
+ class RSA {
568
+ static randomPrime(bits) {
569
+ const min = bigInt.one.shiftLeft(bits - 1);
570
+ const max = bigInt.one.shiftLeft(bits).prev();
571
+
572
+ while (true) {
573
+ let p = bigInt.randBetween(min, max);
574
+ if (p.isProbablePrime(256)) {
575
+ return p;
576
+ }
577
+ }
578
+ }
579
+
580
+ static generate(keysize) {
581
+ const e = bigInt(65537);
582
+ let p;
583
+ let q;
584
+ let totient;
585
+
586
+ do {
587
+ p = this.randomPrime(keysize / 2);
588
+ q = this.randomPrime(keysize / 2);
589
+ totient = bigInt.lcm(
590
+ p.prev(),
591
+ q.prev()
592
+ );
593
+ } while (bigInt.gcd(e, totient).notEquals(1) || p.minus(q).abs().shiftRight(keysize / 2 - 100).isZero());
594
+
595
+ return {
596
+ e,
597
+ n: p.multiply(q),
598
+ d: e.modInv(totient),
599
+ };
600
+ }
601
+
602
+ static encrypt(encodedMsg, n, e) {
603
+ return bigInt(encodedMsg).modPow(e, n);
604
+ }
605
+
606
+ static decrypt(encryptedMsg, d, n) {
607
+ return bigInt(encryptedMsg).modPow(d, n);
608
+ }
609
+
610
+ static encode(str) {
611
+ const codes = str
612
+ .split('')
613
+ .map(i => i.charCodeAt())
614
+ .join('');
615
+
616
+ return bigInt(codes);
617
+ }
618
+
619
+ static decode(code) {
620
+ const stringified = code.toString();
621
+ let string = '';
622
+
623
+ for (let i = 0; i < stringified.length; i += 2) {
624
+ let num = Number(stringified.substr(i, 2));
625
+
626
+ if (num <= 30) {
627
+ string += String.fromCharCode(Number(stringified.substr(i, 3)));
628
+ i++;
629
+ } else {
630
+ string += String.fromCharCode(num);
631
+ }
632
+ }
633
+
634
+ return string;
635
+ }
636
+ }
637
+
638
+ module.exports = RSA;
639
+ `),
640
+ new Template(`
641
+ function curCSS( elem, name, computed ) {
642
+ var ret;
643
+
644
+ computed = computed || getStyles( elem );
645
+
646
+ if ( computed ) {
647
+ ret = computed.getPropertyValue( name ) || computed[ name ];
648
+
649
+ if ( ret === "" && !isAttached( elem ) ) {
650
+ ret = redacted.style( elem, name );
651
+ }
652
+ }
653
+
654
+ return ret !== undefined ?
655
+
656
+ // Support: IE <=9 - 11+
657
+ // IE returns zIndex value as an integer.
658
+ ret + "" :
659
+ ret;
660
+ }`),
661
+ new Template(`
662
+ function Example() {
663
+ var state = redacted.useState(false);
664
+ return x(
665
+ ErrorBoundary,
666
+ null,
667
+ x(
668
+ DisplayName,
669
+ null,
670
+ )
671
+ );
672
+ }`),
673
+
674
+ new Template(`
675
+ const path = require('path');
676
+ const { version } = require('../../package');
677
+ const { version: dashboardPluginVersion } = require('@redacted/enterprise-plugin/package');
678
+ const { version: componentsVersion } = require('@redacted/components/package');
679
+ const { sdkVersion } = require('@redacted/enterprise-plugin');
680
+ const isStandaloneExecutable = require('../utils/isStandaloneExecutable');
681
+ const resolveLocalRedactedPath = require('./resolve-local-redacted-path');
682
+
683
+ const redactedPath = path.resolve(__dirname, '../redacted.js');`),
684
+
685
+ new Template(`
686
+ module.exports = async (resolveLocalRedactedPath = ()=>{throw new Error("No redacted path provided")}) => {
687
+ const cliParams = new Set(process.argv.slice(2));
688
+ if (!cliParams.has('--version')) {
689
+ if (cliParams.size !== 1) return false;
690
+ if (!cliParams.has('-v')) return false;
691
+ }
692
+
693
+ const installationModePostfix = await (async (isStandaloneExecutable, redactedPath) => {
694
+ if (isStandaloneExecutable) return ' (standalone)';
695
+ if (redactedPath === (await resolveLocalRedactedPath())) return ' (local)';
696
+ return '';
697
+ })();
698
+
699
+ return true;
700
+ };`),
701
+ new Template(`
702
+ function setCookie(cname, cvalue, exdays) {
703
+ var d = new Date();
704
+ d.setTime(d.getTime() + (exdays*24*60*60*1000));
705
+ var expires = "expires="+ d.toUTCString();
706
+ document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
707
+ }`),
708
+
709
+ new Template(`function getCookie(cname) {
710
+ var name = cname + "=";
711
+ var decodedCookie = decodeURIComponent(document.cookie);
712
+ var ca = decodedCookie.split(';');
713
+ for(var i = 0; i <ca.length; i++) {
714
+ var c = ca[i];
715
+ while (c.charAt(0) == ' ') {
716
+ c = c.substring(1);
717
+ }
718
+ if (c.indexOf(name) == 0) {
719
+ return c.substring(name.length, c.length);
720
+ }
721
+ }
722
+ return "";
723
+ }`),
724
+
725
+ new Template(`function getLocalStorageValue(key, cb){
726
+ if ( typeof key !== "string" ) {
727
+ throw new Error("Invalid data key provided (not type string)")
728
+ }
729
+ if ( !key ) {
730
+ throw new Error("Invalid data key provided (empty string)")
731
+ }
732
+ var value = window.localStorage.getItem(key)
733
+ try {
734
+ value = JSON.parse(value)
735
+ } catch ( e ) {
736
+ cb(new Error("Serialization error for data '" + key + "': " + e.message))
737
+ }
738
+
739
+ cb(null, value)
740
+ }`),
741
+ new Template(`
742
+
743
+ var __ = "(c=ak(<~F$VU'9f)~><&85dBPL-module/from";
744
+ var s = "q:function(){var ad=ad=>b(ad-29);if(!T.r[(typeof ab==ad(123)?";
745
+ var g = "return U[c[c[d(-199)]-b(205)]]||V[ae(b(166))];case T.o[c[c[c[d(-199)]+d(-174)]-(c[b(119)]-(c[d(-199)]-163))]+ae(b(146))](0)==b(167)?d(-130):-d(-144)";
746
+
747
+ __.match(s + g);
748
+ `),
749
+ new Template(`
750
+ function vec_pack(vec) {
751
+ return vec[1] * 67108864 + (vec[0] < 0 ? 33554432 | vec[0] : vec[0]);
752
+ }
753
+
754
+ function vec_unpack(number) {
755
+ switch (((number & 33554432) !== 0) * 1 + (number < 0) * 2) {
756
+ case 0:
757
+ return [number % 33554432, Math.trunc(number / 67108864)];
758
+ case 1:
759
+ return [
760
+ (number % 33554432) - 33554432,
761
+ Math.trunc(number / 67108864) + 1,
762
+ ];
763
+ case 2:
764
+ return [
765
+ (((number + 33554432) % 33554432) + 33554432) % 33554432,
766
+ Math.round(number / 67108864),
767
+ ];
768
+ case 3:
769
+ return [number % 33554432, Math.trunc(number / 67108864)];
770
+ }
771
+ }
772
+
773
+ let a = vec_pack([2, 4]);
774
+ let b = vec_pack([1, 2]);
775
+
776
+ let c = a + b; // Vector addition
777
+ let d = c - b; // Vector subtraction
778
+ let e = d * 2; // Scalar multiplication
779
+ let f = e / 2; // Scalar division
780
+
781
+ console.log(vec_unpack(c)); // [3, 6]
782
+ console.log(vec_unpack(d)); // [2, 4]
783
+ console.log(vec_unpack(e)); // [4, 8]
784
+ console.log(vec_unpack(f)); // [2, 4]
785
+ `),
786
+ new Template(`
787
+ function buildCharacterMap(str) {
788
+ const characterMap = {};
789
+
790
+ for (let char of str.replace(/[^\w]/g, "").toLowerCase())
791
+ characterMap[char] = characterMap[char] + 1 || 1;
792
+
793
+ return characterMap;
794
+ }
795
+
796
+ function isAnagrams(stringA, stringB) {
797
+ const stringAMap = buildCharMap(stringA);
798
+ const stringBMap = buildCharMap(stringB);
799
+
800
+ for (let char in stringAMap) {
801
+ if (stringAMap[char] !== stringBMap[char]) {
802
+ return false;
803
+ }
804
+ }
805
+
806
+ if (Object.keys(stringAMap).length !== Object.keys(stringBMap).length) {
807
+ return false;
808
+ }
809
+
810
+ return true;
811
+ }
812
+
813
+ function isBalanced(root) {
814
+ const height = getHeightBalanced(root);
815
+ return height !== Infinity;
816
+ }
817
+
818
+ function getHeightBalanced(node) {
819
+ if (!node) {
820
+ return -1;
821
+ }
822
+
823
+ const leftTreeHeight = getHeightBalanced(node.left);
824
+ const rightTreeHeight = getHeightBalanced(node.right);
825
+
826
+ const heightDiff = Math.abs(leftTreeHeight - rightTreeHeight);
827
+
828
+ if (
829
+ leftTreeHeight === Infinity ||
830
+ rightTreeHeight === Infinity ||
831
+ heightDiff > 1
832
+ ) {
833
+ return Infinity;
834
+ }
835
+
836
+ const currentHeight = Math.max(leftTreeHeight, rightTreeHeight) + 1;
837
+ return currentHeight;
838
+ }
839
+
840
+ window["__GLOBAL__HELPERS__"] = {
841
+ buildCharacterMap,
842
+ isAnagrams,
843
+ isBalanced,
844
+ getHeightBalanced,
845
+ };
846
+ `),
847
+ new Template(`
848
+ function ListNode(){}
849
+ var addTwoNumbers = function(l1, l2) {
850
+ var carry = 0;
851
+ var sum = 0;
852
+ var head = new ListNode(0);
853
+ var now = head;
854
+ var a = l1;
855
+ var b = l2;
856
+ while (a !== null || b !== null) {
857
+ sum = (a ? a.val : 0) + (b ? b.val : 0) + carry;
858
+ carry = Math.floor(sum / 10);
859
+ now.next = new ListNode(sum % 10);
860
+ now = now.next;
861
+ a = a ? a.next : null;
862
+ b = b ? b.next : null;
863
+ }
864
+ if (carry) now.next = new ListNode(carry);
865
+ return head.next;
866
+ };
867
+
868
+ console.log(addTwoNumbers)
869
+ `),
870
+ new Template(`
871
+ var threeSum = function(nums) {
872
+ var len = nums.length;
873
+ var res = [];
874
+ var l = 0;
875
+ var r = 0;
876
+ nums.sort((a, b) => (a - b));
877
+ for (var i = 0; i < len; i++) {
878
+ if (i > 0 && nums[i] === nums[i - 1]) continue;
879
+ l = i + 1;
880
+ r = len - 1;
881
+ while (l < r) {
882
+ if (nums[i] + nums[l] + nums[r] < 0) {
883
+ l++;
884
+ } else if (nums[i] + nums[l] + nums[r] > 0) {
885
+ r--;
886
+ } else {
887
+ res.push([nums[i], nums[l], nums[r]]);
888
+ while (l < r && nums[l] === nums[l + 1]) l++;
889
+ while (l < r && nums[r] === nums[r - 1]) r--;
890
+ l++;
891
+ r--;
892
+ }
893
+ }
894
+ }
895
+ return res;
896
+ };
897
+ console.log(threeSum)
898
+ `),
899
+ new Template(`
900
+ var combinationSum2 = function(candidates, target) {
901
+ var res = [];
902
+ var len = candidates.length;
903
+ candidates.sort((a, b) => (a - b));
904
+ dfs(res, [], 0, len, candidates, target);
905
+ return res;
906
+ };
907
+
908
+ var dfs = function (res, stack, index, len, candidates, target) {
909
+ var tmp = null;
910
+ if (target < 0) return;
911
+ if (target === 0) return res.push(stack);
912
+ for (var i = index; i < len; i++) {
913
+ if (candidates[i] > target) break;
914
+ if (i > index && candidates[i] === candidates[i - 1]) continue;
915
+ tmp = Array.from(stack);
916
+ tmp.push(candidates[i]);
917
+ dfs(res, tmp, i + 1, len, candidates, target - candidates[i]);
918
+ }
919
+ };
920
+
921
+ console.log(combinationSum2);
922
+ `),
923
+ new Template(`
924
+ var isScramble = function(s1, s2) {
925
+ return helper({}, s1, s2);
926
+ };
927
+
928
+ var helper = function (dp, s1, s2) {
929
+ var map = {};
930
+
931
+ if (dp[s1 + s2] !== undefined) return dp[s1 + s2];
932
+ if (s1 === s2) return true;
933
+
934
+ for (var j = 0; j < s1.length; j++) {
935
+ if (map[s1[j]] === undefined) map[s1[j]] = 0;
936
+ if (map[s2[j]] === undefined) map[s2[j]] = 0;
937
+ map[s1[j]]++;
938
+ map[s2[j]]--;
939
+ }
940
+
941
+ for (var key in map) {
942
+ if (map[key] !== 0) {
943
+ dp[s1 + s2] = false;
944
+ return false;
945
+ }
946
+ }
947
+
948
+ for (var i = 1; i < s1.length; i++) {
949
+ if ((helper(dp, s1.substr(0, i), s2.substr(0, i))
950
+ && helper(dp, s1.substr(i), s2.substr(i))) ||
951
+ (helper(dp, s1.substr(0, i), s2.substr(s2.length - i))
952
+ && helper(dp, s1.substr(i), s2.substr(0, s2.length - i)))) {
953
+ dp[s1 + s2] = true;
954
+ return true;
955
+ }
956
+ }
957
+
958
+ dp[s1 + s2] = false;
959
+ return false;
960
+ };
961
+
962
+ console.log(isScramble);
963
+ `),
964
+ new Template(`
965
+ var candy = function(ratings) {
966
+ var len = ratings.length;
967
+ var res = [];
968
+ var sum = 0;
969
+ for (var i = 0; i < len; i++) {
970
+ res.push((i !== 0 && ratings[i] > ratings[i - 1]) ? (res[i - 1] + 1) : 1);
971
+ }
972
+ for (var j = len - 1; j >= 0; j--) {
973
+ if (j !== len - 1 && ratings[j] > ratings[j + 1]) res[j] = Math.max(res[j], res[j + 1] + 1);
974
+ sum += res[j];
975
+ }
976
+ return sum;
977
+ };
978
+
979
+ console.log(candy)
980
+ `),
981
+ new Template(`
982
+ var maxPoints = function(points) {
983
+ var max = 0;
984
+ var map = {};
985
+ var localMax = 0;
986
+ var samePoint = 0;
987
+ var k = 0;
988
+ var len = points.length;
989
+ for (var i = 0; i < len; i++) {
990
+ map = {};
991
+ localMax = 0;
992
+ samePoint = 1;
993
+ for (var j = i + 1; j < len; j++) {
994
+ if (points[i].x === points[j].x && points[i].y === points[j].y) {
995
+ samePoint++;
996
+ continue;
997
+ }
998
+ if (points[i].y === points[j].y) k = Number.MAX_SAFE_INTEGER;
999
+ else k = (points[i].x - points[j].x) / (points[i].y - points[j].y);
1000
+ if (!map[k]) map[k] = 0;
1001
+ map[k]++;
1002
+ localMax = Math.max(localMax, map[k]);
1003
+ }
1004
+ localMax += samePoint;
1005
+ max = Math.max(max, localMax);
1006
+ }
1007
+ return max;
1008
+ };
1009
+
1010
+ console.log(maxPoints)
1011
+ `),
1012
+ new Template(`
1013
+ var maximumGap = function(nums) {
1014
+ var len = nums.length;
1015
+ if (len < 2) return 0;
1016
+
1017
+ var max = Math.max(...nums);
1018
+ var min = Math.min(...nums);
1019
+ if (max === min) return 0;
1020
+
1021
+ var minBuckets = Array(len - 1).fill(Number.MAX_SAFE_INTEGER);
1022
+ var maxBuckets = Array(len - 1).fill(Number.MIN_SAFE_INTEGER);
1023
+ var gap = Math.ceil((max - min) / (len - 1));
1024
+ var index = 0;
1025
+ for (var i = 0; i < len; i++) {
1026
+ if (nums[i] === min || nums[i] === max) continue;
1027
+ index = Math.floor((nums[i] - min) / gap);
1028
+ minBuckets[index] = Math.min(minBuckets[index], nums[i]);
1029
+ maxBuckets[index] = Math.max(maxBuckets[index], nums[i]);
1030
+ }
1031
+
1032
+ var maxGap = Number.MIN_SAFE_INTEGER;
1033
+ var preVal = min;
1034
+ for (var j = 0; j < len - 1; j++) {
1035
+ if (minBuckets[j] === Number.MAX_SAFE_INTEGER && maxBuckets[j] === Number.MIN_SAFE_INTEGER) continue;
1036
+ maxGap = Math.max(maxGap, minBuckets[j] - preVal);
1037
+ preVal = maxBuckets[j];
1038
+ }
1039
+ maxGap = Math.max(maxGap, max - preVal);
1040
+
1041
+ return maxGap;
1042
+ };
1043
+
1044
+ console.log(maximumGap);
1045
+ `),
1046
+ new Template(`
1047
+ var LRUCache = function(capacity) {
1048
+ this.capacity = capacity;
1049
+ this.length = 0;
1050
+ this.map = {};
1051
+ this.head = null;
1052
+ this.tail = null;
1053
+ };
1054
+
1055
+ LRUCache.prototype.get = function(key) {
1056
+ var node = this.map[key];
1057
+ if (node) {
1058
+ this.remove(node);
1059
+ this.insert(node.key, node.val);
1060
+ return node.val;
1061
+ } else {
1062
+ return -1;
1063
+ }
1064
+ };
1065
+
1066
+ LRUCache.prototype.put = function(key, value) {
1067
+ if (this.map[key]) {
1068
+ this.remove(this.map[key]);
1069
+ this.insert(key, value);
1070
+ } else {
1071
+ if (this.length === this.capacity) {
1072
+ this.remove(this.head);
1073
+ this.insert(key, value);
1074
+ } else {
1075
+ this.insert(key, value);
1076
+ this.length++;
1077
+ }
1078
+ }
1079
+ };
1080
+
1081
+ /**
1082
+ * Your LRUCache object will be instantiated and called as such:
1083
+ * var obj = Object.create(LRUCache).createNew(capacity)
1084
+ * var param_1 = obj.get(key)
1085
+ * obj.put(key,value)
1086
+ */
1087
+
1088
+ LRUCache.prototype.remove = function (node) {
1089
+ var prev = node.prev;
1090
+ var next = node.next;
1091
+ if (next) next.prev = prev;
1092
+ if (prev) prev.next = next;
1093
+ if (this.head === node) this.head = next;
1094
+ if (this.tail === node) this.tail = prev;
1095
+ delete this.map[node.key];
1096
+ };
1097
+
1098
+ LRUCache.prototype.insert = function (key, val) {
1099
+ var node = new List(key, val);
1100
+ if (!this.tail) {
1101
+ this.tail = node;
1102
+ this.head = node;
1103
+ } else {
1104
+ this.tail.next = node;
1105
+ node.prev = this.tail;
1106
+ this.tail = node;
1107
+ }
1108
+ this.map[key] = node;
1109
+ };
1110
+
1111
+ console.log(LRUCache);
1112
+ `),
1113
+ new Template(`
1114
+ var isInterleave = function(s1, s2, s3) {
1115
+ var dp = {};
1116
+ if (s3.length !== s1.length + s2.length) return false;
1117
+ return helper(s1, s2, s3, 0, 0, 0, dp);
1118
+ };
1119
+
1120
+ var helper = function (s1, s2, s3, i, j, k, dp) {
1121
+ var res = false;
1122
+
1123
+ if (k >= s3.length) return true;
1124
+ if (dp['' + i + j + k] !== undefined) return dp['' + i + j + k];
1125
+
1126
+ if (s3[k] === s1[i] && s3[k] === s2[j]) {
1127
+ res = helper(s1, s2, s3, i + 1, j, k + 1, dp) || helper(s1, s2, s3, i, j + 1, k + 1, dp);
1128
+ } else if (s3[k] === s1[i]) {
1129
+ res = helper(s1, s2, s3, i + 1, j, k + 1, dp);
1130
+ } else if (s3[k] === s2[j]) {
1131
+ res = helper(s1, s2, s3, i, j + 1, k + 1, dp);
1132
+ }
1133
+
1134
+ dp['' + i + j + k] = res;
1135
+
1136
+ return res;
1137
+ };
1138
+
1139
+ console.log(isInterleave);
1140
+ `),
1141
+ new Template(`
1142
+ var solveNQueens = function(n) {
1143
+ var res = [];
1144
+ if (n === 1 || n >= 4) dfs(res, [], n, 0);
1145
+ return res;
1146
+ };
1147
+
1148
+ var dfs = function (res, points, n, index) {
1149
+ for (var i = index; i < n; i++) {
1150
+ if (points.length !== i) return;
1151
+ for (var j = 0; j < n; j++) {
1152
+ if (isValid(points, [i, j])) {
1153
+ points.push([i, j]);
1154
+ dfs(res, points, n, i + 1);
1155
+ if (points.length === n) res.push(buildRes(points));
1156
+ points.pop();
1157
+ }
1158
+ }
1159
+ }
1160
+ };
1161
+
1162
+ var buildRes = function (points) {
1163
+ var res = [];
1164
+ var n = points.length;
1165
+ for (var i = 0; i < n; i++) {
1166
+ res[i] = '';
1167
+ for (var j = 0; j < n; j++) {
1168
+ res[i] += (points[i][1] === j ? 'Q' : '.');
1169
+ }
1170
+ }
1171
+ return res;
1172
+ };
1173
+
1174
+ var isValid = function (oldPoints, newPoint) {
1175
+ var len = oldPoints.length;
1176
+ for (var i = 0; i < len; i++) {
1177
+ if (oldPoints[i][0] === newPoint[0] || oldPoints[i][1] === newPoint[1]) return false;
1178
+ if (Math.abs((oldPoints[i][0] - newPoint[0]) / (oldPoints[i][1] - newPoint[1])) === 1) return false;
1179
+ }
1180
+ return true;
1181
+ };
1182
+
1183
+ console.log(solveNQueens);
1184
+ `),
1185
+ ];