Skip to content

mavxg/chaocipher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

*Cracking exhibit 1*

open ghci

> :l chaocipher.hs

> pt <- readFile "exhibit-1.pt.txt"
> ct <- readFile "exhibit-1.ct.txt"

Start cracking from somewhere with a fair amount of repetition

> take 2 $ crack (take 50 $ drop 11998 ct) (drop 11998 pt)

you will get back a single key

> rewind (Chao "I  AE QS  DW PH R GOC NTBL" "QYGWJZSKLHP TVU XANECFOIDM") (take 50 $ drop 11998 ct)

now use the key you get back to propagate forward

> take 2 $ crack' (take 1500 $ drop 11998 ct) (drop 11998 pt) (Chao "A   SHIN PTCGB ODEWQ   RL " "XQCTVIGYJHNAM WZEOUFPDSL K")

the key you get back will have a single space on the left ring put the X in it

> rewind (Chao "EHSGILWRMTCYBXKJQUFPADZNOV" "JSRBYWFXOTDLMGVPUKNQACIZHE") (take 1500 $ drop 11998 ct)

you can now play to the end to find out what the last ?????? in the plain text is

> decode (Chao "AYFZSHINJPTCGBUODEWQVXKRLM" "XQCTVIGYJHNAMBWZEOUFPDSLRK") (drop 11998 ct)

you can also rewind the key to the begining (Thanks Moshe Rubin for the typo correction in the ct file)

> rewind (Chao "AYFZSHINJPTCGBUODEWQVXKRLM" "XQCTVIGYJHNAMBWZEOUFPDSLRK") (take 119998 ct)

this gives you the orriginal key used (Chao "AYZNBQDSEFGHLWIKCMOPRTUVJX" "CPEDQRSTIXYLMOZABFVGUHWJKN")

now you can decode the whole message

> decode (Chao "AYZNBQDSEFGHLWIKCMOPRTUVJX" "CPEDQRSTIXYLMOZABFVGUHWJKN") pt

note: you will get an error back on the final newline character.

*Cracking Exhibit 4*

pt <- readFile "exhibit-4.01.last.88.removed.pt.txt"
ct <- readFile "chaocipher-exhibit-4.ct.txt"

let pt' = [x | x <- pt, x /= '\n']

-- try first to find for a small amount of plain text 
-- where there are some nice repeated characters (like SSESSTHESITU...)
-- Because the cipher text is not nicely aligned to the plain text
-- you will need to try various offsets until you find it line up

let f n = take 2 $ crack (take 55 $ drop (110 + n) ct) (drop 110 pt')

map (\x -> (x,f x)) [0..50] --try all the offsets from 0 to 50 and interupt if you see a solution

--one of these will have a single key and if you are lucky the rest will have no solutions

rewind (*** single key you just found ***) (take 55 $ drop (110 + n) ct)

take 2 $ crack' (take 60 $ drop (110 + n) ct) (drop 110 pt') (*** key you got from rewind ***)

rewind (*** the key just returned ***) (take (155+110+n) ct)

decode (*** the key you found here ***) ct

let (ct2,_) = encode (*** the key you found here ***) $ (take 20 pt2) ++ pt'

-- find the typo in the cipher text

length $ takeWhile (\(a,b) -> a == b) $ zip ct ct2 --will return 1668

take 10 $ drop 1668 ct
take 10 $ drop 1668 ct2

let ct' = (take 1668 ct) ++ "H" ++ (drop 1669 ct) --fix the typo in the cipher text
--you can find the correct value easily because you have the known plaintext for this point
--if you did not then you might have to start guessing where the typo was when your output
--started to go wild

decode (*** key you found earlier ***) ct'

-- you now have your plain text for exhibit 4

About

Chaocipher crack in haskell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published