RC4.mjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @author n1474335 [n1474335@gmail.com]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation";
  7. import CryptoJS from "crypto-js";
  8. import { format } from "../lib/Ciphers";
  9. /**
  10. * RC4 operation
  11. */
  12. class RC4 extends Operation {
  13. /**
  14. * RC4 constructor
  15. */
  16. constructor() {
  17. super();
  18. this.name = "RC4";
  19. this.module = "Ciphers";
  20. this.description = "RC4 (also known as ARC4) is a widely-used stream cipher designed by Ron Rivest. It is used in popular protocols such as SSL and WEP. Although remarkable for its simplicity and speed, the algorithm's history doesn't inspire confidence in its security.";
  21. this.inputType = "string";
  22. this.outputType = "string";
  23. this.args = [
  24. {
  25. "name": "Passphrase",
  26. "type": "toggleString",
  27. "value": "",
  28. "toggleValues": ["UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1", "Hex", "Base64"]
  29. },
  30. {
  31. "name": "Input format",
  32. "type": "option",
  33. "value": ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"]
  34. },
  35. {
  36. "name": "Output format",
  37. "type": "option",
  38. "value": ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"]
  39. }
  40. ];
  41. }
  42. /**
  43. * @param {string} input
  44. * @param {Object[]} args
  45. * @returns {string}
  46. */
  47. run(input, args) {
  48. const message = format[args[1]].parse(input),
  49. passphrase = format[args[0].option].parse(args[0].string),
  50. encrypted = CryptoJS.RC4.encrypt(message, passphrase);
  51. return encrypted.ciphertext.toString(format[args[2]]);
  52. }
  53. /**
  54. * Highlight RC4
  55. *
  56. * @param {Object[]} pos
  57. * @param {number} pos[].start
  58. * @param {number} pos[].end
  59. * @param {Object[]} args
  60. * @returns {Object[]} pos
  61. */
  62. highlight(pos, args) {
  63. return pos;
  64. }
  65. /**
  66. * Highlight RC4 in reverse
  67. *
  68. * @param {Object[]} pos
  69. * @param {number} pos[].start
  70. * @param {number} pos[].end
  71. * @param {Object[]} args
  72. * @returns {Object[]} pos
  73. */
  74. highlightReverse(pos, args) {
  75. return pos;
  76. }
  77. }
  78. export default RC4;