AtbashCipher.mjs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @author Matt C [matt@artemisbot.uk]
  3. * @copyright Crown Copyright 2016
  4. * @license Apache-2.0
  5. */
  6. import Operation from "../Operation.mjs";
  7. import { affineEncode } from "../lib/Ciphers.mjs";
  8. /**
  9. * Atbash Cipher operation
  10. */
  11. class AtbashCipher extends Operation {
  12. /**
  13. * AtbashCipher constructor
  14. */
  15. constructor() {
  16. super();
  17. this.name = "Atbash Cipher";
  18. this.module = "Ciphers";
  19. this.description = "Atbash is a mono-alphabetic substitution cipher originally used to encode the Hebrew alphabet. It has been modified here for use with the Latin alphabet.";
  20. this.infoURL = "https://wikipedia.org/wiki/Atbash";
  21. this.inputType = "string";
  22. this.outputType = "string";
  23. this.args = [];
  24. }
  25. /**
  26. * @param {string} input
  27. * @param {Object[]} args
  28. * @returns {string}
  29. */
  30. run(input, args) {
  31. return affineEncode(input, [25, 25]);
  32. }
  33. /**
  34. * Highlight Atbash Cipher
  35. *
  36. * @param {Object[]} pos
  37. * @param {number} pos[].start
  38. * @param {number} pos[].end
  39. * @param {Object[]} args
  40. * @returns {Object[]} pos
  41. */
  42. highlight(pos, args) {
  43. return pos;
  44. }
  45. /**
  46. * Highlight Atbash Cipher in reverse
  47. *
  48. * @param {Object[]} pos
  49. * @param {number} pos[].start
  50. * @param {number} pos[].end
  51. * @param {Object[]} args
  52. * @returns {Object[]} pos
  53. */
  54. highlightReverse(pos, args) {
  55. return pos;
  56. }
  57. }
  58. export default AtbashCipher;