├── README.md └── bihu-airdrop-tool.py /README.md: -------------------------------------------------------------------------------- 1 | # bihu-tools 2 | 3 | ## bihu-airdrop-tool.py 4 | 5 | 1. 币乎官方会给每个合格的参与者, 分配一个奖券号,从1开始的整数。 6 | 2. 币乎官方会在空投活动开始前,公布比特币未来的某个区块号,比如1000。 7 | - 并使用这个区块的hash,计算一个luck number 8 | - luck_num = hash1(hash2(...hash(n)(block.hash))) 9 | 3. 对每一个奖券号,计算得分score. 10 | - score = hash( luck_num + 奖券号) % base 11 | 4. 依据得分排序,最高的一等奖,以此等等。 12 | 13 | Demo: 14 | https://repl.it/@clar1/bihu-airdrop-reward 15 | -------------------------------------------------------------------------------- /bihu-airdrop-tool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import hashlib 4 | from collections import OrderedDict 5 | 6 | airdrop_prefix = 'AA' 7 | # block hash 8 | block_hash = bytes.fromhex('0000000000000000003729bfa376e4148ee0643ce834053d885af5699440d6d3') 9 | # total lottery num 10 | total_lottery = 1000 11 | 12 | 13 | 14 | def lucky_num_from_block_hash(h): 15 | hash_names = ['md5', 'md4', 'whirlpool', 'RIPEMD160', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'] 16 | print(str(len(hash_names)) + ": " + str(hash_names)) 17 | 18 | repeat = 10000 * 400 * 20 19 | r = h 20 | for i in range(repeat): 21 | if i % 100000 == 0: 22 | print(str(i) + ":...") 23 | for n in hash_names: 24 | h = hashlib.new(n) 25 | h.update(r) 26 | r = h.digest() 27 | 28 | return r 29 | 30 | 31 | def score_for_each_lottery(lucky_num, lottery_id): 32 | # print(result_hash.hex()) 33 | h = hashlib.sha256() 34 | h.update(lucky_num) 35 | h.update(bytes(lottery_id)) 36 | 37 | base = 10**11 38 | score = int(h.hexdigest(), 16) % base 39 | return score 40 | 41 | 42 | def compute_airdrop_reward(): 43 | r = {} 44 | lucky_num = lucky_num_from_block_hash(block_hash) 45 | 46 | for lottery_id in range(1, total_lottery + 1): 47 | s = score_for_each_lottery(lucky_num, lottery_id) 48 | r[lottery_id] = s 49 | return r 50 | 51 | 52 | def lottery_format(n): 53 | return airdrop_prefix + '-' + str(n).zfill(7) 54 | 55 | 56 | def dump_rewards_to_file(rewards): 57 | c = 1 58 | f = open('rewards.txt', 'w') 59 | for r in rewards: 60 | f.write(str(c) + ',' + lottery_format(r) + ',' + str(rewards[r]) + '\n') 61 | c += 1 62 | 63 | f.close() 64 | 65 | reward_map = compute_airdrop_reward() 66 | reward_sorted = OrderedDict(sorted(reward_map.items(), key=lambda t: t[1], reverse = True)) 67 | print("=======================Rewards================================") 68 | 69 | dump_rewards_to_file(reward_sorted) 70 | --------------------------------------------------------------------------------