MCPcopy
hub / github.com/gchq/CyberChef / bruteForce

Method bruteForce

src/core/lib/Magic.mjs:142–201  ·  view source on GitHub ↗

* Generate various simple brute-forced encodings of the data (trucated to 100 bytes). * * @returns {Object[]} - The encoded data and an operation config to generate it.

()

Source from the content-addressed store, hash-verified

140 * @returns {Object[]} - The encoded data and an operation config to generate it.
141 */
142 async bruteForce() {
143 const sample = new Uint8Array(this.inputBuffer).slice(0, 100);
144 const results = [];
145
146 // 1-byte XOR
147 for (let i = 1; i < 256; i++) {
148 results.push({
149 data: sample.map(b => b ^ i).buffer,
150 conf: {
151 op: "XOR",
152 args: [{"option": "Hex", "string": i.toString(16)}, "Standard", false]
153 }
154 });
155 }
156
157 // Bit rotate
158 for (let i = 1; i < 8; i++) {
159 results.push({
160 data: sample.map(b => (b >> i) | ((b & (Math.pow(2, i) - 1)) << (8 - i))).buffer,
161 conf: {
162 op: "Rotate right",
163 args: [i, false]
164 }
165 });
166 }
167
168 // Character encodings
169 const encodings = OperationConfig["Encode text"].args[0].value;
170
171 /**
172 * Test character encodings and add them if they change the data.
173 */
174 const testEnc = async op => {
175 for (let i = 0; i < encodings.length; i++) {
176 const conf = {
177 op: op,
178 args: [encodings[i]]
179 };
180
181 try {
182 const data = await this._runRecipe([conf], sample.buffer);
183
184 // Only add to the results if it changed the data
185 if (!_buffersEqual(data, sample.buffer)) {
186 results.push({
187 data: data,
188 conf: conf
189 });
190 }
191 } catch (err) {
192 continue;
193 }
194 }
195 };
196
197 await testEnc("Encode text");
198 await testEnc("Decode text");
199

Callers 1

speculativeExecutionMethod · 0.95

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected