linux03[156](3.2)> wget -q http://www.macs.hw.ac.uk/~hwloidl/Courses/F21CN/Labs/f21cn.sh linux03[157](3.2)> source f21cn.sh linux03[158](3.2)> install_ghc_pkgs Installing GHC packages 'QuickCheck' and 'HaskellForMaths' ... ~ ~/Workspace ~/f21cn/HaskellForMaths-0.1.9 ~/f21cn ~/Workspace Configuring HaskellForMaths-0.1.9... Preprocessing library HaskellForMaths-0.1.9... Building HaskellForMaths-0.1.9... [ 1 of 28] Compiling Math.Algebra.Group.StringRewriting ( Math/Algebra/Group/StringRewriting.hs, dist/build/Math/Algebra/Group/StringRewriting.o ) [ 2 of 28] Compiling Math.Common.ListSet ( Math/Common/ListSet.hs, dist/build/Math/Common/ListSet.o ) [ 3 of 28] Compiling Math.Algebra.Group.PermutationGroup ( Math/Algebra/Group/PermutationGroup.hs, dist/build/Math/Algebra/Group/PermutationGroup.o ) [ 4 of 28] Compiling Math.Algebra.Group.SchreierSims ( Math/Algebra/Group/SchreierSims.hs, dist/build/Math/Algebra/Group/SchreierSims.o ) [ 5 of 28] Compiling Math.Combinatorics.Graph ( Math/Combinatorics/Graph.hs, dist/build/Math/Combinatorics/Graph.o ) [ 6 of 28] Compiling Math.Combinatorics.GraphAuts ( Math/Combinatorics/GraphAuts.hs, dist/build/Math/Combinatorics/GraphAuts.o ) [ 7 of 28] Compiling Math.Projects.Rubik ( Math/Projects/Rubik.hs, dist/build/Math/Projects/Rubik.o ) [ 8 of 28] Compiling Math.Common.IntegerAsType ( Math/Common/IntegerAsType.hs, dist/build/Math/Common/IntegerAsType.o ) [ 9 of 28] Compiling Math.Algebra.Commutative.Monomial ( Math/Algebra/Commutative/Monomial.hs, dist/build/Math/Algebra/Commutative/Monomial.o ) [10 of 28] Compiling Math.Algebra.Field.Base ( Math/Algebra/Field/Base.hs, dist/build/Math/Algebra/Field/Base.o ) [11 of 28] Compiling Math.Algebra.Commutative.MPoly ( Math/Algebra/Commutative/MPoly.hs, dist/build/Math/Algebra/Commutative/MPoly.o ) [12 of 28] Compiling Math.Algebra.Commutative.GBasis ( Math/Algebra/Commutative/GBasis.hs, dist/build/Math/Algebra/Commutative/GBasis.o ) [13 of 28] Compiling Math.Algebra.Field.Extension ( Math/Algebra/Field/Extension.hs, dist/build/Math/Algebra/Field/Extension.o ) [14 of 28] Compiling Math.Algebra.NonCommutative.NCPoly ( Math/Algebra/NonCommutative/NCPoly.hs, dist/build/Math/Algebra/NonCommutative/NCPoly.o ) [15 of 28] Compiling Math.Algebra.NonCommutative.GSBasis ( Math/Algebra/NonCommutative/GSBasis.hs, dist/build/Math/Algebra/NonCommutative/GSBasis.o ) [16 of 28] Compiling Math.Algebra.NonCommutative.TensorAlgebra ( Math/Algebra/NonCommutative/TensorAlgebra.hs, dist/build/Math/Algebra/NonCommutative/TensorAlgebra.o ) [17 of 28] Compiling Math.Projects.KnotTheory.LaurentMPoly ( Math/Projects/KnotTheory/LaurentMPoly.hs, dist/build/Math/Projects/KnotTheory/LaurentMPoly.o ) [18 of 28] Compiling Math.Projects.KnotTheory.Braid ( Math/Projects/KnotTheory/Braid.hs, dist/build/Math/Projects/KnotTheory/Braid.o ) [19 of 28] Compiling Math.Projects.KnotTheory.TemperleyLieb ( Math/Projects/KnotTheory/TemperleyLieb.hs, dist/build/Math/Projects/KnotTheory/TemperleyLieb.o ) [20 of 28] Compiling Math.Projects.KnotTheory.IwahoriHecke ( Math/Projects/KnotTheory/IwahoriHecke.hs, dist/build/Math/Projects/KnotTheory/IwahoriHecke.o ) [21 of 28] Compiling Math.Algebra.LinearAlgebra ( Math/Algebra/LinearAlgebra.hs, dist/build/Math/Algebra/LinearAlgebra.o ) [22 of 28] Compiling Math.Combinatorics.FiniteGeometry ( Math/Combinatorics/FiniteGeometry.hs, dist/build/Math/Combinatorics/FiniteGeometry.o ) [23 of 28] Compiling Math.Combinatorics.Design ( Math/Combinatorics/Design.hs, dist/build/Math/Combinatorics/Design.o ) [24 of 28] Compiling Math.Combinatorics.StronglyRegularGraph ( Math/Combinatorics/StronglyRegularGraph.hs, dist/build/Math/Combinatorics/StronglyRegularGraph.o ) [25 of 28] Compiling Math.Combinatorics.Hypergraph ( Math/Combinatorics/Hypergraph.hs, dist/build/Math/Combinatorics/Hypergraph.o ) [26 of 28] Compiling Math.Projects.RootSystem ( Math/Projects/RootSystem.hs, dist/build/Math/Projects/RootSystem.o ) [27 of 28] Compiling Math.Projects.ChevalleyGroup.Classical ( Math/Projects/ChevalleyGroup/Classical.hs, dist/build/Math/Projects/ChevalleyGroup/Classical.o ) [28 of 28] Compiling Math.Projects.ChevalleyGroup.Exceptional ( Math/Projects/ChevalleyGroup/Exceptional.hs, dist/build/Math/Projects/ChevalleyGroup/Exceptional.o ) Registering HaskellForMaths-0.1.9... Installing library in /u1/staff/hwloidl/.cabal/lib/HaskellForMaths-0.1.9/ghc-6.12.3 Registering HaskellForMaths-0.1.9... ~/f21cn ~/Workspace ~/f21cn/QuickCheck-2.4.1.1 ~/f21cn ~/Workspace Configuring QuickCheck-2.4.1.1... Preprocessing library QuickCheck-2.4.1.1... Building QuickCheck-2.4.1.1... [ 1 of 13] Compiling Test.QuickCheck.Exception ( Test/QuickCheck/Exception.hs, dist/build/Test/QuickCheck/Exception.o ) [ 2 of 13] Compiling Test.QuickCheck.Text ( Test/QuickCheck/Text.hs, dist/build/Test/QuickCheck/Text.o ) [ 3 of 13] Compiling Test.QuickCheck.State ( Test/QuickCheck/State.hs, dist/build/Test/QuickCheck/State.o ) [ 4 of 13] Compiling Test.QuickCheck.Gen ( Test/QuickCheck/Gen.hs, dist/build/Test/QuickCheck/Gen.o ) [ 5 of 13] Compiling Test.QuickCheck.Arbitrary ( Test/QuickCheck/Arbitrary.hs, dist/build/Test/QuickCheck/Arbitrary.o ) [ 6 of 13] Compiling Test.QuickCheck.Poly ( Test/QuickCheck/Poly.hs, dist/build/Test/QuickCheck/Poly.o ) [ 7 of 13] Compiling Test.QuickCheck.Modifiers ( Test/QuickCheck/Modifiers.hs, dist/build/Test/QuickCheck/Modifiers.o ) [ 8 of 13] Compiling Test.QuickCheck.Function ( Test/QuickCheck/Function.hs, dist/build/Test/QuickCheck/Function.o ) [ 9 of 13] Compiling Test.QuickCheck.Property ( Test/QuickCheck/Property.hs, dist/build/Test/QuickCheck/Property.o ) [10 of 13] Compiling Test.QuickCheck.Test ( Test/QuickCheck/Test.hs, dist/build/Test/QuickCheck/Test.o ) [11 of 13] Compiling Test.QuickCheck.Monadic ( Test/QuickCheck/Monadic.hs, dist/build/Test/QuickCheck/Monadic.o ) [12 of 13] Compiling Test.QuickCheck ( Test/QuickCheck.hs, dist/build/Test/QuickCheck.o ) [13 of 13] Compiling Test.QuickCheck.All ( Test/QuickCheck/All.hs, dist/build/Test/QuickCheck/All.o ) Registering QuickCheck-2.4.1.1... Installing library in /u1/staff/hwloidl/.cabal/lib/QuickCheck-2.4.1.1/ghc-6.12.3 Registering QuickCheck-2.4.1.1... ~/f21cn ~/Workspace You should now find 'QuickCheck' and 'HaskellForMaths' in the list below: QuickCheck-2.4.1.1 HaskellForMaths-0.1.9 ~/Workspace The exercises are in file caesar.hs: -rw-rw-r-- 1 hwloidl staff 8752 Sep 22 20:49 caesar.hs linux03[159](3.2)> ghci -package HaskellForMaths -package QuickCheck caesar.hs GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package extensible-exceptions-0.1.1.1 ... linking ... done. Loading package array-0.3.0.1 ... linking ... done. Loading package containers-0.3.0.0 ... linking ... done. Loading package filepath-1.1.0.4 ... linking ... done. Loading package old-locale-1.0.0.2 ... linking ... done. Loading package old-time-1.0.0.5 ... linking ... done. Loading package unix-2.4.0.2 ... linking ... done. Loading package directory-1.0.1.1 ... linking ... done. Loading package pretty-1.0.1.1 ... linking ... done. Loading package process-1.0.1.3 ... linking ... done. Loading package Cabal-1.8.0.6 ... linking ... done. Loading package bytestring-0.9.1.7 ... linking ... done. Loading package ghc-binary-0.5.0.2 ... linking ... done. Loading package bin-package-db-0.0.0.0 ... linking ... done. Loading package hpc-0.5.0.5 ... linking ... done. Loading package template-haskell ... linking ... done. Loading package ghc-6.12.3 ... linking ... done. Loading package time-1.1.4 ... linking ... done. Loading package random-1.0.0.2 ... linking ... done. Loading package QuickCheck-2.4.1.1 ... linking ... done. Loading package syb-0.1.0.2 ... linking ... done. Loading package base-3.0.3.2 ... linking ... done. Loading package HaskellForMaths-0.1.9 ... linking ... done. Loading package ffi-1.0 ... linking ... done. [1 of 1] Compiling Caesar ( caesar.hs, interpreted ) Ok, modules loaded: Caesar. *Caesar> let s0 = "a simple test" *Caesar> let c0 = encode 5 s0 Loading package haskell98 ... linking ... done. *Caesar> c0 "f xnruqj yjxy" *Caesar> crack c0 "a simple test" *Caesar> putStrLn (showtab 5) 0 1 2 3 4 0: 0 0 0 0 0 1: 0 1 2 3 4 2: 0 2 4 1 3 3: 0 3 1 4 2 4: 0 4 3 2 1 *Caesar> let x = (3 :: F5) *Caesar> let z = x^2 + 2*x + 1 *Caesar> let zz = (x+1)^2 *Caesar> x 3 *Caesar> z 1 *Caesar> zz 1 *Caesar> quickCheck (\ m n -> m<2 || n<2 || not (gcd m n == 1) || m^(euler n) `mod` n == 1) +++ OK, passed 100 tests. *Caesar> let p = primes!!17 *Caesar> let q = primes!!19 *Caesar> let n = p*q *Caesar> p 61 *Caesar> q 71 *Caesar> n 4331 *Caesar> let phi = (p-1)*(q-1) *Caesar> factors phi [2,3,5,7] *Caesar> let e = 11 *Caesar> gcd e phi 1 *Caesar> let d = mod_inv phi e *Caesar> d 2291 *Caesar> e*d `mod` phi 1 *Caesar> let enc m = m^e `mod` n *Caesar> let dec c = c^d `mod` n *Caesar> let m = 314 *Caesar> let c = enc m *Caesar> c 1168 *Caesar> dec c 314 *Caesar> quickCheck (\ m -> dec (enc (abs m)) == (abs m)) +++ OK, passed 100 tests.