import System.Environment
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import System.Random
main = do
args <- getArgs
glitched <- randomReplaceByte imageFile
let glitchedFileName = mconcat ["glitched_", fileName]
intToChar int
= toEnum safeInt
where safeInt
= int `
mod`
255
intToBC
:: Int -> BC
.ByteString
intToBC int = BC.pack [intToChar int]
replaceByte
:: Int -> Int -> BC
.ByteString
-> BC
.ByteString
replaceByte loc charVal bytes = mconcat [before,newChar,after]
where (before
,rest
) = BC
.splitAt loc bytes
newChar = intToBC charVal
randomReplaceByte
:: BC
.ByteString
-> IO BC
.ByteString
randomReplaceByte bytes = do
let bytesLength
= BC
.length bytes
location <- randomRIO (1, bytesLength)
charVal <- randomRIO (0, 255)
return (replaceByte location charVal bytes
)
CmltcG9ydCBTeXN0ZW0uRW52aXJvbm1lbnQKaW1wb3J0IHF1YWxpZmllZCBEYXRhLkJ5dGVTdHJpbmcgYXMgQgppbXBvcnQgcXVhbGlmaWVkIERhdGEuQnl0ZVN0cmluZy5DaGFyOCBhcyBCQwppbXBvcnQgU3lzdGVtLlJhbmRvbQoKbWFpbiA6OiBJTyAoKQptYWluID0gZG8KICAgIGFyZ3MgPC0gZ2V0QXJncwogICAgbGV0IGZpbGVOYW1lID0gaGVhZCBhcmdzCiAgICBpbWFnZUZpbGUgPC0gQkMucmVhZEZpbGUgZmlsZU5hbWUKICAgIGdsaXRjaGVkIDwtIHJhbmRvbVJlcGxhY2VCeXRlIGltYWdlRmlsZQogICAgbGV0IGdsaXRjaGVkRmlsZU5hbWUgPSBtY29uY2F0IFsiZ2xpdGNoZWRfIiwgZmlsZU5hbWVdCiAgICBCQy53cml0ZUZpbGUgZ2xpdGNoZWRGaWxlTmFtZSBnbGl0Y2hlZAogICAgcHJpbnQgImFsbCBkb25lIgoKCmludFRvQ2hhciA6OiBJbnQgLT4gQ2hhcgppbnRUb0NoYXIgaW50ID0gdG9FbnVtIHNhZmVJbnQKICAgIHdoZXJlIHNhZmVJbnQgPSBpbnQgYG1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