Ciphers.mjs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /**
  2. * Cipher tests.
  3. *
  4. * @author Matt C [matt@artemisbot.uk]
  5. * @author n1474335 [n1474335@gmail.com]
  6. *
  7. * @copyright Crown Copyright 2018
  8. * @license Apache-2.0
  9. */
  10. import TestRegister from "../../TestRegister";
  11. TestRegister.addTests([
  12. {
  13. name: "Affine Encode: no input",
  14. input: "",
  15. expectedOutput: "",
  16. recipeConfig: [
  17. {
  18. op: "Affine Cipher Encode",
  19. args: [1, 0]
  20. }
  21. ],
  22. },
  23. {
  24. name: "Affine Encode: invalid a & b (non-integer)",
  25. input: "some keys are shaped as locks. index[me]",
  26. expectedOutput: "The values of a and b can only be integers.",
  27. recipeConfig: [
  28. {
  29. op: "Affine Cipher Encode",
  30. args: [0.1, 0.00001]
  31. }
  32. ],
  33. },
  34. {
  35. name: "Affine Encode: no effect",
  36. input: "some keys are shaped as locks. index[me]",
  37. expectedOutput: "some keys are shaped as locks. index[me]",
  38. recipeConfig: [
  39. {
  40. op: "Affine Cipher Encode",
  41. args: [1, 0]
  42. }
  43. ],
  44. },
  45. {
  46. name: "Affine Encode: normal",
  47. input: "some keys are shaped as locks. index[me]",
  48. expectedOutput: "vhnl tldv xyl vcxelo xv qhrtv. zkolg[nl]",
  49. recipeConfig: [
  50. {
  51. op: "Affine Cipher Encode",
  52. args: [23, 23]
  53. }
  54. ],
  55. },
  56. {
  57. name: "Affine Decode: no input",
  58. input: "",
  59. expectedOutput: "",
  60. recipeConfig: [
  61. {
  62. op: "Affine Cipher Decode",
  63. args: [1, 0]
  64. }
  65. ],
  66. },
  67. {
  68. name: "Affine Decode: invalid a & b (non-integer)",
  69. input: "vhnl tldv xyl vcxelo xv qhrtv. zkolg[nl]",
  70. expectedOutput: "The values of a and b can only be integers.",
  71. recipeConfig: [
  72. {
  73. op: "Affine Cipher Decode",
  74. args: [0.1, 0.00001]
  75. }
  76. ],
  77. },
  78. {
  79. name: "Affine Decode: invalid a (coprime)",
  80. input: "vhnl tldv xyl vcxelo xv qhrtv. zkolg[nl]",
  81. expectedOutput: "The value of `a` must be coprime to 26.",
  82. recipeConfig: [
  83. {
  84. op: "Affine Cipher Decode",
  85. args: [8, 23]
  86. }
  87. ],
  88. },
  89. {
  90. name: "Affine Decode: no effect",
  91. input: "vhnl tldv xyl vcxelo xv qhrtv. zkolg[nl]",
  92. expectedOutput: "vhnl tldv xyl vcxelo xv qhrtv. zkolg[nl]",
  93. recipeConfig: [
  94. {
  95. op: "Affine Cipher Decode",
  96. args: [1, 0]
  97. }
  98. ],
  99. },
  100. {
  101. name: "Affine Decode: normal",
  102. input: "vhnl tldv xyl vcxelo xv qhrtv. zkolg[nl]",
  103. expectedOutput: "some keys are shaped as locks. index[me]",
  104. recipeConfig: [
  105. {
  106. op: "Affine Cipher Decode",
  107. args: [23, 23]
  108. }
  109. ],
  110. },
  111. {
  112. name: "Atbash: no input",
  113. input: "",
  114. expectedOutput: "",
  115. recipeConfig: [
  116. {
  117. op: "Atbash Cipher",
  118. args: []
  119. }
  120. ],
  121. },
  122. {
  123. name: "Atbash: normal",
  124. input: "old slow slim horn",
  125. expectedOutput: "low hold horn slim",
  126. recipeConfig: [
  127. {
  128. op: "Atbash Cipher",
  129. args: []
  130. }
  131. ],
  132. },
  133. {
  134. name: "Bifid Cipher Encode: no input",
  135. input: "",
  136. expectedOutput: "",
  137. recipeConfig: [
  138. {
  139. "op": "Bifid Cipher Encode",
  140. "args": ["nothing"]
  141. }
  142. ],
  143. },
  144. {
  145. name: "Bifid Cipher Encode: no key",
  146. input: "We recreate conditions similar to the Van-Allen radiation belt in our secure facilities.",
  147. expectedOutput: "Vq daqcliho rmltofvlnc qbdhlcr nt qdq Fbm-Rdkkm vuoottnoi aitp al axf tdtmvt owppkaodtx.",
  148. recipeConfig: [
  149. {
  150. "op": "Bifid Cipher Encode",
  151. "args": [""]
  152. }
  153. ],
  154. },
  155. {
  156. name: "Bifid Cipher Encode: invalid key (non-alphabetic)",
  157. input: "We recreate conditions similar to the Van-Allen radiation belt in our secure facilities.",
  158. expectedOutput: "The key must consist only of letters in the English alphabet",
  159. recipeConfig: [
  160. {
  161. "op": "Bifid Cipher Encode",
  162. "args": ["abc123"]
  163. }
  164. ],
  165. },
  166. {
  167. name: "Bifid Cipher Encode: normal",
  168. input: "We recreate conditions similar to the Van-Allen radiation belt in our secure facilities.",
  169. expectedOutput: "Wc snpsigdd cpfrrcxnfi hikdnnp dm crc Fcb-Pdeug vueageacc vtyl sa zxm crebzp lyoeuaiwpv.",
  170. recipeConfig: [
  171. {
  172. "op": "Bifid Cipher Encode",
  173. "args": ["Schrodinger"]
  174. }
  175. ],
  176. },
  177. {
  178. name: "Bifid Cipher Decode: no input",
  179. input: "",
  180. expectedOutput: "",
  181. recipeConfig: [
  182. {
  183. "op": "Bifid Cipher Decode",
  184. "args": ["nothing"]
  185. }
  186. ],
  187. },
  188. {
  189. name: "Bifid Cipher Decode: no key",
  190. input: "Vq daqcliho rmltofvlnc qbdhlcr nt qdq Fbm-Rdkkm vuoottnoi aitp al axf tdtmvt owppkaodtx.",
  191. expectedOutput: "We recreate conditions similar to the Van-Allen radiation belt in our secure facilities.",
  192. recipeConfig: [
  193. {
  194. "op": "Bifid Cipher Decode",
  195. "args": [""]
  196. }
  197. ],
  198. },
  199. {
  200. name: "Bifid Cipher Decode: invalid key (non-alphabetic)",
  201. input: "Vq daqcliho rmltofvlnc qbdhlcr nt qdq Fbm-Rdkkm vuoottnoi aitp al axf tdtmvt owppkaodtx.",
  202. expectedOutput: "The key must consist only of letters in the English alphabet",
  203. recipeConfig: [
  204. {
  205. "op": "Bifid Cipher Decode",
  206. "args": ["abc123"]
  207. }
  208. ],
  209. },
  210. {
  211. name: "Bifid Cipher Decode: normal",
  212. input: "Wc snpsigdd cpfrrcxnfi hikdnnp dm crc Fcb-Pdeug vueageacc vtyl sa zxm crebzp lyoeuaiwpv.",
  213. expectedOutput: "We recreate conditions similar to the Van-Allen radiation belt in our secure facilities.",
  214. recipeConfig: [
  215. {
  216. "op": "Bifid Cipher Decode",
  217. "args": ["Schrodinger"]
  218. }
  219. ],
  220. },
  221. {
  222. name: "Vigenère Encode: no input",
  223. input: "",
  224. expectedOutput: "",
  225. recipeConfig: [
  226. {
  227. "op": "Vigenère Encode",
  228. "args": ["nothing"]
  229. }
  230. ],
  231. },
  232. {
  233. name: "Vigenère Encode: no key",
  234. input: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  235. expectedOutput: "No key entered",
  236. recipeConfig: [
  237. {
  238. "op": "Vigenère Encode",
  239. "args": [""]
  240. }
  241. ],
  242. },
  243. {
  244. name: "Vigenère Encode: invalid key",
  245. input: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  246. expectedOutput: "The key must consist only of letters",
  247. recipeConfig: [
  248. {
  249. "op": "Vigenère Encode",
  250. "args": ["abc123"]
  251. }
  252. ],
  253. },
  254. {
  255. name: "Vigenère Encode: normal",
  256. input: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  257. expectedOutput: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  258. recipeConfig: [
  259. {
  260. "op": "Vigenère Encode",
  261. "args": ["Edward"]
  262. }
  263. ],
  264. },
  265. {
  266. name: "Vigenère Decode: no input",
  267. input: "",
  268. expectedOutput: "",
  269. recipeConfig: [
  270. {
  271. "op": "Vigenère Decode",
  272. "args": ["nothing"]
  273. }
  274. ],
  275. },
  276. {
  277. name: "Vigenère Decode: no key",
  278. input: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  279. expectedOutput: "No key entered",
  280. recipeConfig: [
  281. {
  282. "op": "Vigenère Decode",
  283. "args": [""]
  284. }
  285. ],
  286. },
  287. {
  288. name: "Vigenère Decode: invalid key",
  289. input: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  290. expectedOutput: "The key must consist only of letters",
  291. recipeConfig: [
  292. {
  293. "op": "Vigenère Decode",
  294. "args": ["abc123"]
  295. }
  296. ],
  297. },
  298. {
  299. name: "Vigenère Decode: normal",
  300. input: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  301. expectedOutput: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  302. recipeConfig: [
  303. {
  304. "op": "Vigenère Decode",
  305. "args": ["Edward"]
  306. }
  307. ],
  308. },
  309. ]);