Created
September 14, 2013 21:38
-
-
Save TinnedTuna/6565880 to your computer and use it in GitHub Desktop.
A basic PRNG based on the Heys' cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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