Jump to content

tullyvey

Member
  • Posts

    3
  • Joined

Everything posted by tullyvey

  1. I'm going to be in London around the 5th-10th of February. If anyone would like to meet for a (hopefully) stimulating conversation, I'd be delighted!
  2. Hey, just saw this post and thought I'd offer an idea. I assume everyone has registered with your website, or that you have some way of assembling a file with the name of each entrant on a separate line. These names are combined with the name of the competition to create a list of hashes to be published. The general principle could be implemented in a number of ways, but here I'll offer a quick solution in Python (either 2.7 or 3). from hashlib import sha256hashes = []COMPETITION = b"Wesley's Wonderful Winners"with open('entrants.txt', 'rb') as f: for line in f: if not line: continue to_hash = COMPETITION + line.strip() entrant_hash = sha256(to_hash).hexdigest().encode('utf-8') hashes.append(entrant_hash)hashes = sorted(hashes)with open('entrant_hashes.txt', 'wb') as f: f.write(COMPETITION + b'n') f.write(b'=' * len(COMPETITION) + b'nn') for entrant_hash in hashes: f.write(entrant_hash + b'n') This reads in a file called "entrants.txt" and outputs "entrant_hashes.txt" which will look like ths following: Wesley's Wonderful Winners==========================0f23540bd360c4caff2a521f39bd6b4c217634ea895a4454c78620b10cf38f2816db7cf51b5dbd4305feacff41c42526b109ac15d1e9287d9eb981014d620b4a7ee5bbc0defb83aa1ef61ae35644523daf2b1202156ccfbf5bf5642ae37455b8d080b46dff919c649f6d609946a1a04c007d50aa54ceaa3bbfafb0859e051132... This is published before the draw, along with the method, so everyone can verify they are entered in the draw. Now you need to have some public and unpredictable information, such as lottery numbers, newspaper headline, top page of reddit, weather information, i.e. something which everyone can agree on such that it's infeasible that anyone involved would influence it. For instance, you could say that at 18:00 UTC you'll take the name of the top link on the front page of imgur. That is "Pastry folding 101" at the time of writing. You take a screenshot for proof, and anyone else online at that time can confirm. That secret is then concatenated to the list of entrant hashes and the whole thing is hashed. That is converted into an index into the list of hashes and there's your winner! Here's a script to do it for you: from hashlib import sha256COMPETITION = b"Wesley's Wonderful Winners"OPEN_SECRET = b"Pastry folding 101"hashes = []entrant_dict = {}with open('entrants.txt', 'rb') as f: for line in f: if not line: continue to_hash = COMPETITION + line.strip() entrant_hash = sha256(to_hash).hexdigest().encode('utf-8') entrant_dict[entrant_hash] = line hashes.append(entrant_hash)hashes = sorted(hashes)hash_data = (COMPETITION + b'n' + b'=' * len(COMPETITION) + b'nn' + b'n'.join(hashes)) # recreate entrant_hashes.txt in memory# perhaps need to make another that just reads the file of hashes# so everyone else can verify which hash was pickedto_hash = hash_data + OPEN_SECRETindex_hash = sha256(to_hash).hexdigest()winner_index = int(index_hash, 16) % len(hashes)winner_hash = hashes[winner_index]winner = entrant_dict[winner_hash]print("Winner is: {}".format(winner.decode())) Hope this helps, or at least that someone finds it interesting!
  3. West Wales
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.