def main(): l = 2201426263 p = 6 * l - 1 F = ExtendedFiniteField(p, "x^2+x+1") E = EllipticCurve(F, 0, 1) i = 3 while True: y = E.get_corresponding_y(i) if y != None: P = E(i, y) if (l * P).is_infinity(): break i += 1 print P rand = [randint(2**31, 2**32) for _ in xrange(10)] print "[+] Weil Pairing: " for x in rand: print weil_pairing(E, P, (x * P).distortion_map(), l)
from ecpy import ExtendedFiniteField, EllipticCurve, MapToPoint from ecpy import symmetric_tate_pairing import hashlib import cPickle # some secret here secret = 0xdeadbeef p = int("519130854181216822940010183929228824799903608965854344652247095061840" "171046331806216450362399027718738907160814923275136184823731671523533" "69121135029626237") l = (p + 1) / 6 F = ExtendedFiniteField(p, "x^2+x+1") E = EllipticCurve(F, 0, 1) P = E(6, (int("132232566129358054566854866197859888282113525457609791458267738" "093383172947853439119386209153000327873055642240731797496321750" "04531990130007962275678599731"), int("264465132258716109133709732395719776564227050915219582916535476" "186766345895706878238772418306000655746111284481463594992643500" "09063980260015924551357199462"))) sP = secret * P def sign(m): global secret, E, l # Q = MapToPoint(m) # return secret * Q h = int(hashlib.sha512(m).hexdigest(), 16) return secret * MapToPoint(E, E.field(h))
def main(): # PKI secret secret = 0xdeadbeef # 3735928559 # 標数(もちろん素数) 155桁 p = int( "501794446334189957604282155189438160845433783392772743395579628617109" "929160215221425142482928909270259580854362463493326988807453595748573" "76419559953437557") # print len(str(p)) # l = (p + 1) / 6 l = 8363240772236499293404702586490636014090563056546212389926327143618498819336920357085708048815154504326347572707724888783146790893262476229403259992239593 F = ExtendedFiniteField(p, "x^2+x+1") # Fは複素数平面 E = EllipticCurve(F, 0, 1) # y^2 = x^3 + 1 P = E( 3, int("1418077311270457886139292292020587683642898636677353664354101171" "7684401801069777797699258667061922178009879315047772033936311133" "535564812495329881887557081")) sP = E( int("129862491850266001914601437161941818413833907050695770313188660767" "152646233571458109764766382285470424230719843324368007925375351295" "39576510740045312772012"), int("452543250979361708074026409576755302296698208397782707067096515523" "033579018123253402743775747767548650767928190884624134827869137911" "24188897792458334596297")) decrypt_time = "0111" setup = Setup(P, sP, secret, l, F, E) print("P=", P) print("sp=", sP) print("Decryption Time:", decrypt_time) time_key = setup.create_time_key(decrypt_time) time_key = time_key[0] # sHT0を抽出 print("time_key = ", time_key) print("[+] Message? :", ) # m = int(input().strip().encode("hex"), 16) m = input() m = m.strip() m = binascii.hexlify((m.encode())) m = int(m, 16) print(m) print("----Encrypt----") encryption = Encryption(P, sP, l, F, E) # C[0]:Enc, C[1]:rP C = encryption.encrypt(m, decrypt_time) print("Enc(sT0,m) = (Your Encrypt Message):", C[0]) print("rP:", C[1]) print("----Decrypt----") decryption = Decryption(P, sP, l, F, E) m = decryption.decrypt(time_key, C) print("sT0 = ", C[0]) print("m(int):", m) # m = hex(m)[2:-1] m = '%02x' % m if len(m) % 2 == 1: m = "0" + m m = binascii.unhexlify(m) m = m.decode() print("[+]Your message :", m) print("-----Is time key correct ? --------") check = Check(P, sP, l, F, E) print("d=", decrypt_time) HT = check.time_to_ecc_check(str(decrypt_time)) check.check_time_key(time_key, HT) print("-----Decrypt (Time = 0000)-------") demo_key = setup.create_time_key("0000") # print demo_key demo_key = demo_key[0] # shT0を抽出 try: m = decryption.decrypt(demo_key, C) print("m(int):", m) m = hex(m)[2:-1] if len(m) % 2 == 1: m = "0" + m m = m.decode("hex") print("[+]Your message:", m) except: print("NOT CORRECT !")