Example #1
0
def main():
    x = readinput("x")
    y = readinput("y")
    if y > x:
        x, y = y, x
    ans = gcd(x, y)
    print("GCD of %d and %d = %d" % (x, y, ans))
Example #2
0
File: gcd.py Project: MotoLee/DPV
def main():
    x = readinput("x")
    y = readinput("y")
    if y > x:
        x, y = y, x
    ans = gcd(x, y)
    print ("GCD of %d and %d = %d" % (x, y, ans))
Example #3
0
def main():
    print ("X^Y % N")
    x = readinput("X")
    y = readinput("Y")
    N = readinput("N")
    ans = modular_exp(x, y, N)
    print ("(%d^%d) %% %d = %d" % (x, y, N, ans))
Example #4
0
def main():
    print("X^Y % N")
    x = readinput("X")
    y = readinput("Y")
    N = readinput("N")
    ans = modular_exp(x, y, N)
    print("(%d^%d) %% %d = %d" % (x, y, N, ans))
Example #5
0
def test_numpower():
    while True:
        x = readinput("X")
        n = readinput("N")
        ans = numpower(x, n)
        print("%d^%d is: %d\n" % (x, n, ans))
        print("press \"n\" to exit, any other key to cont.")
        inp = input()
        if inp.strip() == 'n':
            break
Example #6
0
def main():
    num = readinput()
    clist = findconstant(num)
    print("showing c values: ")
    print(clist)

    ch = input("based on above c values. enter c: ")
    c = float(ch)
    # c = clist[-1]
    print("Now Lets verify if for c=%0.2f the equation Fn <= 2^(c*n) holds" %
          (c))
    print("First lets choose \"n\" value")
    num = readinput()
    verifyc(c, num)
Example #7
0
File: ex03b.py Project: MotoLee/DPV
def main():
    num = readinput()
    clist = findconstant(num)
    print ("showing c values: ")
    print (clist)

    ch = input("based on above c values. enter c: ")
    c = float(ch)
    # c = clist[-1]
    print ("Now Lets verify if for c=%0.2f the equation Fn <= 2^(c*n) holds" %
           (c))
    print ("First lets choose \"n\" value")
    num = readinput()
    verifyc(c, num)
Example #8
0
def send_message(e, N):
    print ("Alish wishes to send message x to Bob")
    print ("She looks up his public key (N, e) and sends him message"
           " y = x^e mod N")
    x = readinput("message x")
    y = modular_exp(x, e, N)
    return y
Example #9
0
def main():
    clist = [0.5, 1, 2]
    print ("Please enter \"n\" value below")
    n = readinput()
    for c in clist:
        theta = calc_theta(c, n)
        print("for c:%0.2f and n:%d, theta is: %0.2f" % (c, n, theta))
Example #10
0
def main():
    num = readinput()
    for n in range(num+1):
        fib = findfibonacci(n)
        sys.stdout.write(str(fib) + " "),
    sys.stdout.write("\n")
    print ("Finding fibonacci through expression 2**(0.694*n)")
    for n in range(num):
        fib = findfibexpr(n)
        sys.stdout.write(str(fib) + " "),
    sys.stdout.write("\n")

    print ("Enter number for fast fibonacci")
    num = readinput()
    fib = findfibopoly(num)
    print ("fib %d is: %d" % (num, fib))
Example #11
0
def send_message(e, N):
    print("Alish wishes to send message x to Bob")
    print("She looks up his public key (N, e) and sends him message"
          " y = x^e mod N")
    x = readinput("message x")
    y = modular_exp(x, e, N)
    return y
Example #12
0
def main():
    num = readinput()
    for n in range(num + 1):
        fib = findfibonacci(n)
        sys.stdout.write(str(fib) + " "),
    sys.stdout.write("\n")
    print("Finding fibonacci through expression 2**(0.694*n)")
    for n in range(num):
        fib = findfibexpr(n)
        sys.stdout.write(str(fib) + " "),
    sys.stdout.write("\n")

    print("Enter number for fast fibonacci")
    num = readinput()
    fib = findfibopoly(num)
    print("fib %d is: %d" % (num, fib))
Example #13
0
def main():
    print("Fermat's little theorem for primality")
    print("If p is prime then for every 1 <= a < p")
    print("a^(p-1) ≡  1 (mod) p")
    p = readinput("prime candidate")
    if isprime(p):
        print("%d is Prime Number" % p)
    else:
        print("%d is Not a Prime Number" % p)
Example #14
0
def main():
    print ("Fermat's little theorem for primality")
    print ("If p is prime then for every 1 <= a < p")
    print ("a^(p-1) ≡  1 (mod) p")
    p = readinput("prime candidate")
    if isprime(p):
        print ("%d is Prime Number" % p)
    else:
        print ("%d is Not a Prime Number" % p)
Example #15
0
def main():
    a = readinput("x value")
    b = readinput("y value")
    x = bin(a)
    y = bin(b)
    x = x[2:]
    y = y[2:]
    xlen = len(x)
    ylen = len(y)
    diff = abs(xlen - ylen)
    z = "0" * diff
    if xlen < ylen:
        x = z + x
    elif ylen < xlen:
        y = z + y
    ans = multiply(x, y)
    print ("x in bin: ", x)
    print ("y in bin: ", y)
    print ("x * y = ", ans)
Example #16
0
def main():
    print("Fermat's little theorem for primality")
    print("If p is prime then for every 1 <= a < p")
    print("a^(p-1) ≡  1 (mod) p")
    p = readinput("prime candidate")
    if isprime(p):
        print("%d is Prime Number" % p)
    else:
        print("%d is Not a Prime Number" % p)
    for i in range(100000):
        if isprime(4):
            print("we are getting 4 as prime")
    print("Done!")
Example #17
0
def main():
    print ("Fermat's little theorem for primality")
    print ("If p is prime then for every 1 <= a < p")
    print ("a^(p-1) ≡  1 (mod) p")
    p = readinput("prime candidate")
    if isprime(p):
        print ("%d is Prime Number" % p)
    else:
        print ("%d is Not a Prime Number" % p)
    for i in range(100000):
        if isprime(4):
            print("we are getting 4 as prime")
    print ("Done!")
Example #18
0
def main():
    num = readinput("n >= 2")
    p = random_prime(num)
    print ("Random Prime less than %d: %d" % (num, p))
    test_random_prime()
Example #19
0
def main():
    x = readinput("X")
    y = readinput("Y")
    ans = division(x, y)
    print("%d / %d = Quotient: %d, Remainder: %d" % (x, y, ans[0], ans[1]))
Example #20
0
def main():
    num = readinput("n >= 2")
    p = random_prime(num)
    print("Random Prime less than %d: %d" % (num, p))
    test_random_prime()
Example #21
0
def main():
    num = readinput("which fibonacci number")
    fib = fibonacci(num)
    print("fib digit len: ", len(str(fib[0])))
    print("%d fibonacci is: %d" % (num, fib[0]))
    print("log(fib): ", math.log(fib[0], 2))
Example #22
0
def main():
    a = readinput("a")
    b = readinput("b")
    (x, y, d) = extended_euclid(a, b)
    print("ax + by = d")
    print("x=%d, y=%d, d=%d" % (x, y, d))
Example #23
0
def main():
    n = readinput("n value")
    count = checkinverses(n)
    print("%d integers have inverses with modulo %d" % (count, n))
Example #24
0
def main():
    num = readinput("which fibonacci? ")
    fib = get_fibonacci(num)
    print ("%d fibonacci: %d" % (num, fib))
Example #25
0
def main():
    x = readinput("X: ")
    y = readinput("Y: ")
    ans = french_mult(x, y)
    print("%d x %d: %d" % (x, y, ans))
Example #26
0
def main():
    num = readinput("n value for series")
    harmonic_series(num)
Example #27
0
def main():
    x = readinput("X: ")
    y = readinput("Y: ")
    ans = french_mult(x, y)
    print ("%d x %d: %d" % (x, y, ans))
Example #28
0
def main():
    a = readinput("a")
    b = readinput("b")
    (x, y, d) = extended_euclid(a, b)
    print ("ax + by = d")
    print ("x=%d, y=%d, d=%d" % (x, y, d))
Example #29
0
def main():
    print("empirical study of log(n!) = Θ(nlog(n))")
    n = readinput("n value")
    test_expression(n)
Example #30
0
def main():
    print("To calculate: X^(-1) mod N")
    x = readinput("X")
    n = readinput("N")
    ans = inverse_modulo(x, n)
    print("Ans: ", ans)
Example #31
0
def test_binary_converter():
    num = readinput("decimal number")
    bnum = tobinary(num)
    print ("binary: ", bnum)
Example #32
0
def main():
    n = readinput("n value")
    count = checkinverses(n)
    print("%d integers have inverses with modulo %d" % (count, n))
Example #33
0
def main():
    x = readinput("X")
    y = readinput("Y")
    ans = division(x, y)
    print("%d / %d = Quotient: %d, Remainder: %d" % (x, y, ans[0], ans[1]))
Example #34
0
def main():
    num = readinput("n value for series")
    harmonic_series(num)
Example #35
0
def main():
    print ("To calculate: X^(-1) mod N")
    x = readinput("X")
    n = readinput("N")
    ans = inverse_modulo(x, n)
    print ("Ans: ", ans)
Example #36
0
def main():
    num = readinput("which fibonacci number")
    fib = fibonacci(num)
    print ("fib digit len: ", len(str(fib[0])))
    print ("%d fibonacci is: %d" % (num, fib[0]))
    print ("log(fib): ", math.log(fib[0], 2))