Commit c94481e9 authored by Simon Marlow's avatar Simon Marlow

use parBuffer

parent 32b922c2
{-# LANGUAGE BangPatterns #-}
module Rsa (encrypt, decrypt, makeKeys)
where
import Control.Parallel
encrypt, decrypt :: Integer -> Integer -> String -> String
encrypt n e = unlines . parmap (show . power e n . code) . collect (size n)
decrypt n d = concat . parmap (decode . power d n . read) . lines
encrypt n e = unlines . parBuffer 100 . map (show . power e n . code) . collect (size n)
decrypt n d = concat . parBuffer 100 . map (decode . power d n . read) . lines
-------- Parallelism -----------
parBuffer :: Int -> [a] -> [a]
parBuffer n xs = return xs (start n xs)
where
return (x:xs) (y:ys) = y `par` (x : return xs ys)
return xs [] = xs
start !n [] = []
start 0 ys = ys
start !n (y:ys) = y `par` start (n-1) ys
parmap :: (String -> String) -> [String] -> [String]
parmap f [] = []
parmap f (x:xs) = fx `par` (pmxs `par` (fx:pmxs))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment