Skip to content

Instantly share code, notes, and snippets.

@elrikdante
Created January 8, 2020 03:13
Show Gist options
  • Save elrikdante/6149184a53f5e59095fa08698e54ed1f to your computer and use it in GitHub Desktop.
Save elrikdante/6149184a53f5e59095fa08698e54ed1f to your computer and use it in GitHub Desktop.
./src/Mnemonic.hs
Magical Seed Phrase:
Line "consido"
Line "illis"
Line "invalesco"
Line "labor"
Line "laetabilis"
Line "Marceniense"
Line "metuo"
Line "pectus"
Line "provisor"
Line "sanitas"
Line "utpote"
Line "volo"
elrikdante@elrikgroup-labbook SaladQL % ./src/Mnemonic.hs
Magical Seed Phrase:
Line "adipiscor"
Line "dominatus"
Line "fleo"
Line "impunitus"
Line "mei"
Line "relaxo"
Line "scientia"
Line "sono"
Line "territo"
Line "tum"
Line "valens"
Line "vulnus"
elrikdante@elrikgroup-labbook SaladQL %
#!/usr/bin/env stack
{- stack
--resolver nightly-2019-12-25
script
--package base
--package text
--package turtle
--package ordered-containers
--package containers
--package random
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Prelude hiding (FilePath)
import Turtle
import System.Random
import Data.IntMap
someFold :: Turtle.Fold Turtle.Line (Data.IntMap.IntMap Turtle.Line)
someFold = Turtle.Fold step begin end
where
step (int, imap) line =
let int' = succ int
in (int', Data.IntMap.union imap (Data.IntMap.singleton int' line))
begin = (0,Data.IntMap.empty)
end (int, imap) = imap
wordList = input "wordlist.latin"
wordRadix = 3479
randomInts :: Int -> System.Random.StdGen -> [Int]
randomInts 0 y = []
randomInts count stdGen = (fromIntegral value) : randomInts (count - 1) stdGen'
where (value, stdGen') = next stdGen
randomWordsMap :: Int -> System.Random.StdGen -> IO (IntMap Turtle.Line)
randomWordsMap count intg = do
words <- Turtle.fold wordList someFold
ints <- fmap (fmap (`mod` wordRadix)) (return $ randomInts count intg)
return (Data.IntMap.intersection words (Data.IntMap.fromList (zip ints (repeat (unsafeTextToLine mempty)))))
randomWords :: IntMap Turtle.Line -> [Turtle.Line]
randomWords = fmap snd . Data.IntMap.toList
twelve = 12
main :: IO ()
main = do
echo "Magical Seed Phrase:"
g <- getStdGen
indices <- randomWordsMap twelve g
Turtle.view (Turtle.select $ randomWords indices)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment