python - Error with len() function or something else? -
so i've been trying programme loop through pke equation e
changing 15 times list. thought had solved in print statement instead of len
printing single number each exponent it's lopping through , printing number every unique number has. i'm having problem seeing i'm going wrong. programme this:
def greatest_common_divisor(a_int, b_int): if a_int > b_int: dividend = a_int divisor = b_int else: # b >= dividend = b_int divisor = a_int remainder = dividend % divisor quotient = dividend // divisor while remainder != 0: dividend = divisor divisor = remainder remainder = dividend % divisor quotient = dividend // divisor homecoming divisor # gcd p =5 q = 7 n = p*q header = ["p","q","n","e","diminished","gcd","unique remainders","max remainders"] print(header) e in range(12,27): unique_remainders_list = [] x in range(1,(n+1)): y = x**e % n diminished = (p - 1)*(q - 1) gcd = greatest_common_divisor(e, diminished) max_uni_val = n-1 if not (y in unique_remainders_list): unique_remainders_list.append(y) print("{:>2} {:>4} {:>6} {:>4} {:>10} {:>9} {:>10} {:>16}".\ format(p,q,n,e,diminished,gcd,len(unique_remainders_list),max_uni_val, end = ' '))
example of print:
['p', 'q', 'n', 'e', 'diminished', 'gcd', 'unique remainders', 'max remainders'] 5 7 35 12 24 12 1 34 5 7 35 12 24 12 2 34 5 7 35 12 24 12 3 34 5 7 35 12 24 12 4 34 5 7 35 13 24 1 1 34 5 7 35 13 24 1 2 34 5 7 35 13 24 1 3 34 5 7 35 13 24 1 4 34 5 7 35 13 24 1 5 34 5 7 35 13 24 1 6 34 5 7 35 13 24 1 7 34 5 7 35 13 24 1 8 34
so think i'm having problem range of e in end, i'm not sure where.
figured out, needed move print statement over. hate when miss such little things, help hagubear.
for e in range(12,27): unique_remainders_list = [] x in range(1,(n+1)): y = x**e % n diminished = (p - 1)*(q - 1) gcd = greatest_common_divisor(e, diminished) max_uni_val = n-1 if not (y in unique_remainders_list): unique_remainders_list.append(y) print("{:>2} {:>4} {:>6} {:>4} {:>10} {:>9} {:>10} {:>16}".\ format(p,q,n,e,diminished,gcd,len(unique_remainders_list),max_uni_val, end = ' '))
python
No comments:
Post a Comment