From de3e8f9f3390e2b7b910ed603373cc41a1b3f983 Mon Sep 17 00:00:00 2001 From: andrew cooke Date: Wed, 8 Jul 2015 11:57:52 -0300 Subject: [PATCH] improving docs --- README.md | 59 +++++++++++-- src/IntModN.jl | 52 ++++-------- test/PTests.jl | 4 +- test/Tests.jl | 221 +++++++++++++++++++++++++------------------------ 4 files changed, 180 insertions(+), 156 deletions(-) diff --git a/README.md b/README.md index 2175c5d..664dae6 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ of crypto code. * [Examples](#examples) * [Types](#types) * [Integers Modulo N](#integers-modulo-n) + * [Polynomials](#polynomials) + * [Polynomials with Integral Coefficients](#polynomials-with-integral-coefficients) + * [Polynomials over GF(2)](#polynomials-over-gf-2) + Incomplete; pull requests welcome. @@ -125,23 +129,24 @@ integers). ### Integers Modulo N -`ZModN{N,I<:Integer} <: Residue` - abstract superclass for *integers* modulo +`ZModN{N,I<:Integer} <: Residue` - abstract superclass for integers modulo some value, where `N` is the modulus, and so typically an `Int` (yes, that's a integer as a *type*, not a value), and `I` -This has two concrete subclasses, because when `N` is a prime number we can do -more stuff. +This has two concrete subclasses, because when `N` is a prime number we can +define a multiplicative inverse. `ZRing{N, I<:Integer} <: ZModN{N,I}` - the general case. -`ZField{N, I<:Integer} <: ZModN{N,I}` - assumes that `N` is prime. +`ZField{N, I<:Integer} <: ZModN{N,I}` - assumes that `N` is prime, and so +includes division. These constructors can be used directly, but do not check that arguments are -consistent with assumptoins made in the code (primality, values within range, -etc). +consistent with assumptions made in the code (values within range, etc). -The associated functions `ZR()` and `ZF()` are more suitable for "normal" use, -and include support for factory functions: +The associated functions `ZR()` and `ZF()` are more suitable for "normal" use +(but still do not check primality for fields), and include support for factory +functions: ```julia julia> ZF(3, 5, UInt8) @@ -167,4 +172,40 @@ julia> @zring 4 begin 1x5 Array{IntModN.ZRing{4,Int64},2}: 1 2 3 0 1 ``` -` + +### Polynomials + +`Poly <: Residue` - abstract superclass for polynomials. All share some basic +conventions about accessing coefficients (with `[]`) and iterators. + +Note: Originally, the code used +[Polynomial.jl](https://github.com/vtjnash/Polynomial.jl), but that had some +weird design decisions so I wrote my own code. Since then, +[Polynomials.jl](https://github.com/Keno/Polynomials.jl) fixed some of the +issues, so at some point it may make sense to revert to that package. + +#### Polynomials With Integral Coefficients + +`ZPoly{I<:Integer} <: Poly` - a simple wrapper around an array of integral +coefficients (including `ZModN` subclasses). The coefficients are in the +"usual" order, so `[i]` gives the ith coefficient, and the leading coefficient +is always non-zero (or the array is empty). + +As with integers mod N, the constructor can be used directly, but it is +generally preferable to use `ZP()`, which has various forms. + +In addition, there's support for the natural syntax `x^n...` via `X()`: + +```julia +julia> x = X(ZF(2)) +ZP(IntModN.ZField{2,Int64},1,0) + +julia> x^3 + x +ZP(IntModN.ZField{2,Int64},1,0,1,0) +``` + +#### Polynomials over GF(2) + +`GF2Poly{I<:Unsigned} <: Poly` - specialized support for polynomials over +GF(2). Coefficients can be only 0 or 1, so we can use bit fields (integers) +for their values. diff --git a/src/IntModN.jl b/src/IntModN.jl index 53e42c2..956f7ea 100644 --- a/src/IntModN.jl +++ b/src/IntModN.jl @@ -209,12 +209,12 @@ end # --- supertype for all polynomial representations -abstract PModN <: Residue +abstract Poly <: Residue -endof(a::PModN) = length(a) -start(::PModN) = 1 -done(a::PModN, i) = i > length(a) -next(a::PModN, i) = (a[i], i+1) +endof(a::Poly) = length(a) +start(::Poly) = 1 +done(a::Poly, i) = i > length(a) +next(a::Poly, i) = (a[i], i+1) # --- arbitrary (but "integer") coeff polynomials @@ -227,7 +227,7 @@ next(a::PModN, i) = (a[i], i+1) # contents unless you have a new instance whose contents you know to be # owned. -immutable ZPoly{I<:Integer} <: PModN +immutable ZPoly{I<:Integer} <: Poly a::Vector{I} ZPoly(a) = length(a) == 0 || a[end] != zero(I) ? new(a) : error("zero leading coeff") end @@ -507,7 +507,7 @@ end # --- GF(2) polynomials encoded as bits -immutable GF2Poly{I<:Unsigned} <: PModN +immutable GF2Poly{I<:Unsigned} <: Poly i::I end @@ -638,29 +638,29 @@ degree{U<:Unsigned}(p::GF2Poly{U}) = 8*sizeof(U) - leading_zeros(p) # this all assumes that the factor poynomial is irreducible -abstract FModN{P<:PModN, F} <: Residue +abstract FModN{P<:Poly, F} <: Residue # assumes already reduced -immutable FRing{P<:PModN, F} <: FModN{P,F} +immutable FRing{P<:Poly, F} <: FModN{P,F} p::P end -function prepare_f{P<:PModN}(p::P, f::P) +function prepare_f{P<:Poly}(p::P, f::P) p % f end -FR{P<:PModN}(p::P, f::P) = FRing{P, encode_factor(f)}(prepare_f(p, f)) +FR{P<:Poly}(p::P, f::P) = FRing{P, encode_factor(f)}(prepare_f(p, f)) -factor{P<:PModN, F}(::Type{FRing{P, F}}) = decode_factor(P, F) -factor{P<:PModN, F}(::FRing{P, F}) = factor(FRing{P, F}) -modulus{P<:PModN, F}(::Type{FModN{P,F}}) = modulus(P) +factor{P<:Poly, F}(::Type{FRing{P, F}}) = decode_factor(P, F) +factor{P<:Poly, F}(::FRing{P, F}) = factor(FRing{P, F}) +modulus{P<:Poly, F}(::Type{FModN{P,F}}) = modulus(P) modulus{F<:FModN}(::F) = modulus(F) # assuming irreducible factor order{F<:FModN}(::Type{F}) = modulus(F) ^ degree(factor(F)) - 1 order{F<:FModN}(::F) = order(F) -zero{P<:PModN, F}(::Type{FRing{P, F}}) = FR(zero(P), decode_factor(P, F)) -one{P<:PModN, F}(::Type{FRing{P, F}}) = FR(one(P), decode_factor(P, F)) +zero{P<:Poly, F}(::Type{FRing{P, F}}) = FR(zero(P), decode_factor(P, F)) +one{P<:Poly, F}(::Type{FRing{P, F}}) = FR(one(P), decode_factor(P, F)) zero{F<:FModN}(f::F) = zero(F) one{F<:FModN}(f::F) = one(F) @@ -690,24 +690,4 @@ liftf{F<:FRing}(f, a::F, b::F) = FR(f(a.p, b.p), factor(F)) inv{F<:FRing}(f::F) = FR(extended_euclidean(f.p, factor(f)), factor(f)) /{F<:FRing}(a::F, b::F) = a * inv(b) - - -# --- pull in tests (does this need ot be so ugly?) - - -# TODO - try include (relative path) here -# TODO - move to Pkg.test etc - -#d = Pkg.dir("IntModN") -#d = "$d/src" -#push!(LOAD_PATH, d) -#import Tests -#import PTests -#pop!(LOAD_PATH) -# -#function tests() -# Tests.tests() -# PTests.tests() -#end - end diff --git a/test/PTests.jl b/test/PTests.jl index afd45fd..b9c1c62 100644 --- a/test/PTests.jl +++ b/test/PTests.jl @@ -3,7 +3,7 @@ module PTests -using Polynomial, IntModN, Compat +using Polynomial, IntModN, Compat, Base.Test import Base: promote_rule, convert @@ -125,7 +125,7 @@ function test_eq(a, T, op) println("($p2) $x ($q2)") println("r2 $(typeof(r2)) $(r2)") end - @assert r1 == r2 + @test r1 == r2 end end end diff --git a/test/Tests.jl b/test/Tests.jl index d25813c..1718319 100644 --- a/test/Tests.jl +++ b/test/Tests.jl @@ -1,7 +1,7 @@ module Tests -using IntModN +using IntModN, Base.Test export tests @@ -10,66 +10,69 @@ export tests function test_z_constructor() - @assert string(ZR(3, 2, Int)) == "2 mod 3" - @assert string(ZR(3, 2)) == "2 mod 3" - @assert sprint(show, ZR(3, 2)) == "ZRing{3,Int64}(2)" - @assert string(ZF(3, 2, Int)) == "2 mod 3" - @assert string(ZF(3, 2)) == "2 mod 3" - @assert sprint(show, ZF(3, 2)) == "ZField{3,Int64}(2)" + @test string(ZR(3, 2, Int)) == "2 mod 3" + @test string(ZR(3, 2)) == "2 mod 3" + @test sprint(show, ZR(3, 2)) == "ZRing{3,Int64}(2)" + @test string(ZF(3, 2, Int)) == "2 mod 3" + @test string(ZF(3, 2)) == "2 mod 3" + @test sprint(show, ZF(3, 2)) == "ZField{3,Int64}(2)" Z2 = ZF(2) - @assert GF2(1) == Z2(1) == ZField{2,Int}(1) == ZF(2, 1) + @test GF2(1) == Z2(1) == ZField{2,Int}(1) == ZF(2, 1) - @assert isa(ZR(4, 0x3).i, Uint8) + @test isa(ZR(4, 0x3).i, Uint8) try bad = ZR(256, 0x0) error("expected failure") catch e - @assert isa(e, ErrorException) - @assert search(string(e), "too large") != 0:-1 + @test isa(e, ErrorException) + @test search(string(e), "too large") != 0:-1 end - @assert one(ZField{2,Int}) == one(GF2(0)) == GF2(1) + @test one(ZField{2,Int}) == one(GF2(0)) == GF2(1) println("test_z_constructor ok") end function test_z_random() - @assert isa(rand(ZRing{3,Uint}), ZRing{3,Uint}) + @test isa(rand(ZRing{3,Uint}), ZRing{3,Uint}) a = rand(ZField{5,Uint8}, 2, 3) - @assert size(a) == (2, 3) - @assert isa(a, Array{ZField{5,Uint8},2}) + @test size(a) == (2, 3) + @test isa(a, Array{ZField{5,Uint8},2}) println("test_z_random ok") end function test_z_arithmetic() - @assert GF2(1) + GF2(1) == GF2(0) - @assert zero(ZRing{5,Int}) - one(ZRing{5,Int}) == ZR(5, 4) - @assert zero(ZField{5,Int}) - one(ZField{5,Int}) == ZF(5, 4) - @assert inv(ZF(5, 3)) == ZF(5, 2) - @assert ZF(5, 3) * ZF(5, 2) == one(ZField{5, Int}) - @assert GF2(0)^0 == GF2(1) + @test GF2(1) + GF2(1) == GF2(0) + @test zero(ZRing{5,Int}) - one(ZRing{5,Int}) == ZR(5, 4) + @test zero(ZField{5,Int}) - one(ZField{5,Int}) == ZF(5, 4) + @test inv(ZF(5, 3)) == ZF(5, 2) + @test ZF(5, 3) * ZF(5, 2) == one(ZField{5, Int}) + @test GF2(0)^0 == GF2(1) for i in 1:10 z1, z2 = ZF(5, rand(1:5)), ZF(5, rand(1:5)) - @assert (z1 - z2) + z2 == z1 - @assert z1 - (z2 - z2) == z1 - @assert z2 + (z1 - z2) == z1 + @test (z1 - z2) + z2 == z1 + @test z1 - (z2 - z2) == z1 + @test z2 + (z1 - z2) == z1 end - @assert ZF(5, 1) - ZF(5, 4) == ZF(5, 2) + @test ZF(5, 1) - ZF(5, 4) == ZF(5, 2) - @assert modulus(GF2(1)) == order(GF2(0)) == 2 + @test modulus(GF2(1)) == order(GF2(0)) == 2 try inv(ZR(6, 2)) error("expected failure") catch e - @assert isa(e, ErrorException) - @assert search(string(e), "not invertible") != 0:-1 + @test isa(e, ErrorException) + @test search(string(e), "not invertible") != 0:-1 end + @test_throws ErrorException ZR(4, 2) / ZR(4, 3) + @test ZF(5, 2) / ZF(5, 3) == ZF(5, 4) + println("test_z_arithmetic ok") end @@ -80,7 +83,7 @@ function test_z_matrix_inverse() 0 1] b = [1, 1] x = A\b - @assert x == [0, 1] + @test x == [0, 1] end # http://math.stackexchange.com/questions/169921/how-to-solve-system-of-linear-equations-of-xor-operation @@ -91,7 +94,7 @@ function test_z_matrix_inverse() 0 1 1 1] b = [1, 1, 0, 1] x = A\b - @assert x == [0, 1, 0, 0] + @test x == [0, 1, 0, 0] end println("test_z_matrix_inverse ok") @@ -101,10 +104,10 @@ function test_z_power() # http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange#Explanation_including_encryption_mathematics base = ZF(23, 5) - @assert (base^6).i == 8 - @assert (base^15).i == 19 - @assert ((base^15)^6).i == 2 - @assert ((base^6)^15).i == 2 + @test (base^6).i == 8 + @test (base^15).i == 19 + @test ((base^15)^6).i == 2 + @test ((base^6)^15).i == 2 println("test_z_power ok") end @@ -113,13 +116,13 @@ function test_z_macros() begin b = 7 end - @assert b == 7 + @test b == 7 @zfield 5 begin b = 1 + 2 * 3 a = b / 3 end - @assert a == ZF(5, 4) - @assert ZR(3, 2) == @zring 3 1 + 4 + @test a == ZF(5, 4) + @test ZR(3, 2) == @zring 3 1 + 4 println("test_z_macros ok") end @@ -146,23 +149,23 @@ end function test_p_constructor() x = ZP(GF2(1), GF2(0)) - @assert ZP(GF2(1), GF2(0), GF2(1), GF2(0)) == x^3 + x + @test ZP(GF2(1), GF2(0), GF2(1), GF2(0)) == x^3 + x x = X(ZF(5)) - @assert ZP(ZF(5,2), ZF(5,3), ZF(5,4)) == 2x^2 + 3x + 4 + @test ZP(ZF(5,2), ZF(5,3), ZF(5,4)) == 2x^2 + 3x + 4 x = X(ZField{3, Int}) - @assert x + 1 == ZP([ZF(3,1), ZF(3,1)]) - @assert x + 1 == ZP(ZF(3,1), ZF(3,1)) - @assert x + 1 == ZP(ZField{3, Int}, [1, 1]) - @assert x + 1 == ZP(ZField{3, Int}, 1, 1) + @test x + 1 == ZP([ZF(3,1), ZF(3,1)]) + @test x + 1 == ZP(ZF(3,1), ZF(3,1)) + @test x + 1 == ZP(ZField{3, Int}, [1, 1]) + @test x + 1 == ZP(ZField{3, Int}, 1, 1) x = X(GF2) - @assert ZP(GF2, 1, 1, 0) == x^2 + x - @assert ZP(ZF(2), [0, 1, 1]) == x^2 + x - @assert ZP(ZField{2,Int}, [0, 1, 1]) == x^2 + x + @test ZP(GF2, 1, 1, 0) == x^2 + x + @test ZP(ZF(2), [0, 1, 1]) == x^2 + x + @test ZP(ZField{2,Int}, [0, 1, 1]) == x^2 + x p = x^2 + x - @assert IntModN.encode_factor(p) == (0, 1, 1) - @assert IntModN.decode_factor(ZPoly{ZField{2,Int}}, (0, 1, 1)) == p + @test IntModN.encode_factor(p) == (0, 1, 1) + @test IntModN.decode_factor(ZPoly{ZField{2,Int}}, (0, 1, 1)) == p println("test_p_constructor ok") end @@ -170,12 +173,12 @@ end function test_p_show() x = X(Int) - @assert string(3x^2 + 1) == "3x^2 + 1" - @assert sprint(show, 3x^2 + 1) == "ZP(Int64,3,0,1)" + @test string(3x^2 + 1) == "3x^2 + 1" + @test sprint(show, 3x^2 + 1) == "ZP(Int64,3,0,1)" x = X(ZF(5)) - @assert string(3x^2 + 1) == "3x^2 + 1 mod 5" - @assert sprint(show, 3x^2 + 1) in + @test string(3x^2 + 1) == "3x^2 + 1 mod 5" + @test sprint(show, 3x^2 + 1) in ("ZP(ZField{5,Int64},3,0,1)", "ZP(IntModN.ZField{5,Int64},3,0,1)") println("test_p_show ok") @@ -184,23 +187,23 @@ end function test_p_comparison() x = X(Int) - @assert x + 1 == x + 1 - @assert x^2 + 1 != x + 1 + @test x + 1 == x + 1 + @test x^2 + 1 != x + 1 for i in 1:10 a = ZP(rand!(Array(ZField{5, Int}, rand(0:2)))) b = ZP(rand!(Array(ZField{5, Int}, rand(0:2)))) - @assert a == b || ((a < b) $ (b < a)) + @test a == b || ((a < b) $ (b < a)) if a < b || a == b - @assert a <= b + @test a <= b end if a > b || a == b - @assert a >= b + @test a >= b end if a == b - @assert !(a != b) + @test !(a != b) else - @assert a != b + @test a != b end end @@ -213,24 +216,24 @@ function test_p_arithmetic() a = x^3 + x^2 + 1 b = x^2 + 1 p, q = divrem(a, b) - @assert string(p * b + q) == "x^3 + x^2 + 1 mod 2" + @test string(p * b + q) == "x^3 + x^2 + 1 mod 2" x = X(ZF(5)) p1 = x^5 + 3x^4 + 4x^3 + 2x^2 + 1 p2 = 4x^5 + 2x^3 + 3x^2 + x + 4 ex = 2x^5 + 3x^4 + 2x^3 + 4x^2 + 4x + 2 r = p1 - p2 - @assert r == ex + @test r == ex println("test_p_arithmetic ok") end function test_p_bitwise() - @assert ZP(3, 2, 1) & ZP(1, 1, 1) == ZP(1, 0, 1) - @assert ZP(3, 2, 1) | ZP(1, 1) == ZP(3, 3, 1) - @assert ZP(GF2(0), GF2(0)) $ ZP(GF2(1)) == ZP(GF2(0), GF2(1)) - @assert ZP(1, 0) << 2 == ZP(1, 0, 0, 0) - @assert ZP(1, 0) >>> 1 == ZP(1) + @test ZP(3, 2, 1) & ZP(1, 1, 1) == ZP(1, 0, 1) + @test ZP(3, 2, 1) | ZP(1, 1) == ZP(3, 3, 1) + @test ZP(GF2(0), GF2(0)) $ ZP(GF2(1)) == ZP(GF2(0), GF2(1)) + @test ZP(1, 0) << 2 == ZP(1, 0, 0, 0) + @test ZP(1, 0) >>> 1 == ZP(1) println("test_p_bitwise") end @@ -239,17 +242,17 @@ function test_p_array() x = X(GF2) p = x^2 + x - @assert p[2] == GF2(1) - @assert p[1] == GF2(0) - @assert length(p) == 3 + @test p[2] == GF2(1) + @test p[1] == GF2(0) + @test length(p) == 3 count = 0 for (i, a) in enumerate(p) count = count + 1 - @assert 0 < i < 4 - @assert (i == 1 && a == GF2(0)) || (i != 1 && a == GF2(1)) + @test 0 < i < 4 + @test (i == 1 && a == GF2(0)) || (i != 1 && a == GF2(1)) end - @assert count == 3 + @test count == 3 println("test_p_array") end @@ -270,11 +273,11 @@ end function test_p2_constructor() x = GF2X(Uint8) - @assert GF2P(0xa) == x^3 + x + @test GF2P(0xa) == x^3 + x p = x^2 + x - @assert IntModN.encode_factor(p) == tuple(6) - @assert IntModN.decode_factor(GF2Poly{Uint8}, tuple(6)) == p + @test IntModN.encode_factor(p) == tuple(6) + @test IntModN.decode_factor(GF2Poly{Uint8}, tuple(6)) == p println("test_p2_constructor ok") end @@ -282,8 +285,8 @@ end function test_p2_show() x = GF2X(Uint) - @assert string(3x^2 + 1) == "x^2 + 1 mod 2" - @assert sprint(show, 3x^2 + 1) in + @test string(3x^2 + 1) == "x^2 + 1 mod 2" + @test sprint(show, 3x^2 + 1) in ("GF2Poly{UInt64}(5)", "GF2Poly{Uint64}(5)") println("test_p2_show ok") @@ -292,23 +295,23 @@ end function test_p2_comparison() x = GF2X(Uint) - @assert x + 1 == x + 1 - @assert x^2 + 1 != x + 1 + @test x + 1 == x + 1 + @test x^2 + 1 != x + 1 for i in 1:10 a = GF2P(rand(Uint8)) b = GF2P(rand(Uint8)) - @assert a == b || ((a < b) $ (b < a)) + @test a == b || ((a < b) $ (b < a)) if a < b || a == b - @assert a <= b + @test a <= b end if a > b || a == b - @assert a >= b + @test a >= b end if a == b - @assert !(a != b) + @test !(a != b) else - @assert a != b + @test a != b end end @@ -321,24 +324,24 @@ function test_p2_arithmetic() a = x^3 + x^2 + 1 b = x^2 + 1 p, q = divrem(a, b) - @assert p*b+q == a - @assert string(p * b + q) == "x^3 + x^2 + 1 mod 2" + @test p*b+q == a + @test string(p * b + q) == "x^3 + x^2 + 1 mod 2" p1 = x^5 + x^4 + x^3 + x^2 + 1 p2 = x^5 + x^3 + x^2 + x ex = x^4 + x + 1 r = p1 - p2 - @assert r == ex + @test r == ex println("test_p2_arithmetic ok") end function test_p2_bitwise() - @assert GF2P(0x5) & GF2P(0x7) == GF2P(0x5) - @assert GF2P(0x5) | GF2P(0x3) == GF2P(0x7) - @assert GF2P(0x0) $ GF2P(0x1) == GF2P(0x1) - @assert GF2P(0x2) << 2 == GF2P(0x8) - @assert GF2P(0x2) >>> 1 == GF2P(0x1) + @test GF2P(0x5) & GF2P(0x7) == GF2P(0x5) + @test GF2P(0x5) | GF2P(0x3) == GF2P(0x7) + @test GF2P(0x0) $ GF2P(0x1) == GF2P(0x1) + @test GF2P(0x2) << 2 == GF2P(0x8) + @test GF2P(0x2) >>> 1 == GF2P(0x1) println("test_p2_bitwise") end @@ -347,17 +350,17 @@ function test_p2_array() x = GF2X() p = x^2 + x - @assert p[2] == GF2(1) - @assert p[1] == GF2(0) - @assert length(p) == 3 + @test p[2] == GF2(1) + @test p[1] == GF2(0) + @test length(p) == 3 count = 0 for (i, a) in enumerate(p) count = count + 1 - @assert 0 < i < 4 - @assert (i == 1 && a == GF2(0)) || (i != 1 && a == GF2(1)) + @test 0 < i < 4 + @test (i == 1 && a == GF2(0)) || (i != 1 && a == GF2(1)) end - @assert count == 3 + @test count == 3 println("test_p2_array") end @@ -378,8 +381,8 @@ end function test_f_constructor() x = X(GF2) f = FR(x^3 + x^2, x^2 + 1) - @assert string(f) == "x + 1 mod x^2 + 1 mod 2" - @assert sprint(show, f) in + @test string(f) == "x + 1 mod x^2 + 1 mod 2" + @test sprint(show, f) in ("FR(ZP(ZField{2,Int64},1,1),ZP(ZField{2,Int64},1,0,1))", "FR(ZP(IntModN.ZField{2,Int64},1,1),ZP(IntModN.ZField{2,Int64},1,0,1))") @@ -392,10 +395,10 @@ function test_f_rijndael() a = FR(x^7 + x^6 + x^3 + x, rij) b = FR(x^6 + x^4 + x + 1, rij) o = one(a) - @assert a * b == o - @assert inv(a) == b - @assert o / b == a - @assert o / a == b + @test a * b == o + @test inv(a) == b + @test o / b == a + @test o / a == b println("test_f_rijndael ok") end @@ -406,10 +409,10 @@ function test_f_rijndael2() a = FR(x^7 + x^6 + x^3 + x, rij) b = FR(x^6 + x^4 + x + 1, rij) o = one(a) - @assert a * b == o - @assert inv(a) == b - @assert o / b == a - @assert o / a == b + @test a * b == o + @test inv(a) == b + @test o / b == a + @test o / a == b println("test_f_rijndael2 ok") end @@ -420,7 +423,7 @@ function test_f_inverse() a = x^7 + x^6 + x^3 + x b = x^6 + x^4 + x + 1 c = extended_euclidean(a, rij) - @assert b == c + @test b == c println("test_f_inverse ok") end