Пример #1
0
def testModExp(number1, number2, number3):
    result = hex(pow(number1, number2, number3) & util.bitMask)[2:]

    return util.test(
        result, "modexp {0} {1} {2}".format(util.toBigIntString(number1),
                                            util.toBigIntString(number2),
                                            util.toBigIntString(number3)))
Пример #2
0
def testSubtract(number1, number2):
    result = number1 - number2

    if result < 0:
        power = max((len(hex(-result)) // 8 + 1) * 32, 32)
        result = (1 << power) + result
        result = hex(result)[2:]
        # Workaround for bizarre "f" and "0" prefixing.
        while result[:8] == "f" * 8:
            result = result[8:]
        while result[0] == '0':
            result = result[1:]
    else:
        result = hex(result)[2:]

    return util.test(
        result, "subtract {0} {1}".format(util.toBigIntString(number1),
                                          util.toBigIntString(number2)))
Пример #3
0
def testXor(number1, number2):
    result = hex((number1 ^ number2) & util.bitMask)[2:]

    return util.test(
        result, "xor {0} {1}".format(util.toBigIntString(number1),
                                     util.toBigIntString(number2)))
Пример #4
0
def testLShift(number, shiftBy):
    assert (shiftBy >= 0)
    result = hex((number << shiftBy) & util.bitMask)[2:]
    nString = util.toBigIntString(number)

    return util.test(result, "lshift {0} {1}".format(nString, shiftBy))
Пример #5
0
def testAnd(number1, number2):
    result = hex((number1 & number2) & util.bitMask)[2:]

    return util.test(
        result, "and {0} {1}".format(util.toBigIntString(number1),
                                     util.toBigIntString(number2)))
Пример #6
0
def testRShift(number, shiftBy):
    assert (shiftBy >= 0)
    result = hex(number >> shiftBy)[2:]
    nString = util.toBigIntString(number)

    return util.test(result, "rshift {0} {1}".format(nString, shiftBy))
Пример #7
0
def testDivide(number1, number2):
    result = hex((number1 // number2) & util.bitMask)[2:]

    return util.test(
        result, "divide {0} {1}".format(util.toBigIntString(number1),
                                        util.toBigIntString(number2)))
Пример #8
0
def testMultiply(number1, number2):
    result = hex((number1 * number2) & util.bitMask)[2:]

    return util.test(
        result, "multiply {0} {1}".format(util.toBigIntString(number1),
                                          util.toBigIntString(number2)))
Пример #9
0
def testMiller(number):
    result = str(millerRabin(number, 20))

    return util.test(result, "prime {0}".format(util.toBigIntString(number)))
Пример #10
0
def testAssign(number):
    result = hex(number)[2:]
    nString = util.toBigIntString(number)

    return util.test(result, "assign {0}".format(nString))