Monday, July 29, 2013

MITRE 2013 Writeup : Cryptography 200

Cryptography 200 was an encrypted text file.  At first glance it's not hard to notice that some patterns repeat:

zhdgduknsardyoeyhdxlnikgullksaeshxaqzhtxcntamjoxrehgsbgncglhtbnnel
oahotgkrdjhdgddjldggtkihoabgsdufhjemziseiuzhdhoriolheuglkkylesskrx
btgkfhbenxammeooprbisnelgnvotgzhdzwhytdjlhvvhotgkacbemzuqkoezhdhlt
kczxbttckkvhoisnezjvdtttxenltgksokcjrechamjiwzhdgduknsard

which suggests a repeating encryption pattern of some sort (short, repeating XOR cipher turned out to not be the case).  The text is also rather long, suggesting that frequency analysis is possible.

Frequency analysis:

n (110) occurs 7.04927334838747 %
t (116) occurs 6.216663771640322 %
s (115) occurs 6.035319321405825 %
k (107) occurs 5.705749522320653 %
z (122) occurs 5.688147762144635 %
g (103) occurs 5.573273116785363 %
d (100) occurs 5.568177870418621 %
e (101) occurs 5.521162642580047 %
o (111) occurs 5.445428753401656 %
r (114) occurs 5.301140640379828 %
h (104) occurs 5.066759307509698 %
a (97) occurs 4.228822882288229 %
u (117) occurs 3.9571536100978517 %
m (109) occurs 3.7324995657460485 %
i (105) occurs 3.145619825140409 %
c (99) occurs 3.0988361994094147 %
l (108) occurs 2.954548086387586 %
y (121) occurs 2.8218400787447164 %
x (120) occurs 2.638642811649586 %
q (113) occurs 2.2442244224422443 %
v (118) occurs 1.7567019859880726 %
j (106) occurs 1.7418794511030051 %
b (98) occurs 1.6527126396850211 %
f (102) occurs 1.3185107984482658 %
w (119) occurs 0.9365989230501998 %
p (112) occurs 0.6003126628452319 %


Comparison with an actual frequency list doesn't yield any results (and substituting the letters in by frequency yields gibberish).

It turns out there's a way to solve Vigenère ciphers by finding repetitions in the text and retrieving the number of letters between them.  Vigenère ciphers are essentially interlaced Caesar ciphers.  Ex:

Key:           abcd
Message:       mexicandanceparty
Extended Key:  abcdabcdabcdabcda

Encrypted Msg: mfzlcbpgaoehpbtwy

where each letter of the message is added to that of the key (A = 0, B = 1, etc., so mexicandanceparty + abcdabcdabcdabcda = m, mexicandanceparty + abcdabcdabcdabcda = f, and so on).

The weakness in a Vigenère cipher is that since the key is repeated for the length of the message, if your message has repeated words, there's a chance that the encrypted message will have repetitions as well.  Ex:

Key:           abcd
Message:       whatyouseeiswhatyouget
Extended Key:  abcdabcdabcdabcdabcdab
Encrypted Msg: wicwypwvefkvwicwypwjeu

There's 12 letters from the above example between the first letters of the words (wicwypwvefkv = 12 letters) so we know that since the key repeats, the length of the key must be a factor of this (a length of 1, 2, 3, 4, 6, or 12).  With enough repetitions, you can figure out the length of the key.  And using a dictionary of words, it's possible to algorithmically determine what the key is, similar to how you'd solve a cryptogram.

This is all ~ super great ~ because not only does our text have repetitions but it is ridiculously long and fits both requirements for a solvable Vigenère cipher.  Feeding it through this lazy person cipher solver yields the key (gaz) and the decrypted text:

theadventuresofsherlockholmesbysirarthurconandoyleiascand
alinbohemiaiitheredheadedleagueiiiacaseofidentityivthebos
combevalleymysteryvthefiveorangepipsvithemanwiththetwiste
dlipviitheadventureofthebluecarbuncleviiitheadventureofth
especkledbandixtheadventureoftheengineersthumbxtheadventu
reofthenoblebachelorxitheadventureoftheberylcoronetxiithe
adventureofthecopperbeechesadventureiascandalinbohemiaito
sherlockholmessheisalwaysthewomanihaveseldomheardhimmenti
onherunderanyothernameinhiseyessheeclipsesandpredominates
thewholeofhersexitwasnotthathefeltanyemotionakintolovefor
ireneadlerallemotionsandthatoneparticularlywereabhorrentt
ohiscoldprecisebutadmirablybalancedmindhewasitakeitthemos
tperfectreasoningandobservingmachinethattheworldhasseenbu
tasaloverhewouldhaveplacedhimselfinafalsepositionhenevers
pokeoft..................................................
............et cetera et cetera .........................
...theflagismcafivezerofivetwofourefourseven.............

MCA-50524E47

No comments:

Post a Comment