2020*/
2121
2222function base64ToUint8Array ( base64 ) {
23- // 将Base64字符串转换为二进制字符串
24- const binaryString = _atob ( base64 ) ;
25- // 将二进制字符串转换为Uint8Array
26- const len = binaryString . length ;
27- const bytes = new Uint8Array ( len ) ;
28- for ( let i = 0 ; i < len ; i ++ ) {
29- bytes [ i ] = binaryString . charCodeAt ( i ) ;
30- }
31- return bytes ;
23+ // 将Base64字符串转换为二进制字符串
24+ const binaryString = _atob ( base64 ) ;
25+ // 将二进制字符串转换为Uint8Array
26+ const len = binaryString . length ;
27+ const bytes = new Uint8Array ( len ) ;
28+ for ( let i = 0 ; i < len ; i ++ ) {
29+ bytes [ i ] = binaryString . charCodeAt ( i ) ;
30+ }
31+ return bytes ;
3232}
3333
3434function uint8ArrayToBase64 ( uint8Array ) {
35- return _btoa ( String . fromCharCode . apply ( null , uint8Array ) ) ;
35+ return _btoa ( String . fromCharCode . apply ( null , uint8Array ) ) ;
3636}
3737
3838// Read input from stdin
@@ -44,53 +44,53 @@ JavywriteOutput(Javyresult);
4444
4545// The main function.
4646function index ( input ) {
47- if ( input === "ERROR" ) {
47+ if ( input === "ERROR" ) {
4848 return "INCORRECT JSON" ;
4949 }
5050
51- if ( input . method == "NEXT" ) {
52- if ( input . inputType == "TEXT" ) {
53- let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
54- Abra . Input_Next ( input . input , input . mode , input . key , input . q , input . r ) ;
55- let Output = Abra . Output ( ) ;
56- if ( input . outputType == "UINT8" ) {
57- Output = uint8ArrayToBase64 ( Output ) ;
58- }
59- return Output ;
60- } else if ( input . inputType == "UINT8" ) {
61- let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
62- let UINT8In = base64ToUint8Array ( input . input ) ;
63- Abra . Input_Next ( UINT8In , input . mode , input . key , input . q , input . r ) ;
64- let Output = Abra . Output ( ) ;
65- if ( input . outputType == "UINT8" ) {
66- Output = uint8ArrayToBase64 ( Output ) ;
67- }
68- return Output ;
69- } else {
70- return "ERROR inputType" ;
51+ if ( input . method == "NEXT" ) {
52+ if ( input . inputType == "TEXT" ) {
53+ let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
54+ Abra . Input_Next ( input . input , input . mode , input . key , input . q , input . r ) ;
55+ let Output = Abra . Output ( ) ;
56+ if ( input . outputType == "UINT8" ) {
57+ Output = uint8ArrayToBase64 ( Output ) ;
58+ }
59+ return Output ;
60+ } else if ( input . inputType == "UINT8" ) {
61+ let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
62+ let UINT8In = base64ToUint8Array ( input . input ) ;
63+ Abra . Input_Next ( UINT8In , input . mode , input . key , input . q , input . r ) ;
64+ let Output = Abra . Output ( ) ;
65+ if ( input . outputType == "UINT8" ) {
66+ Output = uint8ArrayToBase64 ( Output ) ;
67+ }
68+ return Output ;
69+ } else {
70+ return "ERROR inputType" ;
7171 }
72- } else if ( input . method == "OLD" ) {
73- if ( input . inputType == "TEXT" ) {
74- let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
75- Abra . Input ( input . input , input . mode , input . key , input . q ) ;
76- let Output = Abra . Output ( ) ;
77- if ( input . outputType == "UINT8" ) {
78- Output = uint8ArrayToBase64 ( Output ) ;
79- }
80- return Output ;
81- } else if ( input . inputType == "UINT8" ) {
82- let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
83- let UINT8In = base64ToUint8Array ( input . input ) ;
84- Abra . Input ( UINT8In , input . mode , input . key , input . q ) ;
85- let Output = Abra . Output ( ) ;
86- if ( input . outputType == "UINT8" ) {
87- Output = uint8ArrayToBase64 ( Output ) ;
88- }
89- return Output ;
90- } else {
91- return "ERROR inputType" ;
72+ } else if ( input . method == "OLD" ) {
73+ if ( input . inputType == "TEXT" ) {
74+ let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
75+ Abra . Input ( input . input , input . mode , input . key , input . q ) ;
76+ let Output = Abra . Output ( ) ;
77+ if ( input . outputType == "UINT8" ) {
78+ Output = uint8ArrayToBase64 ( Output ) ;
79+ }
80+ return Output ;
81+ } else if ( input . inputType == "UINT8" ) {
82+ let Abra = new Abracadabra ( input . inputType , input . outputType ) ;
83+ let UINT8In = base64ToUint8Array ( input . input ) ;
84+ Abra . Input ( UINT8In , input . mode , input . key , input . q ) ;
85+ let Output = Abra . Output ( ) ;
86+ if ( input . outputType == "UINT8" ) {
87+ Output = uint8ArrayToBase64 ( Output ) ;
88+ }
89+ return Output ;
90+ } else {
91+ return "ERROR inputType" ;
9292 }
93- } else {
93+ } else {
9494 return "ERROR method" ;
9595 }
9696}
@@ -122,12 +122,12 @@ function JavyreadInput() {
122122 context . bufferOffset += chunk . length ;
123123 return context ;
124124 } ,
125- { bufferOffset : 0 , finalBuffer : new Uint8Array ( totalBytes ) } ,
125+ { bufferOffset : 0 , finalBuffer : new Uint8Array ( totalBytes ) }
126126 ) ;
127127
128128 const InputDecoded = new TextDecoder ( ) . decode ( finalBuffer ) ;
129129 try {
130- return JSON . parse ( InputDecoded ) ; ;
130+ return JSON . parse ( InputDecoded ) ;
131131 } catch {
132132 return "ERROR" ;
133133 }
@@ -140,4 +140,4 @@ function JavywriteOutput(output) {
140140 // Stdout file descriptor
141141 const fd = 1 ;
142142 Javy . IO . writeSync ( fd , buffer ) ;
143- }
143+ }
0 commit comments