예제 #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))
예제 #2
0
파일: gcd.py 프로젝트: 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))
예제 #3
0
파일: modulo_expo.py 프로젝트: MotoLee/DPV
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))
예제 #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))
예제 #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
예제 #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)
예제 #7
0
파일: ex03b.py 프로젝트: 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)
예제 #8
0
파일: rsa_demo.py 프로젝트: MotoLee/DPV
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
예제 #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))
예제 #10
0
파일: fibonacci.py 프로젝트: MotoLee/DPV
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))
예제 #11
0
파일: rsa_demo.py 프로젝트: zamiljitu/DPV
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
예제 #12
0
파일: fibonacci.py 프로젝트: zamiljitu/DPV
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))
예제 #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)
예제 #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)
예제 #15
0
파일: multiply.py 프로젝트: zamiljitu/DPV
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)
예제 #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!")
예제 #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!")
예제 #18
0
파일: random_prime.py 프로젝트: MotoLee/DPV
def main():
    num = readinput("n >= 2")
    p = random_prime(num)
    print ("Random Prime less than %d: %d" % (num, p))
    test_random_prime()
예제 #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]))
예제 #20
0
def main():
    num = readinput("n >= 2")
    p = random_prime(num)
    print("Random Prime less than %d: %d" % (num, p))
    test_random_prime()
예제 #21
0
파일: fib_matrix.py 프로젝트: MotoLee/DPV
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))
예제 #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))
예제 #23
0
파일: ex_1_21.py 프로젝트: zamiljitu/DPV
def main():
    n = readinput("n value")
    count = checkinverses(n)
    print("%d integers have inverses with modulo %d" % (count, n))
예제 #24
0
파일: fib_formula.py 프로젝트: MotoLee/DPV
def main():
    num = readinput("which fibonacci? ")
    fib = get_fibonacci(num)
    print ("%d fibonacci: %d" % (num, fib))
예제 #25
0
def main():
    x = readinput("X: ")
    y = readinput("Y: ")
    ans = french_mult(x, y)
    print("%d x %d: %d" % (x, y, ans))
예제 #26
0
파일: ex_1_5.py 프로젝트: zamiljitu/DPV
def main():
    num = readinput("n value for series")
    harmonic_series(num)
예제 #27
0
def main():
    x = readinput("X: ")
    y = readinput("Y: ")
    ans = french_mult(x, y)
    print ("%d x %d: %d" % (x, y, ans))
예제 #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))
예제 #29
0
파일: ex_1_4.py 프로젝트: MotoLee/DPV
def main():
    print("empirical study of log(n!) = Θ(nlog(n))")
    n = readinput("n value")
    test_expression(n)
예제 #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)
예제 #31
0
파일: ex_1_2.py 프로젝트: MotoLee/DPV
def test_binary_converter():
    num = readinput("decimal number")
    bnum = tobinary(num)
    print ("binary: ", bnum)
예제 #32
0
파일: ex_1_21.py 프로젝트: MotoLee/DPV
def main():
    n = readinput("n value")
    count = checkinverses(n)
    print("%d integers have inverses with modulo %d" % (count, n))
예제 #33
0
파일: division.py 프로젝트: MotoLee/DPV
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]))
예제 #34
0
파일: ex_1_5.py 프로젝트: MotoLee/DPV
def main():
    num = readinput("n value for series")
    harmonic_series(num)
예제 #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)
예제 #36
0
파일: fib_matrix.py 프로젝트: zamiljitu/DPV
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))