From cdcd1370ad9a9afbc61a9e71eb558710fb06e470 Mon Sep 17 00:00:00 2001 From: Benjamin Maurer <maurer.benjamin@gmail.com> Date: Sat, 11 Jun 2022 16:57:29 +0200 Subject: [PATCH] real/rsa run-time adjusted. Increased input size and added argument for iteration count. Run-times were: 0.095s/0.651s/3.257s Are now: 0,145s/1,551s/8,064s --- real/rsa/Main.hs | 4 +- real/rsa/Makefile | 4 + real/rsa/rsa.faststdin | 6 + real/rsa/rsa.faststdout | 200 ++++++++++++++++---------------- real/rsa/rsa.slowstdout | 150 ++++++++++++++++++++++++ real/rsa/rsa.stdin | 66 +++++++++++ real/rsa/rsa.stdout | 250 ++++++++++++++++++++++++---------------- 7 files changed, 479 insertions(+), 201 deletions(-) diff --git a/real/rsa/Main.hs b/real/rsa/Main.hs index d9234319..45d39681 100644 --- a/real/rsa/Main.hs +++ b/real/rsa/Main.hs @@ -7,8 +7,10 @@ import System.Environment import NofibUtils main = do + (iters:_) <- getArgs + let n = read iters :: Int input <- getContents - replicateM_ 100 $ do + replicateM_ n $ do input' <- salt input print (hash (encrypt 2036450659413645137870851576872812267542175329986469156678671505255564383842535488743101632280716717779536712424613501441720195827856504007305662157107 387784473137902876992546516170169092918207676456888779623592396031349415024943784869634893342729620092877891356118467738167515879252473323905128540213 diff --git a/real/rsa/Makefile b/real/rsa/Makefile index cf44ea39..0ff7b5f9 100644 --- a/real/rsa/Makefile +++ b/real/rsa/Makefile @@ -3,3 +3,7 @@ include $(TOP)/mk/boilerplate.mk -include opts.mk include $(TOP)/mk/target.mk +FAST_OPTS = 100 +NORM_OPTS = 150 +SLOW_OPTS = 250 + diff --git a/real/rsa/rsa.faststdin b/real/rsa/rsa.faststdin index 78be4830..51a999a3 100644 --- a/real/rsa/rsa.faststdin +++ b/real/rsa/rsa.faststdin @@ -5,3 +5,9 @@ where encrypt, decrypt :: Integer -> Integer -> String -> String encrypt n e = unlines . map (show . power e n . code) . collect (size n) decrypt n d = concat . map (decode . power d n . read) . lines + +-------- Converting between Strings and Integers ----------- + +code :: String -> Integer +code = foldl accum 0 + where accum x y = (128 * x) + fromIntegral (fromEnum y) diff --git a/real/rsa/rsa.faststdout b/real/rsa/rsa.faststdout index bae373e7..41bebc3c 100644 --- a/real/rsa/rsa.faststdout +++ b/real/rsa/rsa.faststdout @@ -1,100 +1,100 @@ -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 -7070291556905191903 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 +18864594872723566 diff --git a/real/rsa/rsa.slowstdout b/real/rsa/rsa.slowstdout index db757853..8f7dfba7 100644 --- a/real/rsa/rsa.slowstdout +++ b/real/rsa/rsa.slowstdout @@ -98,3 +98,153 @@ 5782777958546550349 5782777958546550349 5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 +5782777958546550349 diff --git a/real/rsa/rsa.stdin b/real/rsa/rsa.stdin index 17d04623..cefe34c8 100644 --- a/real/rsa/rsa.stdin +++ b/real/rsa/rsa.stdin @@ -69,3 +69,69 @@ sqr x = x * x This module imports the contents of Densematrix and exports some of the functions renaming many of them for use by Matrix. The original %include statement(from Matrix) is left as a comment at the foot of this file. + +\begin{code} + +module AbsDensematrix(Block,Vec,bmult,bvecmult,vecbmult,vecdot,vecnorm, + vecouter,badd,bsub,vecadd,vecsub,bsize,vecsize,bneg, + bxpose,bident,vecneg,svecmult,mkblock,bswaprow,bswapcol, + bdroprow,bgetrow,bgetcol,bsubscript,vecsubscript,bupdate, + vecupdate,vechd,vectl,mergevecs,binverse,showblock, + showvec, mkvec,mkrvec,vecpart,update2,veclist,matlist) + where + + +import Densematrix + +type Block = Matrix +type Vec = Vector + +bmult = mmult +bvecmult = matvecmult +vecbmult = vmmult +vecdot = vdot + +vecnorm = norm +vecouter = vouter + +badd = madd +bsub = msub +vecadd = vadd +vecsub = vsub + +bsize = msize +vecsize = vsize + +bneg = mneg +bxpose = mxpose +bident = mident + +vecneg = vneg +svecmult = svmult + +mkblock = mkmat + +bswaprow = swaprow +bswapcol = swapcol + +bdroprow = droprow +bgetrow = getrow +bgetcol = getcol + +bsubscript = subscript +vecsubscript = vsubscript + +bupdate = update +vecupdate = vupdate + +vechd = vhd +vectl = vtl + +mergevecs = mergevectors + +binverse = minverse + +showblock = showmatrix +showvec = displayvector + +\end{code} diff --git a/real/rsa/rsa.stdout b/real/rsa/rsa.stdout index fb808adf..9d87bd89 100644 --- a/real/rsa/rsa.stdout +++ b/real/rsa/rsa.stdout @@ -1,100 +1,150 @@ --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 --8068683040965007191 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 +815920302423014274 -- GitLab