From fccbdf1e7cb5ffa1299bf0da92d9b2759e5a339d Mon Sep 17 00:00:00 2001 From: Rich Wareham Date: Fri, 17 Sep 2010 12:41:26 +0100 Subject: [PATCH] output hex strings in JSON rather than numbers Apparently the precise precision JavaScript has for storing integers may not quite be enough. We push this problem downstream by saving the hexadecimal representation of the key rather than the number itself. --- generate_key.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/generate_key.py b/generate_key.py index dac11fa..92531c4 100755 --- a/generate_key.py +++ b/generate_key.py @@ -179,8 +179,10 @@ def output_json(ksv, key, is_sink): The KSV is a single integer. The key is a list of 40 integers.""" - print(json.dumps( - { 'ksv': ksv, 'key': key, 'type': 'sink' if is_sink else 'source' }, + print(json.dumps( { + 'ksv': ('%010x' % ksv), + 'key': map(lambda x: '%014x' % x, key), + 'type': 'sink' if is_sink else 'source' }, sort_keys=True, indent=True)) # run the 'main' function if this file is being executed directly