#!/usr/bin/python import sys def to_digits(num, base): digits = [] while num > 0: digits.insert(0, num % base) num = num // base return digits fobj = open(sys.argv[1]) fp = sys.argv[2].replace(' ', '') word_list = dict([(line[0:5], line[6:].strip()) for line in fobj if line[0:5].isdigit() and line[5].isspace() ]) rolls = to_digits(int(fp, 16), 6)+[0,0,0] # Need to pad this out to the diceware size roll_sets = [''.join([chr(n+ord('1')) for n in rolls[n:n+5]]) for n in range(0, len(rolls), 5)] words = [word_list[roll_set] for roll_set in roll_sets] print 'OpenPGP fingerprint diceware: ' + ' '.join(words)