module Data where
import DiscretLog
import Fourier
import Elliptic
import Data.Complex

-- 2 is generator of F_59
-- Prelude> filter (\x -> x == 2 ) $ map (\x -> mod (2^x) 59) [1..59]
-- [2,2]
-- Prelude> mod (2^19) 59
-- 14


a=2
b=14
p=59
m :: Integer
m=64
lts=64

c = Curve (-7) 10 97
g = Point 96 93 c
aa = Point 37 35 c


grid2print :: (Show a, Show b, Show c) => [(a,b,c)] -> [[Char]]
grid2print = map printtriple where
    printtriple :: (Show a, Show b, Show c) => (a,b,c) -> [Char]
    printtriple (x, y, z) = show x ++ " " ++ show y ++ " " ++ show z    

grid2grid :: (Num a, Eq a, Show c) => a -> [(b,a,c)] -> [Char]
grid2grid a xs = foldl (\z x -> z ++ show x ++ "\t" ) "" $ map (\(_,_,x) -> x ) $ 
                 filter (\(_,x,_) -> x == a ) xs 

-- Original data
--data0 = applygrid a b p m

-- Original data to print
--pdata0 = grid2print data0
--pgdata0 = map (\x -> grid2grid x data0) [0 .. m - 1]

val=g
data0 = map (\(x,y) -> (x,y, (fromInteger x .*. aa) .+. (fromInteger y .*. g))) $ grid m
data1 = map (\(x,y,z)->(fromIntegral x, fromIntegral y,if z == val then 1 else 0)) data0

pdata1 = grid2print data1
pgdata1 = map (\x -> grid2grid x data1) [0 .. m - 1]


data2 = map (\(x,y,z) -> (x, y, (magnitude z)/256)) $ fourier lts data1
pdata2 = grid2print data2
pgdata2 = map (\x -> grid2grid x data2) [0 .. m - 1]
