Skip to content

Instantly share code, notes, and snippets.

@TinnedTuna
Created September 14, 2013 21:38
Show Gist options
  • Save TinnedTuna/6565880 to your computer and use it in GitHub Desktop.
Save TinnedTuna/6565880 to your computer and use it in GitHub Desktop.
A basic PRNG based on the Heys' cipher
import HeysCipher
import Data.ByteString as B
import Data.Bits
import Data.Word
import System.Environment
main = do
[arg, filename] <- getArgs
let bytes = read arg :: Integer
let randomBytes = (B.pack . genBytes . read) arg
B.writeFile filename randomBytes
genBytes :: Int -> [Word8]
genBytes count
| count <= 0 = []
| otherwise = rWord8_first : rWord8_last : genBytes (count - 2)
where
rWord16 = crypt (0,0,0) (fromIntegral count)
rWord8_first = (fromIntegral :: Word16 -> Word8) rWord16 `shiftR` 8
rWord8_last = (fromIntegral :: Word16 -> Word8) rWord16 .&. 0xff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment