From 9baad71687b944f93638f68f306089234080e21a Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 6 Mar 2022 14:28:05 +0000 Subject: [PATCH] convert xgcd to GF2 --- openpower/sv/gf2.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openpower/sv/gf2.py b/openpower/sv/gf2.py index 145825281..5d5066ee4 100644 --- a/openpower/sv/gf2.py +++ b/openpower/sv/gf2.py @@ -60,9 +60,9 @@ def xgcd(a, b): """return (g, x, y) such that a*x + b*y = g = gcd(a, b)""" x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: - (q, a), b = divmod(b, a), a - y0, y1 = y1, y0 - q * y1 - x0, x1 = x1, x0 - q * x1 + (q, a), b = divmodGF2(b, a), a + y0, y1 = y1, y0 ^ multGF2(q , y1) + x0, x1 = x1, x0 ^ multGF2(q , x1) return b, x0, y0 def gf_invert(a, mod=0x11B) : @@ -118,6 +118,12 @@ if __name__ == "__main__": x1 = multGF2(res, y) print("%02x == %02x" % (z, x1 ^ rem)) + + print(xgcd(x, y)) + + + exit(0) + #for i in range(1, 256): # print (i, gf_invert(i)) -- 2.30.2