2020/10/3 CS – Aigme 1: Raib Table ih Hakell
Aige 1: Raib Table ih Hakell
Introdction
The Pble
Raib Table
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
1/7
2020/10/3 CS – Aigme 1: Raib Table ih Hakell
Cacking a Pad ih a Rainb Table
Reicin
“abcd” “abc”
n
The Modle
RainboAssign
import RainboAssign
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
2/7
2020/10/3 CS – Aigme 1: Raib Table ih Hakell
tpe Hash = Int32
tpe Passd = String
Hash Int32 Int Int32 Int fromEnum
Sstem.Random apt-get install libghc-random-dev
cabal install random
Parameers
pLength, nLetters, idth, height :: Int
filename :: FilePath
pLength = 8
nLetters = 5
idth = 40
height = 1000
filename = “table.tt” — filename to store the table
— length of each passord
— number of letters to use in passords: 5 -> a-e
— length of each chain in the table
— number of “ros” in the table
Hashing & Redcing
pHash pReduce
pHash pHash RainboAssign pHash Passd – > Hash
pReduce
pReduce h1/=h2 pReduce h1 /=
pReduce h2
n n
“abcdeabc”
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
3/7
2020/10/3 CS – Aigme 1: Raib Table ih Hakell
pHash
nLetters
pLength
pReduce pReduce 1726491528 == “eacbcbad”
RainboAssign toLetter toLetter 3 == ‘d’
nLetters pReduce (-1726491528::Hash) == “aecdcdec”
nLetters take
pReduce The Ma Daa Sce
Data.Map Data.Map map lookup
import qualified Data.Map as Map
Map. Map.kes
A B [(A,B)] Map.fromList
Bilding he Table
rainboTable Map.Map Hash Passd
*Main> :t rainboTable
rainboTable :: Int -> [Passd] -> Map.Map Hash Passd
*Main> rainboTable 0 [“abcdeabc”]
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
4/7
2020/10/3 CS – Aigme 1: Raib Table ih Hakell
fromList [(1726491528,”abcdeabc”)]
*Main> rainboTable 1 [“abcdeabc”]
fromList [(1477708406,”abcdeabc”)]
*Main> rainboTable 40 [“abcdeabc”]
fromList [(-1993856529,”abcdeabc”)]
*Main> rainboTable 40 [“abcdeabc”, “aabbccdd”, “eeeeeeee”]
fromList [(-1993856529,”abcdeabc”),(1781092264,”aabbccdd”),(2135711886,”eeeeeeee”)]
*Main> rainboTable 2 [“dccdecee”,”cdeccaed”,”acbcaeec”,”eeeeaebd”,”ccdccbeb”]
fromList [(-1862546954,”ccdccbeb”),(-716915723,”cdeccaed”),(1305042273,”acbcaeec”),(162979405
Ceaing, Reading, and Wiing Table
buildTable rainboTable
*Main> buildTable rainboTable nLetters pLength idth height
fromList [(-1860304949,”bddaaaeb”),(-1422325927,”accabecb”),(-857324890,”aaaababb”),(45426764
buildTable IO Map.Map IO IO
RainboAssign buildTable generateTable
generateTable :: IO ()
generateTable = do
table <- buildTable rainboTable nLetters pLength idth height
riteTable table filename
readTable readTable IO
test1 = do
table <- readTable filename
return (Map.lookup 0 table)
Reeing Hahe
pReduce pHash
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
5/7
7
3
2020/10/3 CS - Aigme 1: Raib Table ih Hakell
findPassord
Mabe Passd Mabe Nothing Just Nothing Data.Mabe Mabe
*Main> let table = rainboTable 40 [“abcdeabc”, “aabbccdd”, “eeeeeeee”]
*Main> findPassord table 40 1726491528
Just “abcdeabc”
*Main> findPassord table 40 (-206342227)
Just “dbddecab”
*Main> findPassord table 40 1726491529
Nothing
*Main> findPassord table 40 0
Nothing
More Examples
Experimenting
n
test2 :: Int -> IO ([Passd], Int)
test2 n = do
table <- readTable filename
ps <- randomPassords nLetters pLength n
let hs = map pHash ps
let result = Mabe.mapMabe (findPassord table idth) hs
return (result, length result)
mapMabe Data.Mabe
idth nLetters pLength
height
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
6/7
2020/10/3 CS - Aigme 1: Raib Table ih Hakell
nLetters pLength
Notes and Summar
pReduce
rainboTable findPassord
::
-Wall
Comiling Yo Code
main :: IO ()
main = do
generateTable
res <- test2 10000
print res
ghc -O2 --make -Wall rainbo.hs
./rainbo
Wai ae m aod eall ha inece?
Submitting
h://c.f.ca/2020fa-cm-383-d1/age/Aig1
7/7