-- RSA süsteemi parameetrid

p,q,n,phin,e,d	:: Integer

p		= 41
q		= 67
n		= p*q 		-- = 2747
phin		= (p-1)*(q-1)	-- = 2640
e		= 19
d		= 139		-- =e^{-1} mod phi(n)

-- Funktsioonid encryptNr ja decryptNr realiseerivad krüpteerimise numberkujul

encryptNr	:: Integer -> Integer
decryptNr	:: Integer -> Integer

cryptNr		:: Integer -> Integer -> Integer

cryptNr a x	= mod (x^a) n

encryptNr 	= cryptNr e
decryptNr 	= cryptNr d

-- Funktsioonid encrypt ja decrypt realiseerivad krüpteerimise tähepaaridel

encrypt		:: (Char,Char) -> Integer
decrypt		:: Integer -> (Char,Char)

encrypt 	= encryptNr.charPairToNr
decrypt 	= nrToCharPair.decryptNr

-- Funktsioon charPairToNr teeb tähepaarist arvu

charPairToNr	:: (Char,Char) -> Integer

charPairToNr (a,b) = toInteger(100*(ord a - 96) + (ord b - 96))

-- Funktsioon nrToCharPair teeb arvust tähepaari

nrToCharPair	:: Integer -> (Char,Char)

nrToCharPair i 	= (a,b)
		     where 
		   	a = chr((div (toInt i) 100)+96)
			b = chr((mod (toInt i) 100)+96)
			
-- 

inv	:: Int -> Int
inv a	= mod (a*19) 216

