home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / zines / phrack2 / phrack51.013 < prev    next >
Encoding:
Text File  |  2003-06-11  |  14.9 KB  |  480 lines

  1.  
  2. ---[  Phrack Magazine   Volume 7, Issue 51 September 01, 1997, article 13 of 17
  3.  
  4.  
  5. -------------------------[  Monoalphabetic Cryptanalysis (Cyphers, Part One)
  6.  
  7.  
  8. --------[  Jeff Thompson aka 'Mythrandir' <jwthomp@cu-online.com>
  9.  
  10.  
  11.  
  12. Written for Phrack and completed on Sunday, August 31st, 1997.
  13.  
  14.  
  15. ---------
  16.  
  17. First a quick hello to all of those I met at DefCon this year.  It was
  18. incredible fun to finally put faces to many of the people I have been talking
  19. with for some time.  It was truly was a treat to meet so many others who are
  20. alive with the spirit of discovery.
  21.  
  22. ----------
  23.  
  24.  
  25. This is the first in a series of articles on Cryptology that I am writing.
  26. The goals of these articles will be to attempt to convey some of the excitement
  27. and fun of cyphers.  A topic of much discussion in regards to cryptography
  28. currently, is about computer based cyphers such as DES, RSA, and the PGP
  29. implementation.  I will not be discussing these.  Rather, these articles will
  30. cover what I will term classical cryptology.  Or cryptology as it existed
  31. before fast number crunching machines came into existance.  These are the sorts
  32. of cyphers which interested cryptographers throughout time and continue to be
  33. found even to this very day.  Even today, companies are producing software
  34. whose encryption methods are attackable.  You will find these commonly among
  35. password protection schemes for software programs.  Through the course of these
  36. articles I will explain in practical terms several common cypher types and
  37. various implementations of them as well as cryptanalytic techniques for
  38. breaking these cyphers.
  39.  
  40. Creating cyphers is fun and all, but the real excitement and often times tedium
  41. is found in Cryptanalysis.  Many of the ideas presented in these articles will
  42. based on three sources.  The following two books: The Codebreakers by David
  43. Kahn (ISBN: 0-684-83130-9) and Decrypted Secrets by F.L. Bauer
  44. (ISBN: 3-540-60418-9).  Both authors have put together wonderful books which
  45. both cover the history and methods of Cryptology.  Do yourself and the authors
  46. a favor and purchase these books.  You will be very pleased with the lot.
  47. Finally, a miniscule amount of these articles will be written based on my own
  48. personal experience.
  49.  
  50. The fun is in the journey and I welcome you on what is certain to be an
  51. interesting trip.  Please feel free to raise questions, engage me in
  52. discussions, correct me, or simply offer suggestions at jwthomp@cu-online.com.
  53. Please be patient with me as I am traveling extensively currently, and may be
  54. away from the computer at length occasionally.
  55.  
  56. Out the door and into the wild...
  57.  
  58.  
  59. --Monoalphabetic Cyphers
  60.  
  61. Monoalphabetic cyphers are often currently found in simple cryptograms in books
  62. and magazines.  These are just simple substitution cyphers.  This does not
  63. mean that they are always simple for the beginning amateur to solve.
  64.  
  65. Three common monoalphabetic cyphers which are used are substitution, cyclical,
  66. and keyed cyphers.
  67.  
  68.  
  69. -Substitution Cyphers
  70.  
  71. By taking an alphabet and replacing each letter with another letter in a
  72. unique fashion you create a simple monoalphabetic cypher.
  73.  
  74. Plaintext Alphabet    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  75. Cypher Alphabet        Z I K M O Q S U W Y A C E B D F H J L N P R T V X G
  76.  
  77.  
  78. Plaintext Message
  79.  
  80. The blue cow will rise during the second moon from the west field.
  81.  
  82. Cyphertext Message
  83.  
  84. nuo icpo kdt twcc jwlo mpjwbs nuo lokdbm eddb qjde nuo toln qwocm.
  85.  
  86.  
  87. -Cyclical Cyphers
  88.  
  89. By taking an alphabet and aligning it with a rotated alphabet you get a
  90. cyclical cypher.  For example:
  91.  
  92. Plaintext Alphabet    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  93. Cypher Alphabet        N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
  94.  
  95.  
  96. Indeed, you may recognize this cypher as a ROT13 which is commonly used on
  97. news groups to obscure messages.
  98.  
  99.  
  100. -Keyed Cypher
  101.  
  102. Another way to create a monoalphabetic cypher is to choose a keyword or phrase
  103. as the beginning of the cypher alphabet. Usually, only the unique letters from
  104. the phrase are used in order to make sure the plaintext to cyphertext behaves
  105. in a one to one fashion.
  106.  
  107. For example:
  108.  
  109. Plaintext Alphabet:    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  110. Cypher Alphabet        L E T O S H D G F W A R B C I J K M N P Q U V X Y Z
  111.  
  112. The passphrase in this cypher is "Let loose the dogs of war"  The advantage of
  113. such a system is that the encryption method is easy to remember.  Also, a
  114. method of key change can be created without ever having to distribute the keys.
  115. For example, one could use the 4 words at a time of some piece of literature.
  116. Every message could use the next four words.  Indeed, this change could occur
  117. more frequently, but that is a subject for another article.
  118.  
  119.  
  120. -Bipartite Substitution
  121.  
  122. Bipartite substition is the use of symbol pairs to represent plaintext.  Later
  123. we will see that this sort of substitution lends itself to be easily made more
  124. difficult to analyze. Two examples of this are:
  125.  
  126.   1 2 3 4 5                                     A B C D E
  127. 1 A B C D E                             A A B C D E
  128. 2 F G H I J                             B F G H I J
  129. 3 K L M N O                             C K L M N O
  130. 4 P Q R S T                or             D P Q R S T
  131. 5 U V W X Y                             E U V W X Y
  132. 6 Z 0 1 2 3                             F Z 0 1 2 3
  133. 7 4 5 6 7 8                             G 4 5 6 7 8
  134. 9 9 . - ? ,                             H 9 . - ? ,
  135.  
  136.  
  137. Obviously, the letters do not need to be placed in this order as their solutions
  138. would not be that difficult to guess.
  139.  
  140.  
  141.  
  142. --Cryptanalysis
  143.  
  144.  
  145. Previously we created a cyphered message:
  146.  
  147. nuo icpo kdt twcc jwlo mpjwbs nuo lokdbm eddb qjde nuo toln qwocm.
  148.  
  149.  
  150. If one were to receive this message, figuring out its contents might seem
  151. fairly daunting. However,  there are some very good methods for recovering the
  152. plaintext from the cyphertext. The following discussion will work under the
  153. assumption that we know the cyphers with which we are dealing are
  154. monoalphabetics.
  155.  
  156.  
  157. -Frequency Analysis
  158.  
  159. The first method we will use is frequency analysis.  Natural languages have
  160. many qualities which are very useful for the analysis of cyphertext.  Languages
  161. have letters which occur more commonly in text, collections of letters which
  162. are more frequent,  patterns in words, and other related letter occurances.
  163.  
  164. Counting up the occurances of letters we find that there are...
  165.  
  166. letter    occurances
  167. b        3
  168. c        4
  169. d        5
  170. e        2
  171. i        1
  172. j        3
  173. k        2
  174. l        3
  175. m        3
  176. n        4
  177. o        8
  178. p        2
  179. q        2
  180. s        1
  181. t        3
  182. u        3
  183. w        4
  184.  
  185. The order of greatest frequency to least is:
  186.  
  187.  8   5     4          3           2       1
  188. {o} {d} {c n w} {b j l m t u} {e k p q} {i s}
  189.  
  190.  
  191. If this sort of analysis were run on many volumes of english you would find that
  192. a pattern would emerge.  It would look like this:
  193.  
  194. {e} {t} {a o i n} {s r h} {l d} {c u m f} {p g w y b} {v k} {x j q z}
  195.  
  196. You will notice an immediate correlation between e and o.  However, for the
  197. rest of the letters we can not be very certain.  In fact, we can not be very
  198. certain about e either.
  199.  
  200. Since this text is short it is helpful to take a look at some of the other
  201. behaviors of this text.
  202.  
  203. Counting up the first, second, third, and last letters of the words in this
  204. text we find the following frequencies:
  205.  
  206.  
  207. First Letter in word        Occurances
  208.  
  209. e                    1
  210. i                    1
  211. j                    1
  212. k                    1
  213. l                    1
  214. m                    1
  215. n                    3
  216. q                    2
  217. t                    2
  218.  
  219. Order:
  220.  
  221. n q t e i j k l m
  222.  
  223.  
  224. Second letter in word        Occurances
  225. c                    1
  226. d                    2
  227. i                    1
  228. n                    1
  229. o                    2
  230. p                    1
  231. u                    3
  232. w                    3
  233.  
  234. Order:
  235.  
  236. u w d o c i n p
  237.  
  238.  
  239. Third letter in word        Occurances
  240.  
  241. c                    1
  242. d                    2
  243. i                    1
  244. k                    1
  245. l                    2
  246. o                    4
  247. p                    1
  248. t                    1
  249. u                    1
  250.  
  251. Order:
  252.  
  253. o d l c i k p t u
  254.  
  255.  
  256. Last letter in word        Occurances
  257.  
  258. b                    1
  259. c                    1
  260. e                    1
  261. m                    1
  262. n                    1
  263. o                    5
  264. s                    1
  265. t                    1
  266.  
  267.  
  268. English frequency for first letter:
  269.  
  270. t a o m h w
  271.  
  272. Second letter:
  273.  
  274. h o e i a u
  275.  
  276. Third letter:
  277.  
  278. e s a r n i
  279.  
  280. Last letter:
  281.  
  282. e t s d n r
  283.  
  284. Noticing the higher frequency count for 'o' in the third and last letters of
  285. words in addition to its absence as a first letter in any words gives us strong
  286. reason to believe that 'o' substitutes for 'e'.  This is the first wedge into
  287. solving this cypher.
  288.  
  289. However, do not be fooled by the apparent strengths of frequency analysis.
  290. Entire books have been written without the use of some letters in the English
  291. alphabet.  For instance The Great Gatsby was written without using the letter
  292. 'e' in one word of the book.
  293.  
  294.  
  295. Other items to analyze in cyphertext documents is the appearance of letters in
  296. groups.  These are called bigrams and trigrams.  For example, 'th' is a very
  297. common letter pairing in the english language.  Also, as no surprise 'the' is
  298. a very common trigram.  Analysis of english documents will find these results
  299. for you.
  300.  
  301.  
  302. So now that that we have developed a simple way of starting to attack cyphers
  303. lets examine a few ways to make them more difficult to break.
  304.  
  305.  
  306. --Strengthening Cyphers
  307.  
  308.  
  309. -Removing word and sentence boundaries
  310.  
  311. A simple way to complicate decypherment of a cyphertext is to remove all
  312. spacing and punctuation.  This makes it more difficult to perform a frequency
  313. analysis on letter positions.  However, it is possible to make reasonable
  314. guesses as to word positions once yoy begin to study the document.  Another
  315. method is to break the cyphertext into fixed blocks.  For example after every
  316. four letters a space is placed.
  317.  
  318. The previous cypher text would appear as this:
  319.  
  320. nuoicpokdttwccjwlompjwbsnuolokdbmeddbqjdenuotolnqwocm.
  321.  
  322.  
  323. or this:
  324.  
  325. nuoi cpok dttw ccjw lomp jwbs nuol okdb medd bqjd enuo toln qwoc m
  326.  
  327.  
  328. You will notice that the above line ends with a single character.  This gives
  329. away the end of the text and would be better served by the placement of nulls,
  330. or garbage characters.  The above line becomes:
  331.  
  332. nuoi cpok dttw ccjw lomp jwbs nuol okdb medd bqjd enuo toln qwoc mhew
  333.  
  334. 'hew' will decypher to 'qmi' which will clearly appear to be nulls to the
  335. intended recipient.
  336.  
  337.  
  338. -Nulls
  339.  
  340. Nulls are characters used in messages which have no meanings.  A message could
  341. be sent which uses numbers as nulls. This makes decypherment more difficult as
  342. part of the message has no meaning.  Until the decypherer realizes this, he
  343. may have a hard time of solving the message.
  344.  
  345.  
  346. -Polyphony
  347.  
  348. Another method that can be applied is the use of polyphones.  Polyphones are
  349. simply using a piece of cyphertext to represent more than one piece of
  350. plaintext.  For example a cyphertext 'e' may represent an 'a' and a 'r'.  This
  351. does complicate decypherment and may result in multiple messages.  This is
  352. dangerous as these messages are prone to errors and may even decypher into
  353. multiple texts.
  354.  
  355. A new cyphertext alphabet would be
  356.  
  357. Cyphertext alphabet    A B C D E F G H I J L N P
  358. Plaintext alphabet    Z X U S Q O M K H N R V W
  359.             B D F G I A C E L P J T Y
  360.  
  361. Our old plaintext message becomes
  362.  
  363. nih aich gfp peii ledh bclejd nih dhgfjb gffj clfg nih phdn cehib
  364.  
  365. This decypherment becomes very tricky for someone to accomplish.  Having some
  366. knowledge of the text would be a great help.
  367.  
  368. If it appears that very few letters are being used in a document then you may
  369. wish to suspect the use of polyphones within a document.
  370.  
  371.  
  372. -Homophones
  373.  
  374. Homophones are similar to polyphones except that there is more than one
  375. cyphertext letter for every plaintext letter.  They are useful to use in that
  376. they can reduce the frequencies of letters in a message so that an analysis
  377. yields little information.  This is very easy to do with bipartite
  378. substitution cyphers.  For example:
  379.  
  380.          a b c d e
  381.        a a b c d e
  382.        b f g h i j
  383.        c k l m n o
  384.        d p q r s t
  385.        e u v w x y
  386.        f z * * * *
  387.  
  388. *(fb, fc, fd, fe are NULLS)
  389.  
  390. We can add homophones to the message like this:
  391.  
  392.           a b c d e
  393.  
  394.  i h g a  a b c d e
  395.    k j b  f g h i j
  396.    n l c  k l m n o
  397.    o m d  p q r s t
  398.      p e  u v w x y
  399.        f  z * * * *
  400.  
  401. The optimal way to set up these homophones is to calculate the frequency of
  402. appearance in the natural language you are using of each row of letters.
  403. Homophones should be added so that the cyphertext appearance of each homophone
  404. is reduced to a level where frequency analysis would yield little information.
  405.  
  406.  
  407. -Code Words
  408.  
  409. One final method which can be used is that of code words.  Simply replace
  410. important words in the plaintext with code words which represent another word.
  411. For example the nonsense plaintext that has been chosen for this document could
  412. actually mean:
  413.  
  414.  
  415. The blue cow will rise during the second moon from the west field.
  416.  
  417. The king is angry and will attack in two weeks with the 1st calvary by way of
  418. the foothills.
  419.  
  420. blue is angry
  421. cow is king
  422. rise is attack
  423. second is two weeks
  424. moon is 1st calvary
  425. west field stands for some foothills on the west side of the kingdom.
  426.  
  427.  
  428. Throughout this document I have mentioned frequency analysis of english
  429. documents.  This is a fairly tedious task to do by hand, and so I am
  430. developing software to aid in frequency analysis of documents.  I will be
  431. making it available via my website at http://www.cu-online.com/~jwthomp/ on
  432. Monday, September 8th.  Please watch for it in the Cryptography section.
  433.  
  434.  
  435. Ok, now to try your hand at a few cyphertexts..
  436.  
  437. This one has to do with war.
  438. 1)
  439. kau noelb'd oerf xmtt okkopw ok qoxb euoqf kau kurhtoe wbmcakds, obq dkemwu amd
  440. podktu xamtu xu altq amr
  441.  
  442.  
  443. This one is an excerpt from a technical document.
  444. 2)
  445. etdsalwqs kpjsjljdq gwur orrh frurdjkrf sj qtkkjps npjtk ljeethalwsajhq
  446. sgrqr kpjsjljdq tqr w jhr sj ewhy kwpwfane ijp spwhqeaqqajh sykalwddy tqahn
  447. ldwqq f ahsrphrs kpjsjljd wffprqqrq sj qkrlaiy qkrlaial etdsalwqs npjtkq
  448.  
  449.  
  450. Mail me your answers and I'll put the first person who solves each cypher in
  451. the next Phrack.
  452.  
  453. In fact, I would enjoy seeing some participation in this for the next Phrack.
  454. After reading this, I welcome the submission of any "Monoalphabetic" cypher
  455. based on the discussions of this article.  Please do not yet submit any
  456. polyalphabetic cyphers (Next article).  When submitting to me, please send me
  457. two letters.  The first mail should include only the encyphered text.  Make
  458. sure it is enough so that a reasonable examination can be made of the cypher.
  459. This first mail should have a subject "Cyphertext submission".  If you are
  460. using a method of encypherment not found in this article, please enclose a
  461. brief description of the type of method you used.  Follow this mail up with
  462. another entitled "Cyphertext Solution" along with a description of the
  463. encyphering method as well as the key or table used.
  464.  
  465. I will select a number of these texts to be printed in the next Phrack, where
  466. readers may have a chance at solving the cyphers.  The reason I ask for two
  467. seperate mailing is that I will want to take a crack at these myself.  Finally,
  468. the names of individuals will be placed in the following phrack of the first
  469. to solve each cypher, and whomever solves the most cyphers prior to the next
  470. Phrack release (real name or pseudonym is fine).
  471.  
  472.  
  473. Please mail all submissions to jwthomp@cu-online.com
  474.  
  475. I welcome any comments, suggestions, questions, or whatever at
  476. jwthomp@cu-online.com
  477.  
  478.  
  479. ----[  EOF
  480.