Ejemplo n.º 1
0
    def test(self):
        """
        def hermite(n,y):
            if n == 1: return 2*y
            if n == 0: return 1
            return expand(2*y*hermite(n-1,y) - 2*(n-1)*hermite(n-2,y))

            time hermite(15,var('y'))
        """
        from sage.all_cmdline import Integer, sqrt, real, var, expand
        for _ in xrange(self.rounds):
            _sage_const_2 = Integer(2)
            _sage_const_1 = Integer(1)
            _sage_const_0 = Integer(0)
            _sage_const_15 = Integer(18)

            def hermite(n, y):
                if n == _sage_const_1: return _sage_const_2 * y
                if n == _sage_const_0: return _sage_const_1
                return expand(
                    _sage_const_2 * y * hermite(n - _sage_const_1, y) -
                    _sage_const_2 *
                    (n - _sage_const_1) * hermite(n - _sage_const_2, y))

            hermite(_sage_const_15, var('y'))
Ejemplo n.º 2
0
 def calibrate(self):
     from sage.all_cmdline import Integer, var
     for i in xrange(self.rounds):
         _sage_const_1 = Integer(1)
         _sage_const_7 = Integer(10)
         var('x,y,z')
         f = (x+y+z+_sage_const_1 )**_sage_const_7 
Ejemplo n.º 3
0
 def test(self):
     from sage.all_cmdline import Integer, var, sin, cos, taylor
     for i in xrange(self.rounds):
         _sage_const_0 = Integer(0)
         _sage_const_1000 = Integer(350)
         x=var('x')
         w = (sin(x)*cos(x)).taylor(x,_sage_const_0 ,_sage_const_1000 ) 
Ejemplo n.º 4
0
 def test(self):
     from sage.all_cmdline import Integer, ellipsis_range, pi
     for _ in xrange(self.rounds):
         _sage_const_1 = Integer(1)
         _sage_const_10 = Integer(40000)
         v = (ellipsis_range(-pi, -pi + _sage_const_1 / _sage_const_10,
                             Ellipsis, pi))
Ejemplo n.º 5
0
 def test(self):
     from sage.all_cmdline import Integer, expand, var
     for i in xrange(self.rounds):
         _sage_const_1 = Integer(1)
         _sage_const_7 = Integer(10)
         var('x,y,z')
         f = (x+y+z+_sage_const_1 )**_sage_const_7 
         g = expand(f*(f+_sage_const_1 )); 
Ejemplo n.º 6
0
 def test(self):
     from sage.all_cmdline import Integer, random, ellipsis_range, I
     for _ in xrange(self.rounds):
         _sage_const_0 = Integer(0)
         _sage_const_1000 = Integer(2000)
         a = [
             random() + random() * I for w in (
                 ellipsis_range(_sage_const_0, Ellipsis, _sage_const_1000))
         ]
Ejemplo n.º 7
0
    def calibrate(self):
        from sage.all_cmdline import Integer, sqrt, i
        for _ in xrange(self.rounds):
            _sage_const_3 = Integer(3)
            _sage_const_2 = Integer(2)
            _sage_const_1 = Integer(1)

            def f(z):
                return sqrt(_sage_const_1 / _sage_const_3
                            ) * z**_sage_const_2 + i / _sage_const_3
Ejemplo n.º 8
0
 def test(self):
     """
     u = [e, pi, sqrt(2)]
     time Tuples(u,3).cardinality()
     """
     from sage.all_cmdline import Integer, sqrt, e, pi, Tuples
     for _ in xrange(self.rounds):
         _sage_const_3 = Integer(3)
         _sage_const_2 = Integer(2)
         u = [e, pi, sqrt(_sage_const_2)]
         Tuples(u, _sage_const_3).cardinality()
Ejemplo n.º 9
0
    def test(self):
        from sage.all_cmdline import Integer, sqrt, real, i
        for _ in xrange(self.rounds):
            _sage_const_3 = Integer(3)
            _sage_const_2 = Integer(2)
            _sage_const_1 = Integer(1)

            def f(z):
                return sqrt(_sage_const_1 / _sage_const_3
                            ) * z**_sage_const_2 + i / _sage_const_3

            real(f(f(f(f(f(i / _sage_const_2))))))
Ejemplo n.º 10
0
    def calibrate(self):
        from sage.all_cmdline import Integer, real, expand
        for _ in xrange(self.rounds):
            _sage_const_2 = Integer(2)
            _sage_const_1 = Integer(1)
            _sage_const_0 = Integer(0)
            _sage_const_15 = Integer(15)

            def hermite(n, y):
                if n == _sage_const_1: return _sage_const_2 * y
                if n == _sage_const_0: return _sage_const_1
                return expand(
                    _sage_const_2 * y * hermite(n - _sage_const_1, y) -
                    _sage_const_2 *
                    (n - _sage_const_1) * hermite(n - _sage_const_2, y))
Ejemplo n.º 11
0
 def calibrate(self):
     from sage.all_cmdline import Integer, var, expand
     for i in xrange(self.rounds):
         _sage_const_50 = Integer(55)
         x=var('x')
         y=var('y')
         z=var('z')
         f=expand((x**y+y**z+z**x)**_sage_const_50)
Ejemplo n.º 12
0
def inverse(el):
    ret = el.parent().zero()
    ORDER = el.parent().nilpotency_order
    for i in range(0,ORDER+1):
        add = (el-1)**i
        add *= Integer( (-1)**(i) )
        ret += add
    return ret
Ejemplo n.º 13
0
 def test(self):
     from sage.all_cmdline import Integer, expand, var, diff 
     for i in xrange(self.rounds):
         _sage_const_50 = Integer(110)
         x=var('x')
         y=var('y')
         z=var('z')
         f=expand((x**y+y**z+z**x)**_sage_const_50)
         g = f.diff(x)
Ejemplo n.º 14
0
    def calibrate(self):
        from sage.all_cmdline import Integer, var
        for _ in xrange(self.rounds):
            _sage_const_2 = Integer(2)
            _sage_const_10 = Integer(10)
            _sage_const_0 = Integer(0)
            _sage_const_5 = Integer(5)
            _sage_const_4 = Integer(4)

            def right(f, a, b, n):
                Deltax = (b - a) / n
                c = a
                est = _sage_const_0
                for _ in range(n):
                    c += Deltax
                    est += f(x=c)
                return est * Deltax

            x = var('x')
Ejemplo n.º 15
0
 def calibrate(self):
     from sage.all_cmdline import Integer, var
     for _ in xrange(self.rounds):
         _sage_const_10 = Integer(10)
         l = []
         for j in xrange(1, 10):
             l.append("q" + str(j))
         s = reduce(lambda a, b: a + "," + b, l)
         sp = reduce(lambda a, b: a + "+" + b, l)
         var(s)
         f = eval(sp)
Ejemplo n.º 16
0
def get_flag():
    # Recover message
    _, u, v = xgcd(e1, e2)
    m = pow(ct1, u, modulus) * pow(ct2, v, modulus)

    # Get binary representation and pad
    bin = Integer(m).binary()
    while (len(bin) % 8 != 0):
        bin = '0' + bin

    # Return ASCII string
    print(bin_to_ascii(bin))
Ejemplo n.º 17
0
def log(el):
    """
    TESTS:
    sage: from word_algebras import *
    sage: NFA = NilpotentFreeAlgebra(QQ,2,'x',3)
    sage: x0,x1 = NFA.gens()
    sage: assert x0 == log(exp(x0))
    """
    ret = 0
    ORDER = el.parent().nilpotency_order
    for i in range(1,ORDER+1):
        add = (el-1)**i
        add *= Integer( (-1)**(i+1) ) / i
        ret += add
    return ret
Ejemplo n.º 18
0
    def test(self):
        """
        sage: time v = [-pi,-pi+1/10..,pi]
        """
        from sage.all_cmdline import Integer, var
        for _ in xrange(self.rounds):
            _sage_const_10 = Integer(500)
            l = []
            for j in xrange(1, 1000):
                l.append("q" + str(j))
            s = reduce(lambda a, b: a + "," + b, l)
            sp = reduce(lambda a, b: a + "+" + b, l)
            var(s)
            f = eval(sp)

            a = [bool(f == f) for _ in range(_sage_const_10)]
Ejemplo n.º 19
0
 def test(self):
     from sage.all_cmdline import Integer, random, var
     for _ in xrange(self.rounds):
         _sage_const_3 = Integer(3)
         _sage_const_32 = Integer(32)
         _sage_const_45 = Integer(45)
         _sage_const_4 = Integer(4)
         _sage_const_9 = Integer(9)
         _sage_const_12 = Integer(12)
         _sage_const_10 = Integer(9)
         _sage_const_18 = Integer(18)
         _sage_const_21 = Integer(21)
         _sage_const_34 = Integer(34)
         _sage_const_24 = Integer(24)
         x = var('x')
         f = x**_sage_const_24 + _sage_const_34 * x**_sage_const_12 + _sage_const_45 * x**_sage_const_3 + _sage_const_9 * x**_sage_const_18 + _sage_const_34 * x**_sage_const_10 + _sage_const_32 * x**_sage_const_21
         a = [f(x=random()) for _ in xrange(_sage_const_10**_sage_const_4)]
Ejemplo n.º 20
0
 def calibrate(self):
     from sage.all_cmdline import Integer
     for _ in xrange(self.rounds):
         _sage_const_1 = Integer(1)
         _sage_const_10 = Integer(1000)
Ejemplo n.º 21
0
 def calibrate(self):
     from sage.all_cmdline import Integer, var 
     for i in xrange(self.rounds):
         _sage_const_100 = Integer(120)
         x,y,z=var('x,y,z')
Ejemplo n.º 22
0
 def test(self):
     from sage.all_cmdline import Integer, expand, sin, cos, var
     for i in xrange(self.rounds):
         _sage_const_100 = Integer(200)
         x,y,z=var('x,y,z')
         a = expand((x**sin(x) + y**cos(y) - z**(x+y))**_sage_const_100 ); 
Ejemplo n.º 23
0
 def test(self):
     from sage.all_cmdline import Integer, sin
     for _ in xrange(self.rounds):
         _sage_const_100 = Integer(1400)
         sum(((x + sin(i)) / x + (x - sin(i)) / x)
             for i in xrange(_sage_const_100))
Ejemplo n.º 24
0
 def calibrate(self):
     from sage.all_cmdline import Integer, var 
     for i in xrange(self.rounds):
         _sage_const_0 = Integer(0)
         _sage_const_1000 = Integer(200)
         x=var('x')
Ejemplo n.º 25
0
 def calibrate(self):
     from sage.all_cmdline import Integer, sqrt, e, pi, Tuples
     for _ in xrange(self.rounds):
         _sage_const_3 = Integer(3)
         _sage_const_2 = Integer(2)
         u = [e, pi, sqrt(_sage_const_2)]
Ejemplo n.º 26
0
# This file was *autogenerated* from the file ./flag.sage
from sage.all_cmdline import Integer, xgcd  # import sage library
from sage.crypto.util import bin_to_ascii

# Given values
ct1 = Integer(
    13981765388145083997703333682243956434148306954774120760845671024723583618341148528952063316653588928138430524040717841543528568326674293677228449651281422762216853098529425814740156575513620513245005576508982103360592761380293006244528169193632346512170599896471850340765607466109228426538780591853882736654
)
ct2 = Integer(
    79459949016924442856959059325390894723232586275925931898929445938338123216278271333902062872565058205136627757713051954083968874644581902371182266588247653857616029881453100387797111559677392017415298580136496204898016797180386402171968931958365160589774450964944023720256848731202333789801071962338635072065
)
e1 = Integer(13)
e2 = Integer(15)
modulus = Integer(
    103109065902334620226101162008793963504256027939117020091876799039690801944735604259018655534860183205031069083254290258577291605287053538752280231959857465853228851714786887294961873006234153079187216285516823832102424110934062954272346111907571393964363630079343598511602013316604641904852018969178919051627
)


def get_flag():
    # Recover message
    _, u, v = xgcd(e1, e2)
    m = pow(ct1, u, modulus) * pow(ct2, v, modulus)

    # Get binary representation and pad
    bin = Integer(m).binary()
    while (len(bin) % 8 != 0):
        bin = '0' + bin

    # Return ASCII string
    print(bin_to_ascii(bin))
Ejemplo n.º 27
0
 def calibrate(self):
     from sage.all_cmdline import Integer, var
     for _ in xrange(self.rounds):
         _sage_const_3 = Integer(3)
         _sage_const_32 = Integer(32)
         _sage_const_45 = Integer(45)
         _sage_const_4 = Integer(4)
         _sage_const_9 = Integer(9)
         _sage_const_12 = Integer(12)
         _sage_const_10 = Integer(10)
         _sage_const_18 = Integer(18)
         _sage_const_21 = Integer(21)
         _sage_const_34 = Integer(34)
         _sage_const_24 = Integer(24)
         x = var('x')
         f = x**_sage_const_24 + _sage_const_34 * x**_sage_const_12 + _sage_const_45 * x**_sage_const_3 + _sage_const_9 * x**_sage_const_18 + _sage_const_34 * x**_sage_const_10 + _sage_const_32 * x**_sage_const_21