示例#1
0
文件: lab3.py 项目: b1est/sromlabs
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 )
示例#2
0
文件: lab3.py 项目: b1est/sromlabs
 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
示例#3
0
文件: lab3.py 项目: b1est/sromlabs
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")
示例#4
0
文件: lab3.py 项目: b1est/sromlabs
    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
示例#5
0
文件: lab3.py 项目: b1est/sromlabs
 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
示例#6
0
文件: lab3.py 项目: b1est/sromlabs
 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
示例#7
0
文件: lab3.py 项目: b1est/sromlabs
 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
示例#8
0
文件: lab3.py 项目: b1est/sromlabs
 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
示例#9
0
文件: lab3.py 项目: b1est/sromlabs
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 )
示例#10
0
文件: lab3.py 项目: b1est/sromlabs
 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