TextEncodingBruteForce.mjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @author Cynser
  3. * @copyright Crown Copyright 2018
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. import Utils from "../Utils";
  8. import cptable from "../vendor/js-codepage/cptable.js";
  9. import {IO_FORMAT} from "../lib/ChrEnc";
  10. /**
  11. * Text Encoding Brute Force operation
  12. */
  13. class TextEncodingBruteForce extends Operation {
  14. /**
  15. * TextEncodingBruteForce constructor
  16. */
  17. constructor() {
  18. super();
  19. this.name = "Text Encoding Brute Force";
  20. this.module = "CharEnc";
  21. this.description = "Enumerate all possible text encodings for input.";
  22. this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
  23. this.inputType = "string";
  24. this.outputType = "string";
  25. this.args = [];
  26. }
  27. /**
  28. * @param {string} input
  29. * @param {Object[]} args
  30. * @returns {string}
  31. */
  32. run(input, args) {
  33. const output = [],
  34. charSets = Object.keys(IO_FORMAT);
  35. for (let i = 0; i < charSets.length; i++) {
  36. let currentEncoding = Utils.printable(charSets[i] + ": ", false);
  37. currentEncoding += cptable.utils.encode(IO_FORMAT[charSets[i]], input);
  38. output.push(currentEncoding);
  39. }
  40. return output.join("\n");
  41. }
  42. }
  43. export default TextEncodingBruteForce;