cyberchef 9.38.1 → 9.38.5
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.
- package/package.json +36 -36
- package/src/core/config/OperationConfig.json +38 -16
- package/src/core/lib/Base64.mjs +44 -17
- package/src/core/lib/Binary.mjs +14 -12
- package/src/core/operations/FromBase64.mjs +24 -19
- package/src/core/operations/Substitute.mjs +5 -5
- package/src/core/operations/ToUpperCase.mjs +22 -16
- package/tests/operations/tests/Magic.mjs +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cyberchef",
|
|
3
|
-
"version": "9.38.
|
|
3
|
+
"version": "9.38.5",
|
|
4
4
|
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
|
|
5
5
|
"author": "n1474335 <n1474335@gmail.com>",
|
|
6
6
|
"homepage": "https://gchq.github.io/CyberChef",
|
|
@@ -39,26 +39,27 @@
|
|
|
39
39
|
"node >= 16"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/eslint-parser": "^7.
|
|
44
|
-
"@babel/plugin-syntax-import-assertions": "^7.
|
|
45
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
46
|
-
"@babel/preset-env": "^7.
|
|
47
|
-
"@babel/runtime": "^7.
|
|
48
|
-
"autoprefixer": "^10.4.
|
|
49
|
-
"babel-loader": "^8.2.
|
|
42
|
+
"@babel/core": "^7.18.2",
|
|
43
|
+
"@babel/eslint-parser": "^7.18.2",
|
|
44
|
+
"@babel/plugin-syntax-import-assertions": "^7.17.12",
|
|
45
|
+
"@babel/plugin-transform-runtime": "^7.18.2",
|
|
46
|
+
"@babel/preset-env": "^7.18.2",
|
|
47
|
+
"@babel/runtime": "^7.18.3",
|
|
48
|
+
"autoprefixer": "^10.4.7",
|
|
49
|
+
"babel-loader": "^8.2.5",
|
|
50
50
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
51
|
+
"babel-plugin-transform-builtin-extend": "1.1.2",
|
|
51
52
|
"chromedriver": "^101.0.0",
|
|
52
|
-
"cli-progress": "^3.
|
|
53
|
+
"cli-progress": "^3.11.1",
|
|
53
54
|
"colors": "^1.4.0",
|
|
54
|
-
"copy-webpack-plugin": "^
|
|
55
|
-
"core-js": "^3.
|
|
55
|
+
"copy-webpack-plugin": "^11.0.0",
|
|
56
|
+
"core-js": "^3.22.8",
|
|
56
57
|
"css-loader": "6.7.1",
|
|
57
|
-
"eslint": "^8.
|
|
58
|
-
"grunt": "^1.
|
|
58
|
+
"eslint": "^8.16.0",
|
|
59
|
+
"grunt": "^1.5.3",
|
|
59
60
|
"grunt-chmod": "~1.1.1",
|
|
60
61
|
"grunt-concurrent": "^3.0.0",
|
|
61
|
-
"grunt-contrib-clean": "~2.0.
|
|
62
|
+
"grunt-contrib-clean": "~2.0.1",
|
|
62
63
|
"grunt-contrib-connect": "^3.0.0",
|
|
63
64
|
"grunt-contrib-copy": "~1.0.0",
|
|
64
65
|
"grunt-contrib-watch": "^1.1.0",
|
|
@@ -67,29 +68,28 @@
|
|
|
67
68
|
"grunt-webpack": "^5.0.0",
|
|
68
69
|
"grunt-zip": "^0.18.2",
|
|
69
70
|
"html-webpack-plugin": "^5.5.0",
|
|
70
|
-
"imports-loader": "^
|
|
71
|
+
"imports-loader": "^4.0.0",
|
|
71
72
|
"mini-css-extract-plugin": "2.6.0",
|
|
72
73
|
"modify-source-webpack-plugin": "^3.0.0",
|
|
73
|
-
"nightwatch": "^2.
|
|
74
|
-
"postcss": "^8.4.
|
|
74
|
+
"nightwatch": "^2.1.7",
|
|
75
|
+
"postcss": "^8.4.14",
|
|
75
76
|
"postcss-css-variables": "^0.18.0",
|
|
76
77
|
"postcss-import": "^14.1.0",
|
|
77
|
-
"postcss-loader": "^
|
|
78
|
-
"prompt": "^1.
|
|
79
|
-
"sass-loader": "^
|
|
78
|
+
"postcss-loader": "^7.0.0",
|
|
79
|
+
"prompt": "^1.3.0",
|
|
80
|
+
"sass-loader": "^13.0.0",
|
|
80
81
|
"sitemap": "^7.1.1",
|
|
81
|
-
"terser": "^5.
|
|
82
|
-
"webpack": "^5.
|
|
82
|
+
"terser": "^5.14.0",
|
|
83
|
+
"webpack": "^5.73.0",
|
|
83
84
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
84
|
-
"webpack-dev-server": "4.
|
|
85
|
+
"webpack-dev-server": "4.9.1",
|
|
85
86
|
"webpack-node-externals": "^3.0.0",
|
|
86
87
|
"worker-loader": "^3.0.8"
|
|
87
88
|
},
|
|
88
89
|
"dependencies": {
|
|
89
90
|
"@babel/polyfill": "^7.12.1",
|
|
90
91
|
"arrive": "^2.4.1",
|
|
91
|
-
"avsc": "^5.7.
|
|
92
|
-
"babel-plugin-transform-builtin-extend": "1.1.2",
|
|
92
|
+
"avsc": "^5.7.4",
|
|
93
93
|
"bcryptjs": "^2.4.3",
|
|
94
94
|
"bignumber.js": "^9.0.2",
|
|
95
95
|
"blakejs": "^1.2.1",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"bootstrap-colorpicker": "^3.4.0",
|
|
98
98
|
"bootstrap-material-design": "^4.1.3",
|
|
99
99
|
"browserify-zlib": "^0.2.0",
|
|
100
|
-
"bson": "^4.6.
|
|
100
|
+
"bson": "^4.6.4",
|
|
101
101
|
"buffer": "^6.0.3",
|
|
102
102
|
"cbor": "8.1.0",
|
|
103
103
|
"chi-squared": "^1.1.0",
|
|
@@ -106,9 +106,9 @@
|
|
|
106
106
|
"crypto-browserify": "^3.12.0",
|
|
107
107
|
"crypto-js": "^4.1.1",
|
|
108
108
|
"ctph.js": "0.0.5",
|
|
109
|
-
"d3": "7.
|
|
109
|
+
"d3": "7.4.4",
|
|
110
110
|
"d3-hexbin": "^0.2.2",
|
|
111
|
-
"diff": "^5.
|
|
111
|
+
"diff": "^5.1.0",
|
|
112
112
|
"es6-promisify": "^7.0.0",
|
|
113
113
|
"escodegen": "^2.0.0",
|
|
114
114
|
"esprima": "^4.0.1",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"file-saver": "^2.0.5",
|
|
117
117
|
"flat": "^5.0.2",
|
|
118
118
|
"geodesy": "1.1.3",
|
|
119
|
-
"highlight.js": "^11.5.
|
|
119
|
+
"highlight.js": "^11.5.1",
|
|
120
120
|
"jimp": "^0.16.1",
|
|
121
121
|
"jquery": "3.6.0",
|
|
122
122
|
"js-crc": "^0.2.0",
|
|
@@ -125,28 +125,28 @@
|
|
|
125
125
|
"jsonpath": "^1.1.1",
|
|
126
126
|
"jsonwebtoken": "^8.5.1",
|
|
127
127
|
"jsqr": "^1.4.0",
|
|
128
|
-
"jsrsasign": "^10.5.
|
|
128
|
+
"jsrsasign": "^10.5.23",
|
|
129
129
|
"kbpgp": "2.1.15",
|
|
130
130
|
"libbzip2-wasm": "0.0.4",
|
|
131
131
|
"libyara-wasm": "^1.1.0",
|
|
132
132
|
"lodash": "^4.17.21",
|
|
133
133
|
"loglevel": "^1.8.0",
|
|
134
134
|
"loglevel-message-prefix": "^3.0.0",
|
|
135
|
-
"markdown-it": "^
|
|
136
|
-
"moment": "^2.29.
|
|
135
|
+
"markdown-it": "^13.0.1",
|
|
136
|
+
"moment": "^2.29.3",
|
|
137
137
|
"moment-timezone": "^0.5.34",
|
|
138
138
|
"ngeohash": "^0.6.3",
|
|
139
|
-
"node-forge": "^1.3.
|
|
139
|
+
"node-forge": "^1.3.1",
|
|
140
140
|
"node-md6": "^0.1.0",
|
|
141
141
|
"node-sass": "^7.0.1",
|
|
142
142
|
"nodom": "^2.4.0",
|
|
143
|
-
"notepack.io": "^
|
|
143
|
+
"notepack.io": "^3.0.1",
|
|
144
144
|
"nwmatcher": "^1.4.4",
|
|
145
145
|
"otp": "0.1.3",
|
|
146
146
|
"path": "^0.12.7",
|
|
147
147
|
"popper.js": "^1.16.1",
|
|
148
148
|
"process": "^0.11.10",
|
|
149
|
-
"protobufjs": "^6.11.
|
|
149
|
+
"protobufjs": "^6.11.3",
|
|
150
150
|
"qr-image": "^3.2.0",
|
|
151
151
|
"scryptsy": "^2.1.0",
|
|
152
152
|
"snackbarjs": "^1.1.0",
|
|
@@ -5791,6 +5791,11 @@
|
|
|
5791
5791
|
"name": "Remove non-alphabet chars",
|
|
5792
5792
|
"type": "boolean",
|
|
5793
5793
|
"value": true
|
|
5794
|
+
},
|
|
5795
|
+
{
|
|
5796
|
+
"name": "Strict mode",
|
|
5797
|
+
"type": "boolean",
|
|
5798
|
+
"value": false
|
|
5794
5799
|
}
|
|
5795
5800
|
],
|
|
5796
5801
|
"checks": [
|
|
@@ -5799,7 +5804,8 @@
|
|
|
5799
5804
|
"flags": "i",
|
|
5800
5805
|
"args": [
|
|
5801
5806
|
"A-Za-z0-9+/=",
|
|
5802
|
-
true
|
|
5807
|
+
true,
|
|
5808
|
+
false
|
|
5803
5809
|
]
|
|
5804
5810
|
},
|
|
5805
5811
|
{
|
|
@@ -5807,7 +5813,8 @@
|
|
|
5807
5813
|
"flags": "i",
|
|
5808
5814
|
"args": [
|
|
5809
5815
|
"A-Za-z0-9-_",
|
|
5810
|
-
true
|
|
5816
|
+
true,
|
|
5817
|
+
false
|
|
5811
5818
|
]
|
|
5812
5819
|
},
|
|
5813
5820
|
{
|
|
@@ -5815,7 +5822,8 @@
|
|
|
5815
5822
|
"flags": "i",
|
|
5816
5823
|
"args": [
|
|
5817
5824
|
"A-Za-z0-9+\\-=",
|
|
5818
|
-
true
|
|
5825
|
+
true,
|
|
5826
|
+
false
|
|
5819
5827
|
]
|
|
5820
5828
|
},
|
|
5821
5829
|
{
|
|
@@ -5823,7 +5831,8 @@
|
|
|
5823
5831
|
"flags": "i",
|
|
5824
5832
|
"args": [
|
|
5825
5833
|
"./0-9A-Za-z=",
|
|
5826
|
-
true
|
|
5834
|
+
true,
|
|
5835
|
+
false
|
|
5827
5836
|
]
|
|
5828
5837
|
},
|
|
5829
5838
|
{
|
|
@@ -5831,7 +5840,8 @@
|
|
|
5831
5840
|
"flags": "i",
|
|
5832
5841
|
"args": [
|
|
5833
5842
|
"A-Za-z0-9_.",
|
|
5834
|
-
true
|
|
5843
|
+
true,
|
|
5844
|
+
false
|
|
5835
5845
|
]
|
|
5836
5846
|
},
|
|
5837
5847
|
{
|
|
@@ -5839,7 +5849,8 @@
|
|
|
5839
5849
|
"flags": "i",
|
|
5840
5850
|
"args": [
|
|
5841
5851
|
"A-Za-z0-9._-",
|
|
5842
|
-
true
|
|
5852
|
+
true,
|
|
5853
|
+
false
|
|
5843
5854
|
]
|
|
5844
5855
|
},
|
|
5845
5856
|
{
|
|
@@ -5847,7 +5858,8 @@
|
|
|
5847
5858
|
"flags": "i",
|
|
5848
5859
|
"args": [
|
|
5849
5860
|
"0-9a-zA-Z+/=",
|
|
5850
|
-
true
|
|
5861
|
+
true,
|
|
5862
|
+
false
|
|
5851
5863
|
]
|
|
5852
5864
|
},
|
|
5853
5865
|
{
|
|
@@ -5855,7 +5867,8 @@
|
|
|
5855
5867
|
"flags": "i",
|
|
5856
5868
|
"args": [
|
|
5857
5869
|
"0-9A-Za-z+/=",
|
|
5858
|
-
true
|
|
5870
|
+
true,
|
|
5871
|
+
false
|
|
5859
5872
|
]
|
|
5860
5873
|
},
|
|
5861
5874
|
{
|
|
@@ -5863,6 +5876,7 @@
|
|
|
5863
5876
|
"flags": "",
|
|
5864
5877
|
"args": [
|
|
5865
5878
|
" -_",
|
|
5879
|
+
false,
|
|
5866
5880
|
false
|
|
5867
5881
|
]
|
|
5868
5882
|
},
|
|
@@ -5871,7 +5885,8 @@
|
|
|
5871
5885
|
"flags": "i",
|
|
5872
5886
|
"args": [
|
|
5873
5887
|
"+\\-0-9A-Za-z",
|
|
5874
|
-
true
|
|
5888
|
+
true,
|
|
5889
|
+
false
|
|
5875
5890
|
]
|
|
5876
5891
|
},
|
|
5877
5892
|
{
|
|
@@ -5879,7 +5894,8 @@
|
|
|
5879
5894
|
"flags": "",
|
|
5880
5895
|
"args": [
|
|
5881
5896
|
"!-,-0-689@A-NP-VX-Z[`a-fh-mp-r",
|
|
5882
|
-
true
|
|
5897
|
+
true,
|
|
5898
|
+
false
|
|
5883
5899
|
]
|
|
5884
5900
|
},
|
|
5885
5901
|
{
|
|
@@ -5887,7 +5903,8 @@
|
|
|
5887
5903
|
"flags": "i",
|
|
5888
5904
|
"args": [
|
|
5889
5905
|
"N-ZA-Mn-za-m0-9+/=",
|
|
5890
|
-
true
|
|
5906
|
+
true,
|
|
5907
|
+
false
|
|
5891
5908
|
]
|
|
5892
5909
|
},
|
|
5893
5910
|
{
|
|
@@ -5895,7 +5912,8 @@
|
|
|
5895
5912
|
"flags": "i",
|
|
5896
5913
|
"args": [
|
|
5897
5914
|
"./0-9A-Za-z",
|
|
5898
|
-
true
|
|
5915
|
+
true,
|
|
5916
|
+
false
|
|
5899
5917
|
]
|
|
5900
5918
|
},
|
|
5901
5919
|
{
|
|
@@ -5903,7 +5921,8 @@
|
|
|
5903
5921
|
"flags": "i",
|
|
5904
5922
|
"args": [
|
|
5905
5923
|
"/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC",
|
|
5906
|
-
true
|
|
5924
|
+
true,
|
|
5925
|
+
false
|
|
5907
5926
|
]
|
|
5908
5927
|
},
|
|
5909
5928
|
{
|
|
@@ -5911,7 +5930,8 @@
|
|
|
5911
5930
|
"flags": "i",
|
|
5912
5931
|
"args": [
|
|
5913
5932
|
"3GHIJKLMNOPQRSTUb=cdefghijklmnopWXYZ/12+406789VaqrstuvwxyzABCDEF5",
|
|
5914
|
-
true
|
|
5933
|
+
true,
|
|
5934
|
+
false
|
|
5915
5935
|
]
|
|
5916
5936
|
},
|
|
5917
5937
|
{
|
|
@@ -5919,7 +5939,8 @@
|
|
|
5919
5939
|
"flags": "i",
|
|
5920
5940
|
"args": [
|
|
5921
5941
|
"ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2",
|
|
5922
|
-
true
|
|
5942
|
+
true,
|
|
5943
|
+
false
|
|
5923
5944
|
]
|
|
5924
5945
|
},
|
|
5925
5946
|
{
|
|
@@ -5927,7 +5948,8 @@
|
|
|
5927
5948
|
"flags": "i",
|
|
5928
5949
|
"args": [
|
|
5929
5950
|
"HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5",
|
|
5930
|
-
true
|
|
5951
|
+
true,
|
|
5952
|
+
false
|
|
5931
5953
|
]
|
|
5932
5954
|
}
|
|
5933
5955
|
]
|
package/src/core/lib/Base64.mjs
CHANGED
|
@@ -82,47 +82,74 @@ export function toBase64(data, alphabet="A-Za-z0-9+/=") {
|
|
|
82
82
|
* // returns [72, 101, 108, 108, 111]
|
|
83
83
|
* fromBase64("SGVsbG8=", null, "byteArray");
|
|
84
84
|
*/
|
|
85
|
-
export function fromBase64(data, alphabet="A-Za-z0-9+/=", returnType="string", removeNonAlphChars=true) {
|
|
85
|
+
export function fromBase64(data, alphabet="A-Za-z0-9+/=", returnType="string", removeNonAlphChars=true, strictMode=false) {
|
|
86
86
|
if (!data) {
|
|
87
87
|
return returnType === "string" ? "" : [];
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
alphabet = alphabet || "A-Za-z0-9+/=";
|
|
91
91
|
alphabet = Utils.expandAlphRange(alphabet).join("");
|
|
92
|
+
|
|
93
|
+
// Confirm alphabet is a valid length
|
|
92
94
|
if (alphabet.length !== 64 && alphabet.length !== 65) { // Allow for padding
|
|
93
|
-
throw new OperationError(`
|
|
95
|
+
throw new OperationError(`Error: Base64 alphabet should be 64 characters long, or 65 with a padding character. Found ${alphabet.length}: ${alphabet}`);
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
97
|
-
let chr1, chr2, chr3,
|
|
98
|
-
enc1, enc2, enc3, enc4,
|
|
99
|
-
i = 0;
|
|
100
|
-
|
|
98
|
+
// Remove non-alphabet characters
|
|
101
99
|
if (removeNonAlphChars) {
|
|
102
100
|
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
|
|
103
101
|
data = data.replace(re, "");
|
|
104
102
|
}
|
|
105
103
|
|
|
104
|
+
if (strictMode) {
|
|
105
|
+
// Check for incorrect lengths (even without padding)
|
|
106
|
+
if (data.length % 4 === 1) {
|
|
107
|
+
throw new OperationError(`Error: Invalid Base64 input length (${data.length}). Cannot be 4n+1, even without padding chars.`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (alphabet.length === 65) { // Padding character included
|
|
111
|
+
const pad = alphabet.charAt(64);
|
|
112
|
+
const padPos = data.indexOf(pad);
|
|
113
|
+
if (padPos >= 0) {
|
|
114
|
+
// Check that the padding character is only used at the end and maximum of twice
|
|
115
|
+
if (padPos < data.length - 2 || data.charAt(data.length - 1) !== pad) {
|
|
116
|
+
throw new OperationError(`Error: Base64 padding character (${pad}) not used in the correct place.`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Check that input is padded to the correct length
|
|
120
|
+
if (data.length % 4 !== 0) {
|
|
121
|
+
throw new OperationError("Error: Base64 not padded to a multiple of 4.");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const output = [];
|
|
128
|
+
let chr1, chr2, chr3,
|
|
129
|
+
enc1, enc2, enc3, enc4,
|
|
130
|
+
i = 0;
|
|
131
|
+
|
|
106
132
|
while (i < data.length) {
|
|
107
133
|
enc1 = alphabet.indexOf(data.charAt(i++));
|
|
108
|
-
enc2 = alphabet.indexOf(data.charAt(i++)
|
|
109
|
-
enc3 = alphabet.indexOf(data.charAt(i++)
|
|
110
|
-
enc4 = alphabet.indexOf(data.charAt(i++)
|
|
134
|
+
enc2 = alphabet.indexOf(data.charAt(i++));
|
|
135
|
+
enc3 = alphabet.indexOf(data.charAt(i++));
|
|
136
|
+
enc4 = alphabet.indexOf(data.charAt(i++));
|
|
111
137
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
138
|
+
if (strictMode && (enc1 < 0 || enc2 < 0 || enc3 < 0 || enc4 < 0)) {
|
|
139
|
+
throw new OperationError("Error: Base64 input contains non-alphabet char(s)");
|
|
140
|
+
}
|
|
115
141
|
|
|
116
142
|
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
117
143
|
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
118
144
|
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
119
145
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
146
|
+
if (chr1 < 256) {
|
|
147
|
+
output.push(chr1);
|
|
148
|
+
}
|
|
149
|
+
if (chr2 < 256 && enc3 !== 64) {
|
|
123
150
|
output.push(chr2);
|
|
124
151
|
}
|
|
125
|
-
if (enc4 !== 64) {
|
|
152
|
+
if (chr3 < 256 && enc4 !== 64) {
|
|
126
153
|
output.push(chr3);
|
|
127
154
|
}
|
|
128
155
|
}
|
package/src/core/lib/Binary.mjs
CHANGED
|
@@ -19,31 +19,33 @@ import OperationError from "../errors/OperationError.mjs";
|
|
|
19
19
|
* @returns {string}
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
-
* // returns "
|
|
22
|
+
* // returns "00001010 00010100 00011110"
|
|
23
23
|
* toBinary([10,20,30]);
|
|
24
24
|
*
|
|
25
|
-
* // returns "
|
|
26
|
-
* toBinary([10,20,30], "
|
|
25
|
+
* // returns "00001010:00010100:00011110"
|
|
26
|
+
* toBinary([10,20,30], "Colon");
|
|
27
|
+
*
|
|
28
|
+
* // returns "1010:10100:11110"
|
|
29
|
+
* toBinary([10,20,30], "Colon", 0);
|
|
27
30
|
*/
|
|
28
31
|
export function toBinary(data, delim="Space", padding=8) {
|
|
32
|
+
if (data === undefined || data === null)
|
|
33
|
+
throw new OperationError("Unable to convert to binary: Empty input data enocuntered");
|
|
34
|
+
|
|
29
35
|
delim = Utils.charRep(delim);
|
|
30
36
|
let output = "";
|
|
31
37
|
|
|
32
38
|
if (data.length) { // array
|
|
33
39
|
for (let i = 0; i < data.length; i++) {
|
|
34
|
-
output += data[i].toString(2).padStart(padding, "0")
|
|
40
|
+
output += data[i].toString(2).padStart(padding, "0");
|
|
41
|
+
if (i !== data.length - 1) output += delim;
|
|
35
42
|
}
|
|
36
43
|
} else if (typeof data === "number") { // Single value
|
|
37
44
|
return data.toString(2).padStart(padding, "0");
|
|
38
45
|
} else {
|
|
39
46
|
return "";
|
|
40
47
|
}
|
|
41
|
-
|
|
42
|
-
if (delim.length) {
|
|
43
|
-
return output.slice(0, -delim.length);
|
|
44
|
-
} else {
|
|
45
|
-
return output;
|
|
46
|
-
}
|
|
48
|
+
return output;
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
|
|
@@ -57,10 +59,10 @@ export function toBinary(data, delim="Space", padding=8) {
|
|
|
57
59
|
*
|
|
58
60
|
* @example
|
|
59
61
|
* // returns [10,20,30]
|
|
60
|
-
* fromBinary("
|
|
62
|
+
* fromBinary("00001010 00010100 00011110");
|
|
61
63
|
*
|
|
62
64
|
* // returns [10,20,30]
|
|
63
|
-
* fromBinary("
|
|
65
|
+
* fromBinary("00001010:00010100:00011110", "Colon");
|
|
64
66
|
*/
|
|
65
67
|
export function fromBinary(data, delim="Space", byteLen=8) {
|
|
66
68
|
if (byteLen < 1 || Math.round(byteLen) !== byteLen)
|
|
@@ -34,93 +34,98 @@ class FromBase64 extends Operation {
|
|
|
34
34
|
name: "Remove non-alphabet chars",
|
|
35
35
|
type: "boolean",
|
|
36
36
|
value: true
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "Strict mode",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
value: false
|
|
37
42
|
}
|
|
38
43
|
];
|
|
39
44
|
this.checks = [
|
|
40
45
|
{
|
|
41
46
|
pattern: "^\\s*(?:[A-Z\\d+/]{4})+(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$",
|
|
42
47
|
flags: "i",
|
|
43
|
-
args: ["A-Za-z0-9+/=", true]
|
|
48
|
+
args: ["A-Za-z0-9+/=", true, false]
|
|
44
49
|
},
|
|
45
50
|
{
|
|
46
51
|
pattern: "^\\s*[A-Z\\d\\-_]{20,}\\s*$",
|
|
47
52
|
flags: "i",
|
|
48
|
-
args: ["A-Za-z0-9-_", true]
|
|
53
|
+
args: ["A-Za-z0-9-_", true, false]
|
|
49
54
|
},
|
|
50
55
|
{
|
|
51
56
|
pattern: "^\\s*(?:[A-Z\\d+\\-]{4}){5,}(?:[A-Z\\d+\\-]{2}==|[A-Z\\d+\\-]{3}=)?\\s*$",
|
|
52
57
|
flags: "i",
|
|
53
|
-
args: ["A-Za-z0-9+\\-=", true]
|
|
58
|
+
args: ["A-Za-z0-9+\\-=", true, false]
|
|
54
59
|
},
|
|
55
60
|
{
|
|
56
61
|
pattern: "^\\s*(?:[A-Z\\d./]{4}){5,}(?:[A-Z\\d./]{2}==|[A-Z\\d./]{3}=)?\\s*$",
|
|
57
62
|
flags: "i",
|
|
58
|
-
args: ["./0-9A-Za-z=", true]
|
|
63
|
+
args: ["./0-9A-Za-z=", true, false]
|
|
59
64
|
},
|
|
60
65
|
{
|
|
61
66
|
pattern: "^\\s*[A-Z\\d_.]{20,}\\s*$",
|
|
62
67
|
flags: "i",
|
|
63
|
-
args: ["A-Za-z0-9_.", true]
|
|
68
|
+
args: ["A-Za-z0-9_.", true, false]
|
|
64
69
|
},
|
|
65
70
|
{
|
|
66
71
|
pattern: "^\\s*(?:[A-Z\\d._]{4}){5,}(?:[A-Z\\d._]{2}--|[A-Z\\d._]{3}-)?\\s*$",
|
|
67
72
|
flags: "i",
|
|
68
|
-
args: ["A-Za-z0-9._-", true]
|
|
73
|
+
args: ["A-Za-z0-9._-", true, false]
|
|
69
74
|
},
|
|
70
75
|
{
|
|
71
76
|
pattern: "^\\s*(?:[A-Z\\d+/]{4}){5,}(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$",
|
|
72
77
|
flags: "i",
|
|
73
|
-
args: ["0-9a-zA-Z+/=", true]
|
|
78
|
+
args: ["0-9a-zA-Z+/=", true, false]
|
|
74
79
|
},
|
|
75
80
|
{
|
|
76
81
|
pattern: "^\\s*(?:[A-Z\\d+/]{4}){5,}(?:[A-Z\\d+/]{2}==|[A-Z\\d+/]{3}=)?\\s*$",
|
|
77
82
|
flags: "i",
|
|
78
|
-
args: ["0-9A-Za-z+/=", true]
|
|
83
|
+
args: ["0-9A-Za-z+/=", true, false]
|
|
79
84
|
},
|
|
80
85
|
{
|
|
81
86
|
pattern: "^[ !\"#$%&'()*+,\\-./\\d:;<=>?@A-Z[\\\\\\]^_]{20,}$",
|
|
82
87
|
flags: "",
|
|
83
|
-
args: [" -_", false]
|
|
88
|
+
args: [" -_", false, false]
|
|
84
89
|
},
|
|
85
90
|
{
|
|
86
91
|
pattern: "^\\s*[A-Z\\d+\\-]{20,}\\s*$",
|
|
87
92
|
flags: "i",
|
|
88
|
-
args: ["+\\-0-9A-Za-z", true]
|
|
93
|
+
args: ["+\\-0-9A-Za-z", true, false]
|
|
89
94
|
},
|
|
90
95
|
{
|
|
91
96
|
pattern: "^\\s*[!\"#$%&'()*+,\\-0-689@A-NP-VX-Z[`a-fh-mp-r]{20,}\\s*$",
|
|
92
97
|
flags: "",
|
|
93
|
-
args: ["!-,-0-689@A-NP-VX-Z[`a-fh-mp-r", true]
|
|
98
|
+
args: ["!-,-0-689@A-NP-VX-Z[`a-fh-mp-r", true, false]
|
|
94
99
|
},
|
|
95
100
|
{
|
|
96
101
|
pattern: "^\\s*(?:[N-ZA-M\\d+/]{4}){5,}(?:[N-ZA-M\\d+/]{2}==|[N-ZA-M\\d+/]{3}=)?\\s*$",
|
|
97
102
|
flags: "i",
|
|
98
|
-
args: ["N-ZA-Mn-za-m0-9+/=", true]
|
|
103
|
+
args: ["N-ZA-Mn-za-m0-9+/=", true, false]
|
|
99
104
|
},
|
|
100
105
|
{
|
|
101
106
|
pattern: "^\\s*[A-Z\\d./]{20,}\\s*$",
|
|
102
107
|
flags: "i",
|
|
103
|
-
args: ["./0-9A-Za-z", true]
|
|
108
|
+
args: ["./0-9A-Za-z", true, false]
|
|
104
109
|
},
|
|
105
110
|
{
|
|
106
111
|
pattern: "^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}CC|[A-Z=\\d\\+/]{3}C)?\\s*$",
|
|
107
112
|
flags: "i",
|
|
108
|
-
args: ["/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC", true]
|
|
113
|
+
args: ["/128GhIoPQROSTeUbADfgHijKLM+n0pFWXY456xyzB7=39VaqrstJklmNuZvwcdEC", true, false]
|
|
109
114
|
},
|
|
110
115
|
{
|
|
111
116
|
pattern: "^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}55|[A-Z=\\d\\+/]{3}5)?\\s*$",
|
|
112
117
|
flags: "i",
|
|
113
|
-
args: ["3GHIJKLMNOPQRSTUb=cdefghijklmnopWXYZ/12+406789VaqrstuvwxyzABCDEF5", true]
|
|
118
|
+
args: ["3GHIJKLMNOPQRSTUb=cdefghijklmnopWXYZ/12+406789VaqrstuvwxyzABCDEF5", true, false]
|
|
114
119
|
},
|
|
115
120
|
{
|
|
116
121
|
pattern: "^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}22|[A-Z=\\d\\+/]{3}2)?\\s*$",
|
|
117
122
|
flags: "i",
|
|
118
|
-
args: ["ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2", true]
|
|
123
|
+
args: ["ZKj9n+yf0wDVX1s/5YbdxSo=ILaUpPBCHg8uvNO4klm6iJGhQ7eFrWczAMEq3RTt2", true, false]
|
|
119
124
|
},
|
|
120
125
|
{
|
|
121
126
|
pattern: "^\\s*(?:[A-Z=\\d\\+/]{4}){5,}(?:[A-Z=\\d\\+/]{2}55|[A-Z=\\d\\+/]{3}5)?\\s*$",
|
|
122
127
|
flags: "i",
|
|
123
|
-
args: ["HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5", true]
|
|
128
|
+
args: ["HNO4klm6ij9n+J2hyf0gzA8uvwDEq3X1Q7ZKeFrWcVTts/MRGYbdxSo=ILaUpPBC5", true, false]
|
|
124
129
|
}
|
|
125
130
|
];
|
|
126
131
|
}
|
|
@@ -131,9 +136,9 @@ class FromBase64 extends Operation {
|
|
|
131
136
|
* @returns {byteArray}
|
|
132
137
|
*/
|
|
133
138
|
run(input, args) {
|
|
134
|
-
const [alphabet, removeNonAlphChars] = args;
|
|
139
|
+
const [alphabet, removeNonAlphChars, strictMode] = args;
|
|
135
140
|
|
|
136
|
-
return fromBase64(input, alphabet, "byteArray", removeNonAlphChars);
|
|
141
|
+
return fromBase64(input, alphabet, "byteArray", removeNonAlphChars, strictMode);
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
/**
|
|
@@ -44,8 +44,8 @@ class Substitute extends Operation {
|
|
|
44
44
|
* @returns {string}
|
|
45
45
|
*/
|
|
46
46
|
run(input, args) {
|
|
47
|
-
const plaintext = Utils.expandAlphRange(args[0])
|
|
48
|
-
ciphertext = Utils.expandAlphRange(args[1])
|
|
47
|
+
const plaintext = Utils.expandAlphRange([...args[0]]),
|
|
48
|
+
ciphertext = Utils.expandAlphRange([...args[1]]);
|
|
49
49
|
let output = "",
|
|
50
50
|
index = -1;
|
|
51
51
|
|
|
@@ -53,9 +53,9 @@ class Substitute extends Operation {
|
|
|
53
53
|
output = "Warning: Plaintext and Ciphertext lengths differ\n\n";
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
for (
|
|
57
|
-
index = plaintext.indexOf(
|
|
58
|
-
output += index > -1 && index < ciphertext.length ? ciphertext[index] :
|
|
56
|
+
for (const character of input) {
|
|
57
|
+
index = plaintext.indexOf(character);
|
|
58
|
+
output += index > -1 && index < ciphertext.length ? ciphertext[index] : character;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
return output;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import Operation from "../Operation.mjs";
|
|
8
|
+
import OperationError from "../errors/OperationError.mjs";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* To Upper case operation
|
|
@@ -37,25 +38,30 @@ class ToUpperCase extends Operation {
|
|
|
37
38
|
* @returns {string}
|
|
38
39
|
*/
|
|
39
40
|
run(input, args) {
|
|
41
|
+
if (!args || args.length === 0) {
|
|
42
|
+
throw new OperationError("No capitalization scope was provided.");
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
const scope = args[0];
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
case "All": /* falls through */
|
|
56
|
-
default:
|
|
57
|
-
return input.toUpperCase();
|
|
47
|
+
if (scope === "All") {
|
|
48
|
+
return input.toUpperCase();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const scopeRegex = {
|
|
52
|
+
"Word": /(\b\w)/gi,
|
|
53
|
+
"Sentence": /(?:\.|^)\s*(\b\w)/gi,
|
|
54
|
+
"Paragraph": /(?:\n|^)\s*(\b\w)/gi
|
|
55
|
+
}[scope];
|
|
56
|
+
|
|
57
|
+
if (scopeRegex === undefined) {
|
|
58
|
+
throw new OperationError("Unrecognized capitalization scope");
|
|
58
59
|
}
|
|
60
|
+
|
|
61
|
+
// Use the regex to capitalize the input
|
|
62
|
+
return input.replace(scopeRegex, function(m) {
|
|
63
|
+
return m.toUpperCase();
|
|
64
|
+
});
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
/**
|
|
@@ -68,7 +68,7 @@ TestRegister.addTests([
|
|
|
68
68
|
{
|
|
69
69
|
name: "Magic Chain: Base64",
|
|
70
70
|
input: "WkVkV2VtUkRRbnBrU0Vwd1ltMWpQUT09",
|
|
71
|
-
expectedMatch: /From_Base64\('A-Za-z0-9\+\/=',true\)\nFrom_Base64\('A-Za-z0-9\+\/=',true\)\nFrom_Base64\('A-Za-z0-9\+\/=',true\)/,
|
|
71
|
+
expectedMatch: /From_Base64\('A-Za-z0-9\+\/=',true,false\)\nFrom_Base64\('A-Za-z0-9\+\/=',true,false\)\nFrom_Base64\('A-Za-z0-9\+\/=',true,false\)/,
|
|
72
72
|
recipeConfig: [
|
|
73
73
|
{
|
|
74
74
|
op: "Magic",
|
|
@@ -79,7 +79,7 @@ TestRegister.addTests([
|
|
|
79
79
|
{
|
|
80
80
|
name: "Magic Chain: Hex -> Hexdump -> Base64",
|
|
81
81
|
input: "MDAwMDAwMDAgIDM3IDM0IDIwIDM2IDM1IDIwIDM3IDMzIDIwIDM3IDM0IDIwIDMyIDMwIDIwIDM3ICB8NzQgNjUgNzMgNzQgMjAgN3wKMDAwMDAwMTAgIDMzIDIwIDM3IDM0IDIwIDM3IDMyIDIwIDM2IDM5IDIwIDM2IDY1IDIwIDM2IDM3ICB8MyA3NCA3MiA2OSA2ZSA2N3w=",
|
|
82
|
-
expectedMatch: /From_Base64\('A-Za-z0-9\+\/=',true\)\nFrom_Hexdump\(\)\nFrom_Hex\('Space'\)/,
|
|
82
|
+
expectedMatch: /From_Base64\('A-Za-z0-9\+\/=',true,false\)\nFrom_Hexdump\(\)\nFrom_Hex\('Space'\)/,
|
|
83
83
|
recipeConfig: [
|
|
84
84
|
{
|
|
85
85
|
op: "Magic",
|