# -*- coding: utf-8 -*-
# Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
# Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
# denoted as "the implementer".
#
# For more information, feedback or questions, please refer to our websites:
# http://keccak.noekeon.org/
# http://keyak.noekeon.org/
# http://ketje.noekeon.org/
#
# To the extent possible under law, the implementer has waived all copyright
# and related or neighboring rights to the source code in this file.
# http://creativecommons.org/publicdomain/zero/1.0/

import CompactFIPS202
import base64
import binascii
import io
import sys

instance=(1344, 256, 0x1F, 256)
# instance=(1344, 256, 0x01, 128) would be Keccak with standard parameters, except length
if sys.argv[1] == '-l':
    x = int(sys.argv[2])
    fileName = sys.argv[3]
    instance=(1344, 256, 0x1F, x*8)
else:
    fileName = sys.argv[1]
try:
    with open(fileName, 'rb') as f:
        b = bytearray(f.read())
        (r, c, s, n) = instance
        h = CompactFIPS202.Keccak(r, c, b, s, n//8)
        print(bytes.decode(binascii.hexlify(h)))
except IOError:
    pass
except:
    raise