Created
August 16, 2013 18:22
-
-
Save qoelet/6252260 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
-- implementing a simple 2 key encrypt/decrypt | |
-- assuming a n-vector p (message) | |
-- generate a random n-vector v1 (key1) | |
-- and n-vector v2 (via subtract v1 from p) | |
subV :: Integer -> Integer -> Integer | |
subV x y | x == y = 0 | |
| otherwise = 1 | |
encode :: [Integer] -> [Integer] -> [Integer] | |
encode [] _ = [] | |
encode (p:ps) (v1:v1s) = [subV p v1] ++ encode ps v1s | |
-- e.g. | |
-- Prelude> let p = [1,0,1,0,1,1,1] | |
-- Prelude> let v1 = [0,0,0,1,0,1,0] | |
-- Prelude> let v2 = encode p v1 | |
-- Prelude> v2 | |
-- [1,0,1,1,1,0,1] | |
-- Prelude> p == encode v2 v1 | |
-- True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment