Ingen beskrivning

challenge.adoc 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. = Vigenere cipher
  2. :stem: latexmath
  3. == Task
  4. The content of link:./ciphertext.txt[this file] is encrypted with a _Vigenere cipher_. (The key length is limited to 20 letters) +
  5. Your task is to decrypt the content. Please note that you do not know the length of the key in this task!
  6. Your solution will only be accepted if you find a better approach than simply trying all possible combinations for every possible key length (w.r.t. brute force) paired with a _simple_ frequency analysis.
  7. _A more intelligent appraoch will solve this task in roughtly quadratic time stem:[O=n^2], whereas trying all possible combinations, i.e. brute force, needs exponential time stem:[O=c^n \leftarrow c \gt 1]._
  8. == Help
  9. [NOTE]
  10. ====
  11. The values used in this example are artifical and not the real values. For a very short text, the solution is not accurate enough!
  12. ====
  13. . you need to guess the key length, thus you know it is not longer than 20 letters, try every possible key length stem:[2 \leq length \leq 20]
  14. . for every key length analyze the ciphertext statistically to derive the best plaintext
  15. .. you have to crack the key two letters at a time +
  16. if the length is 3
  17. VHEEMCRD (<- note that this is the plaintext for the example)
  18. ABCABCAB
  19. you observe that the letters VH, EM and RD are encrypted with the first two letters of the key
  20. .. cut the ciphertext to strings with the size of the key length. each column is then encoded with one letter +
  21. example: +
  22. Suppose the key is *ABC*. The _ciphertext_ *VIGENERE* should be cut into
  23. VIG
  24. ENE
  25. RE
  26. . combining the first string with the second, the second with the third and so on. the last string should be combined with the first +
  27. this gives us:
  28. 01 01 01 (key_index)
  29. --------
  30. VI EN RE # letters enrypted with key[0] and key[1]
  31. 12 12 (key_index)
  32. -----
  33. IG NE # letters enrypted with key[1] and key[2]
  34. 20 20 (key_index)
  35. -----
  36. GV EE # letters enrypted with key[2] and key[0]
  37. . for each sequence of two consecutive letters try all possible two letters keys (AA, AB, AC, ..., ZY, ZZ)
  38. VI EN RE decrypted with AA gives VI EN RE
  39. VI EN RE decrypted with AB gives VH EM RD
  40. ...
  41. VI EN RE decrypted with ZZ gives WJ FO SF
  42. . using the link:./english_bigram[Bigram Frequencies] (the frequencies are sorted alphabetically) give each key a score by multiplying the frequencies of the bigrams in the plaintext
  43. CIPHER | KEY | PLAIN
  44. --------------------------
  45. VI EN RE | AB | VH EM RD
  46. --------------------------
  47. score(AB) = frequency(VH) + frequency(EM) + frequency(RD)
  48. [TIP]
  49. --
  50. * Normally, you would calculate the score by multiplication: `score(AB) = frequency(VH) * frequency(EM) * frequency(RD)`. However, with the given bigram frequencies, which are provided as logarithmic values, you can use an addition instead
  51. * This means, the calculation using the numbers from the provided Bigram Frequencies is as follows: `score(AB) = frequency(VH) + frequency(EM) + frequency(RD)`
  52. ** The higher the calculated value, the better is the score for that particular bigram pair
  53. --
  54. . select for each string the key with the best score
  55. PLAIN | KEY | K_index | SCORE
  56. -----------------------------------
  57. VH EM RD | AB | 01 |151125528
  58. DA IY | FG | 12 |119303088
  59. EI CR | CN | 20 |122328401
  60. . form the final key from these keys
  61. key[0] is either A or N, since score(AB) > score(CN), take A
  62. key[1] is either B or F, since score(AB) > score(FG), take B
  63. key[2] is either G or C, since score(CN) > score(FG), take C
  64. => the best key of length 3 is ABC
  65. . do this process for key lengths 2 to 20
  66. . using frequency analysis find the best fit of the 19 keys