Beispiel #1
0
 def combine(self, shares):
     words = set([len(x.split(' ')) for x in shares])
     if len(words) != 1:
         raise Exception('Inconsistent number of words')
     datalen = list(words)[0] * 4 / 3 - 1
     shares = [binascii.hexlify(self.mnemo.to_entropy(x)) for x in shares]
     if set([int(x[0], 16) for x in shares]) != set([len(shares)]):
         raise Exception('Number of shares does not match the threshold')
     points = [(int(x[1], 16), int(x[2:], 16)) for x in shares]
     prime = self.primes[datalen]
     r = points_to_secret_int(points, prime)
     r = hex(r)[2:-1].zfill(datalen * 2)
     return binascii.unhexlify(r)
	def combine(self, shares):
		words = set([ len(x.split(' ')) for x in shares ])
		if len(words) != 1:
			raise Exception('Inconsistent number of words')
		datalen = list(words)[0] * 4 / 3 - 1
		shares = [ binascii.hexlify(self.mnemo.to_entropy(x)) for x in shares ]
		if set([ int(x[0], 16) for x in shares ]) != set([len(shares)]):
			raise Exception('Number of shares does not match the threshold')
		points = [ ( int(x[1], 16), int(x[2:], 16) ) for x in shares ]
		prime = self.primes[datalen]
		r = points_to_secret_int(points, prime)
		r = hex(r)[2:-1].zfill(datalen * 2)
		return binascii.unhexlify(r)
def decrypt(votername, votesize, share, config):
    """Receive aggregate secret share and decrypt if possible."""

    state = config["state"]
    state["decrypting"] = True

    if not "decryption" in state:
        state["decryption"] = {}

    if not votername in [name for (name, key) in state["counterkeys"]]:
        print("You are not a vote counter!", file=sys.stderr)
        return

    if votesize != len(state["votes"]):
        print("Inconsistent number of votes, sync up!", file=sys.stderr)
        return

    state["decryption"][votername] = share.split(",")

    if len(state["counterkeys"]) == len(state["decryption"]):
        countervotes = list(state["decryption"].values())
        ncounters = len(countervotes)

        shares = [[parsepoint(countervotes[i][k]) for i in range(ncounters)]
                  for k in range(config["schedulesize"])]
        tally = [
            points_to_secret_int(row, config["megaprime"]) for row in shares
        ]

        print(countervotes, file=sys.stderr)
        print(shares, file=sys.stderr)
        print(tally, file=sys.stderr)

        state["finaltally"] = tally

        tallyfname = os.path.join("server", "public", "tally.json")

        with open(tallyfname, "w") as tallyfile:
            tallyfile.write(json.dumps(tally))
Beispiel #4
0
from secretsharing import secret_int_to_points, points_to_secret_int
from secretsharing import SecretSharer
import binascii


myshares = [(1, 9608474170977308238036624146101441469538628637045706610338073590812843162969037926492967854559828114435865261425719619743472419864336210874222029453059741L),
            (2, 68500755079349789351078524541708453870296292990294021018027228505078681492284299873863659247273461856762128786874833326789786067325816477066780304059822843L),
            (3, 224183841656780872927678242626279871433733831057475254917387185998520511272846647279913467443558309288829498488402883425874249712684215384203475752039681175L),
            (4, 524164732834933988556388319839274528391312080836319720002737667326861328789556912063222725295339950383555529443266354316704089242529615243887408038702736241L),
            (5, 1015950427545472565825761297620151258974491880324557727968398393745824130327315926142371765654543965113857776728721730398986530543452098367721676829359089545L)]



# for item in myshares:
#     print(hex(item[1]).rstrip("L").lstrip("0x"))

# get the int Long secret from the shares
s = points_to_secret_int(myshares)
print("Secret INT: {}".format(s))
# convert to hex, but remove 0x and L (LONG) from it
myhex = hex(int(s)).replace("0x", "").replace("L","")
# print(myhex)
# convert to b64
mybase64 = binascii.b2a_base64(binascii.unhexlify(myhex)).replace("\n", "")
# print(mybase64)
# convert base64 to raw
myraw = binascii.a2b_base64(mybase64).decode()
print("Flag: {}".format(myraw))
Beispiel #5
0
def summed_points_to_plain_sum(spvs, prime):
    npl = len(spvs)  # The number of players
    # To reconstruct, we take the first players-1 points, but leaving out any one point is possible.
    plain_sum = points_to_secret_int(spvs[0 : (npl - 1)], prime)
    return plain_sum
def recover_splits(splits):
    return points_to_secret_int(splits)
Beispiel #7
0
import secretsharing  # need version from git
import binascii

x = [31337, 1337, 735]
y = [74755106547149950494298118376047078452,
     328103284834185548901467840973205257218,
     234731986215211726774334392959253481398]
p = 340282366920938463463374607431768211507

points = zip(x,y)

secret = secretsharing.points_to_secret_int(points, p)
secret = binascii.unhexlify('%x' % secret)
print secret