def Sqr(a): num = Num() s = time.time() a = stb(a) p = stb(num.polynom) res = num.sqr(a) print(bts(res) + Fore.BLUE + "\nTime: " + str(time.time() - s) + " seconds" + Style.RESET_ALL )
def Tr(self, a): tmp = Num() a = stb(a) pol = stb(self.polynom) tr = [0] for i in range(0, self.m): tr = tmp.addBig(tr.copy(), a.copy()) a = tmp.sqr(a.copy()) res = bts(tr) del tmp return res
def t1(a, b, c): n = Num() a = stb(a) b = stb(b) c = stb(c) res1 = n.mulPoly(bts(n.addBig(a.copy(), b.copy())), c) res2 = n.addPol(stb(n.mulPoly(bts(a), bts(c))), stb(n.mulPoly(bts(b), bts(c)))) if res1 == res2: print("ok.") else: print("no")
def mulPoly(self, a, b): tmp = Num() aBin = stb(a) bBin = stb(b) pol = stb(self.polynom) mul = tmp.mulL(aBin, bBin, 2) div = tmp.divL(mul, pol)[1] while(len(div) > self.m): del div[0] num = bts(div) return num
def poW(self, a, n): tmp = Num() b = [1] a = stb(a) e = stb(n) e.reverse() for i in range(len(e)): if e[i] == 1: b = tmp.mulL(b.copy(), a.copy()) b = tmp.divL(b.copy(), self.polynom)[1] a = tmp.sqr(a.copy()) a = tmp.divL(a.copy(), self.polynom)[1] res = b return res
def sqr(self, a): p = stb(self.polynom) nA = len(a) - 1 for i in range(nA): a.insert(i*2 + 1, 0) r = Num() res = r.divL(a.copy(), p)[1] return res
def mulL(self, a, b, e = 2): if len(a) > len(b): x = a a = b b = x res = [] b.reverse() for i in range(len(b)): tmp = Num() temp = tmp.modb(a, b[i], e) temp = sdth(stb(temp), i) res = tmp.addBig(temp, res) return res
def divL(self, a, b): k = len(b) r = a q = [] if type(b) == str: b = stb(b) while lcmp(r, b) == 1 or lcmp(r, b) == 0: t = len(r) c = sdth(b, t-k) tmp = Num() r = tmp.addBig(r, c) q = ins(q, t-k) while(len(r) != 0): if r[0] == 0: del r[0] else: break return q, r
def Add(a, b): num = Num() s = time.time() res = bts(num.addBig(stb(a), stb(b))) print(res + Fore.BLUE + "\nTime: " + str(time.time() - s) + " seconds" + Style.RESET_ALL )
def inv(self, a): tmp = Num() a = stb(a) n = conv(str((2 ** self.m) - 2), 2, 10) tmp = tmp.poW(a, n) return tmp