# randfake(m, j) = fake random number generator for interval [0, m-1], # j = calling order def randfake(m, j): return (127*j + 307)%m # c2a(s) = list of ASCII codes for string s def c2a(s): return [ord(j) for j in s] # a2c(v) = string represented by list of ASCII codes v def a2c(v): u = [chr(j) for j in v] w = join(u, "") return(w) # numell(E, q=0) = number of points on elliptic curve E # in finite field of size q # # For now if E is tied to a finite field and q is provided, insist # that q is the size of the field. def numell(E, q=0): En = E.base_field().order() if q > 0: if En < +Infinity: if q != En: print "Curve is attached to field of size ", En return(-1) num = E.order() return num else: Er = E.reduction(q) num = Er.order() return num else: if En < +Infinity: return E.order() else: return +Infinity # pointstocodes(tries, ptlist) = list of ascii codes # Subtle point: the coordinates of points in this context are integer_mods def pointstocodes(tries, ptlist): codes = [] for q in ptlist: t = floor( ( lift(q[0])-1 )/tries ) codes.append(t) return codes # codestopoints(curve, prime, tries, codelist) # = list of points on "curve" over field of "prime" elements based # on finding the first x-coordinate among mx+1, mx+2, mx+m def codestopoints(curve, prime, tries, codelist): pts = [] e = curve.reduction(prime) for c in codelist: flag = False for j in range(1, tries+1): x = tries*c + j if e.is_x_coord(x): ptt = e.lift_x(x) flag = True break if flag == True: if ptt.order() == 1: print "Origin shows up on curve for code ", c return [] else: pt = [ptt[0], ptt[1]] else: print "Failed to find a point on curve for code ", c return [] pts.append(pt) return pts