-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc5.js
3000 lines (2956 loc) · 117 KB
/
sc5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
class SC5 {
constructor(key, digest=0, blocksize = 0, mode="string",error=false) {
this.salt_1_dat = [0xdc, 0xc2, 0x81, 0xf2, 0x67, 0x59, 0xba, 0xe6, 0x58, 0x7c, 0xea, 0xbf, 0xe8, 0x8d, 0x95, 0x8b, 0x7c, 0x12, 0x17, 0x15, 0x50, 0x77, 0x5e, 0x13, 0x6c, 0x67, 0x17, 0x6f, 0x92, 0x95, 0x7c, 0x55, 0xb3, 0xb6, 0x05, 0xc6];
this.salt_2_dat = [0x77, 0x9a, 0x82, 0x45, 0xc7, 0xa6, 0x7a, 0x85, 0xd4, 0x2a, 0x89, 0xad, 0xd5, 0x13, 0xd2, 0x16, 0x01, 0xb4, 0x2d, 0x3b, 0xa8, 0x8a, 0xe9, 0x00, 0x02, 0x59, 0x9f, 0x5f, 0x30, 0x93, 0x6c, 0xe4, 0x92, 0xb1, 0x60, 0x28];
this.salt_st_dat = [0x01, 0xaa, 0xbb, 0xfa, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff];
this.hex_char = "abcdef0123456789";
this.change_a = "864123b0ec7fd9a5";
this.change_b = "fc3bd9a2678e5014";
this.change_c = "53804edc67f1ba92";
this.change_d = "9ca621fd74538e0b";
this.change_e = "7c20fbe64d9351a8";
this.change_f = "210f8eacd764b593";
this.change_0 = "e7b8a246590c31df";
this.change_1 = "28b5ae9cd430167f";
this.change_2 = "17fc54839b062eda";
this.change_3 = "d986c1f2ba04537e";
this.change_4 = "34b78915d0ae26fc";
this.change_5 = "5bef683092c1ad74";
this.change_6 = "df9b3a41c76e2508";
this.change_7 = "9374d21c50fe8b6a";
this.change_8 = "60f931edc7b254a8";
this.change_9 = "c17384b062ea95df";
this.hashchan = "4f571ae30b9c2d68";
this.hashchan1 = "94c37de51f80b6a2";
this.hex_characters = "abcdef0123456789";
this.sg="C1C2C3C4E1324412";
this.base64_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+";
this.hex_1 = "549e30c67ba2f81d";
this.hex_2 = "e326a51d04789fcb";
this.hex_3 = "3bd45206fec9a718";
this.hXc = "0132102013201203";
this.hth_1 = "61fa2bed734890c5";
this.rot13_1="v/Fpr29x0UjfHXoYmGO73LIDKulEaPgCdzN56Th8BqSsnRy4e1cW+tJQZVwAbkMi";
this.rot13_2="sdk5qnN7MJITpwEUWfih8m0X91tYyC4eDAx2brOlHVgFK6u/ocP3a+zSjRvQZGBL";
this.rot13_3="/hX2I5EbOmzxDJ9tK60aA3jV78YcqHMBQgUNZCWrRdveyswfSLun1FGpokPi4lT+";
this.rot13_4="JuEnkzXo2lM5cadLfStT6s4R8j3rhp+NZWHixq9PCUQw0gOvFDeVGy/1AbBYmKI7";
this.hash0 = "Lp2Pa9D+C7wF0Rt6ogmOzjncEQrTXhUZGiyS1f8B4/WHYNM3klsueAKVvIxJqb5d";
this.hash1 = "257IF1i6SPaQXrsNYtwERHLUCZTxOjm9JclqzKuAkn0DVW4gMbGByv38/fdhpo+e";
this.hash2 = "GzhwZ8MgP4k7l5RHaxAKu0vSFT9ycIn6EVm/NJief2qY+jsQUWbtoXL3pDrOBd1C";
this.hash3 = "p40k9jRq786irIMoCWUn+uEeZaOhtyXgAL2dw5V1QvmbS3HYJGfxPDNFscKB/Tzl";
this.hash4 = "HtigypvlBwSa94zkD5rPEUXMYR6LjdOJ+ueVF7on1h/3GfINmQWKTbCxq82Zsc0A";
this.hash5 = "EfUAHgGCpohPNW47wkv+/dc6OrmbKSVzy0tj8M32La5RuIlqXeJQixsZ91TFYBnD";
this.hash6 = "mTANO4zeudspRMXQxbPLV5Hi+GgW12Y/qDIrl3BUtjh9fov0wS6J7c8yknZCFEaK";
this.hash7 = "IN4+2QL/UqthmjPKGRJvakdln6SAwObpVeE30szyDCi7Wuf8xgZc9BTHYX1rMFo5";
this.hash8 = "oApR3+SPcLdJaOeVQmhN4F9BrKM267/wkyGXTUYDn8HvZxjitqECu0bgIszlf5W1";
this.hash9 = "gVmZR0HGbx+OeskhAv2yLBW1fY5jF4dEulnMiP/Tp6JNqX8a93SoDQ7IrtcwUCKz";
this.hasha = "VOW3M7gvdrxu5hYeFcz2jKoEt0UP9lNy4I1mnZsqaLCiAB6J+8RGpTQfXwkbDSH/";
this.hashb = "08TjDklwrCpAgH7GsU3QIvBaREZOM+of/ni1XFyLVYxhPzW629t4JKSmuNbd5eqc";
this.hashc = "D1396NtaIpQydChzMnlFvYS/iLu7eAG8BbOxqoUVX5+rjH2EWRKP4gmTwZsfc0Jk";
this.hashd = "3QjE5SfU+Y1MVbIy0a6Zm8hKoO4e2nctFdR9uXrpWJlCxGAsvBT/kzDwigNqP7LH";
this.hashe = "hRa4QoBy5blILAusSC/YFXKr6qfpP92cN13TUvtZJxGWw0e+DOM7z8idVjHgEmkn";
this.hashf = "fX+0wuaDgj4U8GKBHPF17ATq3vpmSV9ICkoY/RJxMeOZiQbLsdn2WNhtyrl5z6cE";
this.ax1xxxx=0;
if (error === null || error === undefined || error === "") {
this.error = false;
} else {
this.error = error;
}
if (key === null || key === undefined || key === "") {
this.key = "123456789";
} else {
this.key = key;
}
if (mode === null || mode === undefined || mode === "") {
this.mode = "string";
} else {
this.mode = mode;
}
if (!isNaN(digest)) {
if (digest === null || digest === undefined || digest === "") {
this.digest=0;
}else{
if(isNaN(digest)){
this.digest = digest;
}else{
this.digest = parseInt(digest);
}
}
}else{
this.digest=0;
}
if (!isNaN(blocksize)) {
if (blocksize === null || blocksize === undefined || blocksize === "") {
this.blocksize=128;
}else{
if(parseInt(blocksize)>=128 && parseInt(blocksize)<256){
this.blocksize = 128;
}else if(parseInt(blocksize)>=256){
this.blocksize = 256;
}else if(parseInt(blocksize)<128){
this.blocksize = 0;
}else{
if(isNaN(blocksize)){
if(blocksize>=128 && blocksize<256){
this.blocksize = 128;
}if(blocksize>=256){
this.blocksize = 256;
}else{
this.blocksize=0;
}
}else{
if(parseInt(blocksize)>=128 && parseInt(blocksize)<256){
this.blocksize = 128;
}if(parseInt(blocksize)>=256){
this.blocksize = 256;
}else{
this.blocksize=0;
}
}
}
}
}else{
this.blocksize=128;
}
}
setblocksize(blocksize = 128){
if (!isNaN(blocksize)) {
if (blocksize === null || blocksize === undefined || blocksize === "") {
this.blocksize=128;
}else{
if(parseInt(blocksize)>=128 && parseInt(blocksize)<256){
this.blocksize = 128;
}else if(parseInt(blocksize)>=256){
this.blocksize = 256;
}else if(parseInt(blocksize)<128){
this.blocksize = 0;
}else{
if(isNaN(blocksize)){
if(blocksize>=128 && blocksize<256){
this.blocksize = 128;
}if(blocksize>=256){
this.blocksize = 256;
}else{
this.blocksize=0;
}
}else{
if(parseInt(blocksize)>=128 && parseInt(blocksize)<256){
this.blocksize = 128;
}if(parseInt(blocksize)>=256){
this.blocksize = 256;
}else{
this.blocksize=0;
}
}
}
}
}else{
this.blocksize=128;
}
}
setdigest(digest = 0){
if (!isNaN(digest)) {
if (digest === null || digest === undefined || digest === "") {
this.digest=0;
}else{
if(isNaN(digest)){
this.digest = digest;
}else{
this.digest = parseInt(digest);
}
}
}else{
this.digest=0;
}
}
setkey(key){
if (key === null || key === undefined || key === "") {
this.key = "123456789";
} else {
this.key = key;
}
}
setmode(mode){
if (mode === null || mode === undefined || mode === "") {
this.mode = "string";
} else {
this.mode = mode;
}
}
seterror(error){
if (error === null || error === undefined || error === "") {
this.error = false;
} else {
this.error = error;
}
}
createPANEL(){
var process_panel = document.getElementById("process_viewer_SC5_process_panel");
if (process_panel) {
var this_process = document.createElement ("div");
var block = document.createElement ("div");
var process = document.createElement ("div");
block.style.fontSize = "36px";
block.style.color = "#db3e3e";
block.style.fontFamily = "'Roboto Slab',sans-serif";
block.style.display = "block";
block.style.marginTop = "10px";
process.style.fontSize = "18px";
process.style.color = "dimgrey";
process.style.fontFamily = "'Roboto Slab',sans-serif";
process.style.wordBreak = "break-word";
process.style.display = "block";
process.style.marginTop = "10px";
this_process.appendChild (block);
this_process.appendChild (process);
process_panel.appendChild (this_process);
return [process_panel,this_process,block,process];
}
var div = document.createElement ("div");
div.id = "process_viewer_SC5_Panel";
div.style.width = "320px";
div.style.height = "auto";
div.style.backgroundColor = "transparent";
div.style.zIndex = "9999";
div.style.position = "fixed";
div.style.left = "50%";
div.style.top = "50%";
div.style.transform = "translate(-50%, -50%)";
div.style.border = "2px solid salmon";
div.style.borderRadius = "8px";
div.style.fontSize = "36px";
div.style.color = "#db3e3e";
div.style.fontFamily = "'Roboto Slab',sans-serif";
div.style.backdropFilter = "blur(4px)";
div.style.textAlign = "center";
div.style.padding = "5px";
var logo = document.createElement ("img");
logo.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAC8ElEQVR4nO2ZW4hNURjHf2aMy7gO0QhDrrmlUWRCIsWDywMPg6JGlHjgZV6QiaYQuT3wYF4oE0UUUZLGRNFEI5OUZDAuTe7369aq/9RubOfs2zl7b51ffbVa6/vW+n/nsvZa34YcORLLMqCchDMJ+CWbQkLpANQDluy6+hLHciXwQmapL1EUAs0SXwGsUvsp0I0EsV3CbwF5spvq20ZCGAx8kugZtv4y4DfwGRhKAjipJI47jNVq7AQxZ5rtUx/iMD4I+KhkZhJT8oAGidyawq9KPreBfGLIGgl8kmZn6go8ku9qYkZP4LnEuTmOLJXvS6A3MWKPj6f3VcXsJiaMAL7qPDXZQ1ypYr4Do4kB5/XJHvERW6PYc0TMPAl5BxQ7jHcCimSm3Z5ixVqaKxIKgHsSUfkPny22069pO1GpcTOXmTPrbJSAB0DnNM8MS20nzDd1Xz4byDJ9gFdafGEKPzeJGBbJ5w3QjyxyWAtfTuPnNhHDRfkdIkuMA34AP4EJISYyVluxmXciWeCKhB1w4eslEcNB+dZn+lq8RAu9BvpmIJEioFX+i8kQXYCHWmSdyxiviRjWy79ZV+bQ2awFmjzs934SyQfuKGYTITMQ+KDJ53qI85OIYbZizJW5hBA5ponPeIzzm4jhrOKOEhJTdX39BozKYiLDdao2a08nIGYLvCEhO3zEB0nEsFOxDbpK+2alrVrYK4JEegDPFL8Cn3QHWmzVwiA7naW2HyoU3yJNnqkO4WstsN1HCkKozlR7DR4GfNEfzV4tjIoy24Yz0kvg6RTVwqiolaZTbgNmhfgwatt1jO0KOFeJraZsNKY9HjS6qBa6Za8tEdMOSpXmugt0TOW4Vo6PQzqwhZ1IobRZ0pr2CB3Wy0vz+mCOzKmo7YdyaWyV5r/YL4drCXjXVyet+9oPjNE102u1MCpKpdVcucfbBy4EqBZGRY00X2rrWKCO98AAkkN/4K20z0c3Pivh1mQv7yfZ6qL+eeT4b/kDXLNVbksXjZ8AAAAASUVORK5CYII=";
var process_panel = document.createElement ("div");
process_panel.id = "process_viewer_SC5_process_panel"
var this_process = document.createElement ("div");
var block = document.createElement ("div");
var process = document.createElement ("div");
block.style.fontSize = "36px";
block.style.color = "#db3e3e";
block.style.fontFamily = "'Roboto Slab',sans-serif";
process.style.fontSize = "18px";
process.style.color = "dimgrey";
process.style.fontFamily = "'Roboto Slab',sans-serif";
process.style.wordBreak = "break-word";
div.appendChild (logo);
this_process.appendChild (block);
this_process.appendChild (process);
process_panel.appendChild (this_process);
div.appendChild (process_panel);
document.body.prepend (div);
return [process_panel,this_process,block,process];
}
writex(a1,a2){
a1.innerHTML = a2;
return true;
}
async asyncEncrypt (d) {
var [process_panel,this_process,block,process] = [null,null,null];
try{
var [[a,a1,b,z,i,keylen,c,m],[k,g,h,rxa],[ax,e,f]]=[this.keygen0(d,"enc"),[1,1,1,1],["","",""]];
try{
let error = null;
try{
[process_panel,this_process,block,process] = await this.createPANEL();
}catch(ex){error = true;}
if(!error){
var size = new TextEncoder().encode(d).length;
var kiloBytes = size / 1024;
this.writex(process,"Single Core Encrypt Process<br>Size:"+kiloBytes.toFixed(1) + " KB");
this.writex(block,"0/"+m);
let promise = new Promise((resolve, reject) => {
let intervalID = setInterval(function () {
if (process.innerHTML.length > 1 && block.innerHTML.length > 1) {
clearInterval(intervalID);
resolve();
}
}, 10);
});
await promise;
}
}catch(e){}
for(var l of i){
await new Promise(r => setTimeout(r, 1));
[a,a1,b,f,keylen,k,m,c,h,g,e,ax,l,z,i] = this.epart0(a,a1,b,f,keylen,k,m,c,h,g,e,ax,l,z,i);
try{
this.writex(block,rxa+"/"+m);
await new Promise(r => setTimeout(r, 1));
rxa++;
}catch(e){}
await new Promise(r => setTimeout(r, 1));
}
e+="==";
if((this_process) && (process_panel)){
this_process.remove();
if (!process_panel.hasChildNodes()) {
process_panel.parentNode.remove();
}
}
return e;
}catch(ex){
if((this_process) && (process_panel)){
this_process.remove();
if (!process_panel.hasChildNodes()) {
process_panel.parentNode.remove();
}
}
if(this.error==false){return "";}{
throw new Error('asyncEncrypt Error:'+ex);
}
}
}
async asyncDecrypt (e) {
var [process_panel,this_process,block,process] = [null,null,null];
try{
e = e.replace(/ /g, "").trim().replace(/=/g, "");
var [[a,a1,b,z,h,keylen,c,n],[l,f,g,rxa],[d,ax,i],[ixa1k]] = [this.keygen0(e,"dec"),[1,1,1,1],["","",""],[0]];
try{
let error = null;
try{
[process_panel,this_process,block,process] = await this.createPANEL();
}catch(ex){error = true;}
if(!error){
var size = new TextEncoder().encode(e).length;
var kiloBytes = size / 1024;
this.writex(process,"Single Core Decrypt Process<br>Size:"+kiloBytes.toFixed(1) + " KB");
this.writex(block,"0/"+n);
let promise = new Promise((resolve, reject) => {
let intervalID = setInterval(function () {
if (process.innerHTML.length > 1 && block.innerHTML.length > 1) {
clearInterval(intervalID);
resolve();
}
}, 10);
});
await promise;
}
}catch(e){}
for(var m of h){
await new Promise(r => setTimeout(r, 1));
[b,a1,i,keylen,l,n,c,ax,g,a,f,m,z,d,ixa1k,h] = this.dpart0(b,a1,i,keylen,l,n,c,ax,g,a,f,m,z,d,ixa1k,h);
try{
this.writex(block,rxa+"/"+n);
await new Promise(r => setTimeout(r, 1));
rxa++;
}catch(e){}
await new Promise(r => setTimeout(r, 1));
}
d = this.dend0(d);
if((this_process) && (process_panel)){
this_process.remove();
if (!process_panel.hasChildNodes()) {
process_panel.parentNode.remove();
}
}
return d;
}catch(ex){
if((this_process) && (process_panel)){
this_process.remove();
if (!process_panel.hasChildNodes()) {
process_panel.parentNode.remove();
}
}
if(this.error==false){return "";}{
throw new Error('asyncDecrypt Error:'+ex);
}
}
}
WP(){
var h=10,u=[],w=[],q,p,B,v,A,f,e,b,a,G,F,s="\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886";for(q=8;q-->0;){u[q]=[]}
for(p=0;p<256;p++){B=s.charCodeAt(p/2);f=((p&1)==0)?B>>>8:B&255;e=f<<1;if(e>=256){e^=285}
b=e<<1;if(b>=256){b^=285}
a=b^f;G=b<<1;if(G>=256){G^=285}
F=G^f;u[0][p]=[0,0];u[0][p][0]=(f<<24)|(f<<16)|(b<<8)|(f);u[0][p][1]=(G<<24)|(a<<16)|(e<<8)|(F);for(var q=1;q<8;q++){u[q][p]=[0,0];u[q][p][0]=(u[q-1][p][0]>>>8)|((u[q-1][p][1]<<24));u[q][p][1]=(u[q-1][p][1]>>>8)|((u[q-1][p][0]<<24))}}
w[0]=[0,0];for(v=1;v<=h;v++){A=8*(v-1);w[v]=[0,0];w[v][0]=(u[0][A][0]&4278190080)^(u[1][A+1][0]&16711680)^(u[2][A+2][0]&65280)^(u[3][A+3][0]&255);w[v][1]=(u[4][A+4][1]&4278190080)^(u[5][A+5][1]&16711680)^(u[6][A+6][1]&65280)^(u[7][A+7][1]&255)}
let z=[],y=[],d=[],o=[],m=[],l=[],g=[],n=0,j=0;function E(){let C,c,I,H,x;for(C=0,c=0;C<8;C++,c+=8){l[C]=[0,0];l[C][0]=((y[c]&255)<<24)^((y[c+1]&255)<<16)^((y[c+2]&255)<<8)^((y[c+3]&255));l[C][1]=((y[c+4]&255)<<24)^((y[c+5]&255)<<16)^((y[c+6]&255)<<8)^((y[c+7]&255))}
for(C=0;C<8;C++){g[C]=[0,0];o[C]=[0,0];g[C][0]=l[C][0]^(o[C][0]=d[C][0]);g[C][1]=l[C][1]^(o[C][1]=d[C][1])}
for(I=1;I<=h;I++){for(C=0;C<8;C++){m[C]=[0,0];for(x=0,H=56,c=0;x<8;x++,H-=8,c=H<32?1:0){m[C][0]^=u[x][(o[(C-x)&7][c]>>>(H%32))&255][0];m[C][1]^=u[x][(o[(C-x)&7][c]>>>(H%32))&255][1]}}
for(C=0;C<8;C++){o[C][0]=m[C][0];o[C][1]=m[C][1]}
o[0][0]^=w[I][0];o[0][1]^=w[I][1];for(C=0;C<8;C++){m[C][0]=o[C][0];m[C][1]=o[C][1];for(x=0,H=56,c=0;x<8;x++,H-=8,c=H<32?1:0){m[C][0]^=u[x][(g[(C-x)&7][c]>>>(H%32))&255][0];m[C][1]^=u[x][(g[(C-x)&7][c]>>>(H%32))&255][1]}}
for(C=0;C<8;C++){g[C][0]=m[C][0];g[C][1]=m[C][1]}}
for(C=0;C<8;C++){d[C][0]^=g[C][0]^l[C][0];d[C][1]^=g[C][1]^l[C][1]}};function k(r){let c,x,t=r.toString();r=[];for(c=0;c<t.length;c++){x=t.charCodeAt(c);if(x>=256){r.push(x>>>8&255)}
r.push(x&255)}
return r};const enc={init:function(){for(var c=32;c-->0;){z[c]=0}
n=j=0;y=[0];for(c=8;c-->0;){d[c]=[0,0]}
return enc},add:function(c){if(!c){return enc}
c=k(c);let K=c.length*8,r=0,t=(8-(K&7))&7,C=n&7,x,H,J,I=K;for(x=31,J=0;x>=0;x--){J+=(z[x]&255)+(I%256);z[x]=J&255;J>>>=8;I=Math.floor(I/256)}
while(K>8){H=((c[r]<<t)&255)|((c[r+1]&255)>>>(8-t));y[j++]|=H>>>C;n+=8-C;if(n==512){E();n=j=0;y=[]}
y[j]=((H<<(8-C))&255);n+=C;K-=8;r++}
if(K>0){H=(c[r]<<t)&255;y[j]|=H>>>C}else{H=0}
if(C+K<8){n+=K}else{j++;n+=8-C;K-=8-C;if(n==512){E();n=j=0;y=[]}
y[j]=((H<<(8-C))&255);n+=K}
return enc},finalize:function(){let r,c,t,H="",C=[],x="0123456789ABCDEF".split("");y[j]|=128>>>(n&7);j++;if(j>32){while(j<64){y[j++]=0}
E();j=0;y=[]}
while(j<32){y[j++]=0}
y.push.apply(y,z);E();for(r=0,c=0;r<8;r++,c+=8){t=d[r][0];C[c]=t>>>24&255;C[c+1]=t>>>16&255;C[c+2]=t>>>8&255;C[c+3]=t&255;t=d[r][1];C[c+4]=t>>>24&255;C[c+5]=t>>>16&255;C[c+6]=t>>>8&255;C[c+7]=t&255}
for(r=0;r<C.length;r++){H+=x[C[r]>>>4];H+=x[C[r]&15]}
return H.toLowerCase();}}
function h2b(str){let hexString=str,strOut='';for(var x=0;x<hexString.length;x+=2){strOut+=String.fromCharCode(parseInt(hexString.substr(x,2),16));}
return strOut;}
function hex2Uint(hex,buf){
let view=new Uint8Array(hex.length/2)
for(var i=0;i<hex.length;i+=2){view[i/2]=parseInt(hex.substring(i,i+2),16)}
if(buf){return view.buffer}
return view}
function h2b64(hex){return btoa(hex.match(/\w{2}/g).map(function(a){return String.fromCharCode(parseInt(a,16));}).join(""));}
let res;const Whirlpool={encSync:function(i,digest){if(!i||typeof i!=='string'||i===''){return null}
res=enc.init().add(i).finalize()
if(!digest||digest.toLowerCase()==='hex'){return res}
if(digest.toLowerCase()==='bytes'){return h2b(res);}
if(digest.toLowerCase()==='base64'){return h2b64(res);}
if(digest.toLowerCase()==='uint8'){return hex2Uint(res,false);}
if(digest.toLowerCase()==='arraybuffer'){return hex2Uint(res,true);}},enc:function(i,digest,cb){if(typeof digest=='function'){cb=digest
return}
if(typeof i!=='string'||i===''){cb('whirlpool input must be a string',null)
return}
try{res=enc.init().add(i).finalize();if(typeof disgest==='function'||digest.toLowerCase()==='hex'){cb(false,res);}
if(digest.toLowerCase()==='bytes'){cb(false,h2b(res));}
if(digest.toLowerCase()==='base64'){cb(false,h2b64(res));}
if(digest.toLowerCase()==='uint8'){cb(false,hex2Uint(res,false));}
if(digest.toLowerCase()==='arraybuffer'){cb(false,hex2Uint(res,true));}}catch(err){cb(err,null);}},encP:function(i,digest){return new Promise(function(resolve,reject){if(!i||typeof i!=='string'||i===''){reject('whirlpool input must be a string');}
try{res=enc.init().add(i).finalize();if(!digest||digest.toLowerCase()==='hex'){resolve(res);}
if(digest.toLowerCase()==='bytes'){resolve(h2b(res));}
if(digest.toLowerCase()==='base64'){resolve(h2b64(res));}
if(digest.toLowerCase()==='uint8'){resolve(hex2Uint(res,false));}
if(digest.toLowerCase()==='arraybuffer'){resolve(hex2Uint(res,true));}
return;}catch(err){reject(err);}})}}
return Whirlpool;
}
base64_encode(array) {
var base64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var result = '';
var i, j, triplet;
for (i = 0; i < array.length; i += 3) {
triplet = (array[i] << 16) | (array[i + 1] << 8) | array[i + 2];
for (j = 0; j < 4; j += 1) {
if (i * 8 + j * 6 <= array.length * 8) {
result += base64.charAt((triplet >> 18 - j * 6) & 0x3F);
}
}
}
return result;
}
base64_decode(str) {
let buffer = [];
let bits = 0;
let value = 0;
let index = 0;
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i);
let digit = charCode > 64 && charCode < 91 ? charCode - 65
: charCode > 96 && charCode < 123 ? charCode - 71
: charCode > 47 && charCode < 58 ? charCode + 4
: charCode === 43 ? 62
: charCode === 47 ? 63
: -1;
if (digit !== -1) {
value = (value << 6) | digit;
bits += 6;
if (bits >= 8) {
buffer[index++] = (value >> (bits - 8)) & 255;
bits -= 8;
}
}
}
return new Uint8Array(buffer);
}
adler32(message) {
const MOD_ADLER = 65521;
let a = 1, b = 0;
for (let i = 0; i < message.length; i++) {
a = (a + message.charCodeAt(i)) % MOD_ADLER;
b = (b + a) % MOD_ADLER;
}
return ((b << 16) | a).toString(16).padStart(8, '0').replace(/-/g, "");
}
strtr(text,textstring, replace_pairs) {
let b = textstring;
let c = replace_pairs;
let d = text.replace(/[A-Za-z0-9+/=]/g, m => c[b.indexOf(m)]);
return d;
}
str_split(str, length) {
// str parametresinin tipini bir değişkene kaydet
var inputType = typeof str;
// eğer girdi bir number ise, onu bir Uni8Array'e dönüştür
if (inputType == "number") {
// sayıyı bir dizgeye dönüştür
var strNum = str.toString();
// dizgeyi bir Uni8Array'e dönüştür
str = new Uint8Array(strNum.length);
// dizgenin her elemanını sayıya dönüştürerek Uni8Array'e atayın
for (var i = 0; i < strNum.length; i++) {
str[i] = parseInt(strNum[i]);
}
}
// eğer girdi bir Uni8Array ise, onu bir dizgeye dönüştür
// if (str instanceof Uint8Array) {
// str = String.fromCharCode.apply(null, str);
// }
// düzenli ifadeyi oluştur
// var regex = new RegExp("(.{1," + length + "})", "gms");
// // match() fonksiyonu ile dizgeyi düzenli ifadeye göre eşleştiren bir dizi elde et
// var result = str.match(regex);
if (typeof str === "string") {
str = this.StringTouint8Array(str);
}
var result = [];
var decoder = new TextDecoder("utf-8"); // string'e dönüştürmek için decoder
var uint8array = str;
for (var i = 0; i < uint8array.length; i += length) {
var subarray = uint8array.slice(i, i + length); // uni8array'i istenen uzunlukta bölüyor
if (inputType == "object" || inputType == "number") {
var str = subarray;
}else{
var str = decoder.decode(subarray); // subarray'i string'e çeviriyor
}
result.push(str); // sonuç dizisine ekliyor
}
// eğer sonuç null ise, girdiyi bir diziye dönüştür
if (subarray == null) {
result = [str];
}
// sonucu döndür
return result;
}
split_block(str,blocksize) {
// Check if the input is a valid Uint8Array
if (!(str instanceof Uint8Array)) {
throw new TypeError('Input must be a Uint8Array');
}
// Define the block size
const length = blocksize;
// Initialize an array to store the output
var result = [];
// Loop through the input
for (var i = 0; i < str.length; i += length) {
// Get the slice of the input corresponding to the current block
var subarray = str.slice(i, i + length);
// Pad or slice the subarray to make it exactly blocksize bytes long
subarray = subarray.length < blocksize ? new Uint8Array([...subarray, ...new Array(blocksize - subarray.length).fill(0)]) : subarray;
// Add the subarray to the output array
result.push(subarray);
}
// Return the output array
return result;
}
removeEmptyBytes(array) {
// Check if the input is a valid Uint8Array
if (!(array instanceof Uint8Array)) {
throw new TypeError('Input must be a Uint8Array');
}
// Filter the array by non-zero values
var filtered = array.filter(x => x !== 0);
// Return the filtered array
return filtered;
}
strrev(str) {
// parametrenin türünü kontrol et
if (typeof str === "string") {
// yeni bir dizge oluştur
var res = "";
// son karakterden başlayarak dizgenin her karakterini ekle
for (var i = str.length - 1; i >= 0; i--) {
res += str[i];
}
// sonucu döndür
return res;
} else if (str instanceof Uint8Array) {
// yeni bir Uint8Array oluştur
var res = new Uint8Array(str.length);
// son elemandan başlayarak dizinin her elemanını kopyala
for (var i = 0; i < str.length; i++) {
res[i] = str[str.length - 1 - i];
}
// sonucu döndür
return res;
} else {
// hata fırlat
throw new Error("Invalid parameter type");
}
}
CharCodeToUint8Array(hex) {
var str = String.fromCharCode(hex);
// Convert the string to a Uint8Array using the TextEncoder class
var encoder = new TextEncoder();
var arr = encoder.encode(str);
// Return the Uint8Array
return arr;
}
uint8ArrayToString(uint8Array) {
return new TextDecoder().decode(uint8Array);
}
StringTouint8Array(str) {
return new TextEncoder().encode(str);
}
hex2bin(hexString) {
if (typeof hexString !== "string") {
// hata fırlat veya başka bir işlem yap
throw new TypeError("hexString must be a string");
}
// hexString'in uzunluğunu kontrol et
if (hexString.length % 2 !== 0) {
// Uzunluk tek ise başına sıfır ekle
hexString = "0" + hexString;
}
var length = hexString.length / 2;
var uint8Array = new Uint8Array(length);
for (let i = 0; i < length; ++i) {
// Her iki karakteri al ve 16 tabanında sayıya dönüştür
uint8Array[i] = parseInt(hexString.substr(i * 2, 2), 16);
}
return uint8Array;
}
bin2hex(uint8Array) {
let hexString = "";
for (let i = 0; i < uint8Array.length; i++) {
let hex = uint8Array[i].toString(16).padStart(2, "0");
hexString += hex;
}
return hexString;
}
substr(str, start, length) {
try{
if (typeof str == "number") {
str = str.toString();
}
// parametrelerin türünü kontrol et
if (typeof str !== "string") {
throw new Error("Invalid string parameter");
}
if (typeof start !== "number") {
throw new Error("Invalid start parameter");
}
if (length !== undefined && typeof length !== "number") {
throw new Error("Invalid length parameter");
}
// eğer başlangıç indeksi negatifse, dizge uzunluğuna ekle
if (start < 0) {
start = str.length + start;
}
// eğer uzunluk verilmediyse veya negatifse, dizge uzunluğunu kullan
if (length === undefined || length < 0) {
length = str.length;
}
// başlangıç indeksinden verilen uzunlukla dizgeyi kes
return str.slice(start, start + length);
} catch (e) {
return str;
}
}
md5(data, asUint8Array = false){
if (data instanceof Uint8Array) {
var decoder = new TextDecoder();
var data = decoder.decode(data);
}
var result = CryptoJS.MD5(data).toString(CryptoJS.enc.Hex); // get the MD5 hash of data as a hex string
if (asUint8Array) {
// convert the result to a Uint8Array
var resultLength = result.length / 2; // the length of the Uint8Array is half the length of the hex string
var resultUint8 = new Uint8Array(resultLength); // create a new Uint8Array with the result length
for (var i = 0; i < resultLength; i++) {
// get the hex value of each pair of characters in the result
var hex = result.substring(i * 2, i * 2 + 2);
// convert the hex value to a decimal value
var dec = parseInt(hex, 16);
// set the decimal value to the corresponding index in the Uint8Array
resultUint8[i] = dec;
}
// return the Uint8Array
return resultUint8;
}
else {
// return the result as a string
return result;
}
}
sha1(data, asUint8Array = false){
if (data instanceof Uint8Array) {
var decoder = new TextDecoder();
var data = decoder.decode(data);
}
var result = CryptoJS.SHA1(data).toString(CryptoJS.enc.Hex); // get the SHA1 hash of data as a hex string
if (asUint8Array) {
// convert the result to a Uint8Array
var resultLength = result.length / 2; // the length of the Uint8Array is half the length of the hex string
var resultUint8 = new Uint8Array(resultLength); // create a new Uint8Array with the result length
for (var i = 0; i < resultLength; i++) {
// get the hex value of each pair of characters in the result
var hex = result.substring(i * 2, i * 2 + 2);
// convert the hex value to a decimal value
var dec = parseInt(hex, 16);
// set the decimal value to the corresponding index in the Uint8Array
resultUint8[i] = dec;
}
// return the Uint8Array
return resultUint8;
}
else {
// return the result as a string
return result;
}
}
hash(algo, data) {
if (data instanceof Uint8Array) {
var decoder = new TextDecoder();
var data = decoder.decode(data);
}
switch (algo) {
case 'whirlpool':
var result = this.WP().encSync(data, 'hex');
return result;
break;
case 'sha512':
// crypto-js kütüphanesinin SHA512 algoritmasını kullan
var result = CryptoJS.SHA512(data).toString(CryptoJS.enc.Hex);
return result;
break;
case 'sha256':
// crypto-js kütüphanesinin SHA256 algoritmasını kullan
var result = CryptoJS.SHA256(data).toString(CryptoJS.enc.Hex);
return result;
break;
// ...
default:
// Throw an error if the algorithm is not supported
throw new Error('Unsupported algorithm: ' + algo);
}
}
hash_uni8array(algo, data) {
switch (algo) {
case 'whirlpool':
var result = this.WP().encSync(data, 'hex');
// sonucu Uint8Array olarak dönüştür
var bytes = Buffer.from(result, 'hex');
var array = new Uint8Array(bytes.words.length * 4);
for (var i = 0; i < bytes.words.length; i++) {
array[i * 4] = (bytes.words[i] & 0xff000000) >>> 24;
array[i * 4 + 1] = (bytes.words[i] & 0x00ff0000) >>> 16;
array[i * 4 + 2] = (bytes.words[i] & 0x0000ff00) >>> 8;
array[i * 4 + 3] = (bytes.words[i] & 0x000000ff);
}
return array;
break;
case 'sha512':
// crypto-js kütüphanesinin SHA512 algoritmasını kullan
var result = CryptoJS.SHA512(data).toString(CryptoJS.enc.Hex);
// sonucu Uint8Array olarak dönüştür
var bytes = CryptoJS.enc.Hex.parse(result);
var array = new Uint8Array(bytes.words.length * 4);
for (var i = 0; i < bytes.words.length; i++) {
array[i * 4] = (bytes.words[i] & 0xff000000) >>> 24;
array[i * 4 + 1] = (bytes.words[i] & 0x00ff0000) >>> 16;
array[i * 4 + 2] = (bytes.words[i] & 0x0000ff00) >>> 8;
array[i * 4 + 3] = (bytes.words[i] & 0x000000ff);
}
return array;
break;
case 'sha256':
// crypto-js kütüphanesinin SHA256 algoritmasını kullan
var result = CryptoJS.SHA256(data).toString(CryptoJS.enc.Hex);
// sonucu Uint8Array olarak dönüştür
var bytes = CryptoJS.enc.Hex.parse(result);
var array = new Uint8Array(bytes.words.length * 4);
for (var i = 0; i < bytes.words.length; i++) {
array[i * 4] = (bytes.words[i] & 0xff000000) >>> 24;
array[i * 4 + 1] = (bytes.words[i] & 0x00ff0000) >>> 16;
array[i * 4 + 2] = (bytes.words[i] & 0x0000ff00) >>> 8;
array[i * 4 + 3] = (bytes.words[i] & 0x000000ff);
}
return array;
break;
// ...
default:
// Throw an error if the algorithm is not supported
throw new Error('Unsupported algorithm: ' + algo);
}
}
fix (x) {
// check if x is already a Uint8Array
if (x instanceof Uint8Array) {
return x; // no need to fix
}
// check if x is an object
if (Object.prototype.toString.call(x) === "[object Object]") {
// convert x to a Uint8Array using TextEncoder
var string = JSON.stringify(x); // convert x to a string
var encoder = new TextEncoder(); // create a TextEncoder object
var y = encoder.encode(string); // encode the string to a Uint8Array
return y; // return the fixed Uint8Array
}
// try to convert x to a Uint8Array
try {
var y = new Uint8Array(x); // this may throw an error if x is not convertible
return y; // return the fixed Uint8Array
}
catch (error) {
// x is not convertible to a Uint8Array
throw new Error("Cannot fix x: " + error.message); // throw an error with a message
}
}
openssl_random_pseudo_bytes(length) {
// geçerli bir uzunluk kontrolü yap
if (length < 1 || length > 65536) {
throw new Error("Invalid length");
}
// belirtilen uzunlukta bir Uint8Array oluştur
var bytes = new Uint8Array(length);
// diziyi rastgele baytlarla doldur
for (var i = 0; i < length; i++) {
// 0 ile 255 arasında rastgele bir tam sayı üret
var randomByte = Math.floor(Math.random() * 256);
// dizinin i. elemanına ata
bytes[i] = randomByte;
}
// diziyi döndür
return bytes;
}
convert (charCodes) {
// create an empty array to store the Uint8Arrays
var result = [];
// loop through the charCodes array
for (var i = 0; i < charCodes.length; i++) {
// get the current charCode
var charCode = charCodes[i];
// convert it to a Uint8Array using this.CharCodeToUint8Array()
var uint8 = this.CharCodeToUint8Array(charCode);
// push the Uint8Array to the result array
result.push(uint8);
}
// create a single Uint8Array from the result array
var resultLength = 0; // the total length of the result
for (var i = 0; i < result.length; i++) {
resultLength += result[i].length; // add the length of each Uint8Array
}
var resultUint8 = new Uint8Array(resultLength); // create a new Uint8Array with the total length
var offset = 0; // the current offset in the resultUint8
for (var i = 0; i < result.length; i++) {
resultUint8.set(result[i], offset); // copy each Uint8Array to the resultUint8
offset += result[i].length; // update the offset
}
// return the single Uint8Array
return resultUint8;
}
generateKeys(k, n) {
// Parametrelerin tiplerini kontrol edelim
if (typeof k === "string" && typeof n === "number") {
k = this.uint8ArrayToString(this.swapPairs(this.shiftRight(this.bitShiftRight(this.hex2bin(CryptoJS.SHA512(k).toString())))));
// Key değerlerini tutacak bir array tanımlayalım
let keys = [];
// n kadar round yapalım
for (let i = 0; i < n; i++) {
// k parametresi için formülleri uygulayalım
var t = this.hex2bin(this.Hex_Dont_Count (this.hash("sha512", this.md5(k))));
t = this.bitShiftLeft(t);
var f = this.Hex_Dont_Count (this.hash("sha512", f + t + this.convert(0x3f,0x6c,0x33)));
var l = this.Raw_hexrev (this.hex2bin(this.Hex_Dont_Count (this.hash("sha512", f))));
l = this.bitShiftRight(l);
var q = this.Raw_hexrev (this.hex2bin(this.Hex_Dont_Count (this.hash("whirlpool", this.uint8ArrayToString(this.hex2bin(this.E_hex_1 (f)))))));
q = this.bitShiftLeft(q);
var m = this.hex2bin(this.Hex_Dont_Count (this.hash("whirlpool", this.uint8ArrayToString(this.hex2bin(this.md5 (this.XOREncrypt(this.hex2bin(f), q)))))));
m = this.bitShiftRight(m);
var g = this.hashtoXcode(f);
var o = this.hex2bin(this.Hex_Dont_Count (this.hash("sha512", this.uint8ArrayToString(this.Raw_hexrev (this.StringTouint8Array(Math.exp (Math.pow (2, 2))) + this.XOREncrypt(l, k))))));
o = this.bitShiftLeft(o);
var p = this.hex2bin(this.Hex_Dont_Count (this.hash("sha512", this.uint8ArrayToString(this.hex2bin(this.hash("whirlpool", q))))));
p = this.bitShiftRight(p);
// Elde edilen değerleri bir array olarak tutalım
var key = [t, f, l, q, m, g, o, p];
// Key değerini arraye ekleyelim
keys.push(key);
// k parametresini CryptoJS SHA512 ile güncelleyelim
k = this.uint8ArrayToString(this.swapPairs(this.shiftLeft(this.bitShiftRight(this.hex2bin(CryptoJS.SHA512(k).toString())))));
}
// Key değerlerini döndürelim
return keys;
} else {
// Geçersiz parametre hatası verelim
console.error("Parametreler bir string ve bir sayı olmalıdır.");
}
}
Eadd(array, add) {
add = add % 256; // Toplama miktarını 256'nın modunu al
let result = Uint8Array.from(array, num => (num + add) & 255); // Her değeri topla ve 8 bitlik sınırı koru
return result;
}
Dadd(array, add) {
add = add % 256; // Toplama miktarını 256'nın modunu al
let result = Uint8Array.from(array, num => (num - add) & 255); // Her değerden çıkar ve 8 bitlik sınırı koru
return result;
}
EaddX(array) {
let result = new Uint8Array(array.length); // Sonuç için yeni bir Uint8Array oluştur
for (let i = 0; i < array.length; i++) {
// Her değeri sırası kadar topla ve 8 bitlik sınırı koru
result[i] = (array[i] + i) & 255;
}
return result;
}
DaddX(array) {
let result = new Uint8Array(array.length); // Sonuç için yeni bir Uint8Array oluştur
for (let i = 0; i < array.length; i++) {
// Her değerden sırasını çıkar ve 8 bitlik sınırı koru
result[i] = (array[i] - i) & 255;
}
return result;
}
swapPairs(array) {
// array'in uzunluğu tek ise son elemanı atla
let limit = array.length;
if (array.length % 2 == 1) {
limit = array.length - 1;
}
// array'in uzunluğunun çift veya tek olduğunu varsayalım
for (let i = 0; i < limit; i += 2) {
// i ve i+1. elemanları yer değiştir
let temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
}
return array;
}
shiftRight(array, times=1) {
// Check if the input is a valid Uint8Array
if (!(array instanceof Uint8Array)) {
throw new TypeError('Input must be a Uint8Array');
}
// Check if the times is a valid number
if (typeof times !== 'number' || isNaN(times) || times < 0) {
throw new TypeError('Times must be a positive number');
}
// Reduce the times by the array's length modulo
times = times % array.length;
// Create a new Uint8Array to store the output
let output = new Uint8Array(array.length);
// Loop through the array
for (let i = 0; i < array.length; i++) {
// Calculate the shifted index
let j = (i + times) % array.length;
// Assign the output element to the array element
output[j] = array[i];
}
// Return the output array
return output;
}
shiftLeft(array, times=1) {
// Check if the input is a valid Uint8Array
if (!(array instanceof Uint8Array)) {
throw new TypeError('Input must be a Uint8Array');
}
// Check if the times is a valid number
if (typeof times !== 'number' || isNaN(times) || times < 0) {
throw new TypeError('Times must be a positive number');
}
// Reduce the times by the array's length modulo
times = times % array.length;
// Create a new Uint8Array to store the output
let output = new Uint8Array(array.length);
// Loop through the array
for (let i = 0; i < array.length; i++) {
// Calculate the shifted index
let j = (i - times + array.length) % array.length;
// Assign the output element to the array element
output[j] = array[i];
}
// Return the output array
return output;
}
bitShiftRight(array) {
// array'in son elemanının en düşük bitini al
let lastBit = array[array.length - 1] & 1;
// array'in her elemanını sağa doğru bir bit kaydır
for (let i = 0; i < array.length; i++) {
// elemanın en yüksek bitini kaybetmemek için sakla
let highBit = array[i] & 128;
// elemanı sağa doğru bir bit kaydır
array[i] = array[i] >>> 1;
// elemanın en yüksek bitini geri koy
array[i] = array[i] | highBit;
}
// array'in ilk elemanının en yüksek bitini son elemanın en düşük biti yap
if (lastBit == 1) {
array[0] = array[0] | 128;
} else {
array[0] = array[0] & 127;
}
return array;
}
bitShiftLeft(array) {
// array'in ilk elemanının en yüksek bitini al
let highBit = array[0] & 128;