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

Method parseQEncodedWord

src/core/operations/MIMEDecoding.mjs:145–168  ·  view source on GitHub ↗

* Parses a Q encoded word * * @param encodedWord

(encodedWord)

Source from the content-addressed store, hash-verified

143 * @param encodedWord
144 */
145 parseQEncodedWord(encodedWord) {
146 let decodedWord = "";
147 for (let i = 0; i < encodedWord.length; i++) {
148 if (encodedWord[i] === "_") {
149 decodedWord += " ";
150 // Parse hex encoding
151 } else if (encodedWord[i] === "=") {
152 if ((i + 2) >= encodedWord.length) throw new OperationError("Incorrectly Encoded Word");
153 const decodedHex = Utils.byteArrayToChars(fromHex(encodedWord.substring(i + 1, i + 3)));
154 decodedWord += decodedHex;
155 i += 2;
156 } else if (
157 (encodedWord[i].charCodeAt(0) >= " ".charCodeAt(0) && encodedWord[i].charCodeAt(0) <= "~".charCodeAt(0)) ||
158 encodedWord[i] === "\n" ||
159 encodedWord[i] === "\r" ||
160 encodedWord[i] === "\t") {
161 decodedWord += encodedWord[i];
162 } else {
163 throw new OperationError("Incorrectly Encoded Word");
164 }
165 }
166
167 return decodedWord;
168 }
169}
170
171export default MIMEDecoding;

Callers 1

decodeHeadersMethod · 0.95

Calls 2

fromHexFunction · 0.90
byteArrayToCharsMethod · 0.80

Tested by

no test coverage detected