Ciphers.mjs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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: "Citrix CTX1 Encode",
  223. input: "Password1",
  224. expectedOutput: "PFFAJEDBOHECJEDBODEGIMCJPOFLJKDPKLAO",
  225. recipeConfig: [
  226. {
  227. "op": "Citrix CTX1 Encode",
  228. "args": []
  229. }
  230. ],
  231. },
  232. {
  233. name: "Citrix CTX1 Decode: normal",
  234. input: "PFFAJEDBOHECJEDBODEGIMCJPOFLJKDPKLAO",
  235. expectedOutput: "Password1",
  236. recipeConfig: [
  237. {
  238. "op": "Citrix CTX1 Decode",
  239. "args": []
  240. }
  241. ],
  242. },
  243. {
  244. name: "Citrix CTX1 Decode: invalid length",
  245. input: "PFFAJEDBOHECJEDBODEGIMCJPOFLJKDPKLA",
  246. expectedOutput: "Incorrect hash length",
  247. recipeConfig: [
  248. {
  249. "op": "Citrix CTX1 Decode",
  250. "args": []
  251. }
  252. ],
  253. },
  254. {
  255. name: "Vigenère Encode: no input",
  256. input: "",
  257. expectedOutput: "",
  258. recipeConfig: [
  259. {
  260. "op": "Vigenère Encode",
  261. "args": ["nothing"]
  262. }
  263. ],
  264. },
  265. {
  266. name: "Vigenère Encode: no key",
  267. input: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  268. expectedOutput: "No key entered",
  269. recipeConfig: [
  270. {
  271. "op": "Vigenère Encode",
  272. "args": [""]
  273. }
  274. ],
  275. },
  276. {
  277. name: "Vigenère Encode: invalid key",
  278. input: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  279. expectedOutput: "The key must consist only of letters",
  280. recipeConfig: [
  281. {
  282. "op": "Vigenère Encode",
  283. "args": ["abc123"]
  284. }
  285. ],
  286. },
  287. {
  288. name: "Vigenère Encode: normal",
  289. input: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  290. expectedOutput: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  291. recipeConfig: [
  292. {
  293. "op": "Vigenère Encode",
  294. "args": ["Edward"]
  295. }
  296. ],
  297. },
  298. {
  299. name: "Vigenère Decode: no input",
  300. input: "",
  301. expectedOutput: "",
  302. recipeConfig: [
  303. {
  304. "op": "Vigenère Decode",
  305. "args": ["nothing"]
  306. }
  307. ],
  308. },
  309. {
  310. name: "Vigenère Decode: no key",
  311. input: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  312. expectedOutput: "No key entered",
  313. recipeConfig: [
  314. {
  315. "op": "Vigenère Decode",
  316. "args": [""]
  317. }
  318. ],
  319. },
  320. {
  321. name: "Vigenère Decode: invalid key",
  322. input: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  323. expectedOutput: "The key must consist only of letters",
  324. recipeConfig: [
  325. {
  326. "op": "Vigenère Decode",
  327. "args": ["abc123"]
  328. }
  329. ],
  330. },
  331. {
  332. name: "Vigenère Decode: normal",
  333. input: "PXCGRJIEWSVPIQPVRUIQJEJDPOEEJFEQXETOSWDEUDWHJEDLIVANVPMHOCRQFHYLFWLHZAJDPOEEJDPZWYJXWHED",
  334. expectedOutput: "LUGGAGEBASEMENTVARENNESALLIESCANBECLOTHEDASENEMIESENEMIESCANBECLOTHEDASALLIESALWAYSUSEID",
  335. recipeConfig: [
  336. {
  337. "op": "Vigenère Decode",
  338. "args": ["Edward"]
  339. }
  340. ],
  341. },
  342. {
  343. name: "Substitute: no pt/ct",
  344. input: "flee at once. we are discovered!",
  345. expectedOutput: "flee at once. we are discovered!",
  346. recipeConfig: [
  347. {
  348. "op": "Substitute",
  349. "args": ["", ""]
  350. }
  351. ],
  352. },
  353. {
  354. name: "Substitute: no input",
  355. input: "",
  356. expectedOutput: "",
  357. recipeConfig: [
  358. {
  359. "op": "Substitute",
  360. "args": ["abcdefghijklmnopqrstuvwxyz", "zebrascdfghijklmnopqtuvwxy"]
  361. }
  362. ],
  363. },
  364. {
  365. name: "Substitute: uneven pt/ct",
  366. input: "flee at once. we are discovered!",
  367. expectedOutput: "Warning: Plaintext and Ciphertext lengths differ\n\nsiaa zq lkba. va zoa rfpbluaoar!",
  368. recipeConfig: [
  369. {
  370. "op": "Substitute",
  371. "args": ["abcdefghijklmnopqrstuvwxyz", "zebrascdfghijklmnopqtuvwx"]
  372. }
  373. ],
  374. },
  375. {
  376. name: "Substitute: normal",
  377. input: "flee at once. we are discovered!",
  378. expectedOutput: "siaa zq lkba. va zoa rfpbluaoar!",
  379. recipeConfig: [
  380. {
  381. "op": "Substitute",
  382. "args": ["abcdefghijklmnopqrstuvwxyz", "zebrascdfghijklmnopqtuvwxy"]
  383. }
  384. ],
  385. },
  386. ]);