20
20
*/
21
21
22
22
function 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 ;
32
32
}
33
33
34
34
function uint8ArrayToBase64 ( uint8Array ) {
35
- return _btoa ( String . fromCharCode . apply ( null , uint8Array ) ) ;
35
+ return _btoa ( String . fromCharCode . apply ( null , uint8Array ) ) ;
36
36
}
37
37
38
38
// Read input from stdin
@@ -44,53 +44,53 @@ JavywriteOutput(Javyresult);
44
44
45
45
// The main function.
46
46
function index ( input ) {
47
- if ( input === "ERROR" ) {
47
+ if ( input === "ERROR" ) {
48
48
return "INCORRECT JSON" ;
49
49
}
50
50
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" ;
71
71
}
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" ;
92
92
}
93
- } else {
93
+ } else {
94
94
return "ERROR method" ;
95
95
}
96
96
}
@@ -122,12 +122,12 @@ function JavyreadInput() {
122
122
context . bufferOffset += chunk . length ;
123
123
return context ;
124
124
} ,
125
- { bufferOffset : 0 , finalBuffer : new Uint8Array ( totalBytes ) } ,
125
+ { bufferOffset : 0 , finalBuffer : new Uint8Array ( totalBytes ) }
126
126
) ;
127
127
128
128
const InputDecoded = new TextDecoder ( ) . decode ( finalBuffer ) ;
129
129
try {
130
- return JSON . parse ( InputDecoded ) ; ;
130
+ return JSON . parse ( InputDecoded ) ;
131
131
} catch {
132
132
return "ERROR" ;
133
133
}
@@ -140,4 +140,4 @@ function JavywriteOutput(output) {
140
140
// Stdout file descriptor
141
141
const fd = 1 ;
142
142
Javy . IO . writeSync ( fd , buffer ) ;
143
- }
143
+ }
0 commit comments