3 * $Id: gfx.cal,v 1.2 2004/03/21 22:52:06 mdw Exp $
5 * Testbed for %$\gf{2}$% poltnomial arithmetic
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 2004/03/21 22:52:06 mdw
34 * Merge and close elliptic curve branch.
36 * Revision 1.1.4.1 2004/03/21 22:39:46 mdw
37 * Elliptic curves on binary fields work.
39 * Revision 1.1 2000/10/08 16:01:37 mdw
40 * Prototypes of various bits of code.
44 /*----- Object types ------------------------------------------------------*/
48 /*----- Static variables --------------------------------------------------*/
50 static obj gf example_gf_object;
52 /*----- Main code ---------------------------------------------------------*/
54 dummy = config("lib_debug", -1);
65 if (istype(x, example_gf_object))
71 define gf_add(x, y) = gf(xor(gfint(x), gfint(y)));
72 define gf_sub(x, y) = gf(xor(gfint(x), gfint(y)));
77 local a = gfint(x), b = gfint(y), z = 0, i, bits = highbit(a);
78 for (i = 0; i <= bits; i++) {
85 define gfx_div(rx, dx)
87 local r = gfint(rx), d = gfint(dx), i;
88 local q = 0, dbits, rbits;
91 for (i = rbits - dbits; i >= 0; i--) {
92 if (bit(r, i + dbits)) {
116 local g, x, y, X, Y, u, v, t, q, r;
117 x = gf(1); X = gf(0);
118 y = gf(0); Y = gf(1);
120 if (b == gf(0)) { g = a; } else if (a == gf(0)) { g = b; }
123 q = gf_div(b, a); r = gf_mod(b, a);
124 t = X * q + x; x = X; X = t;
125 t = Y * q + y; y = Y; Y = t;
130 if (g != gf(1)) quit "not coprime in gf_inv";
134 /*----- That's all, folks -------------------------------------------------*/