#!/usr/libexec/platform-python

# Script that uses the fletcher8 algorithm to generate a hash from an input
# string. This is used to generate VRRP ids for use with Keepalived.
#
# https://en.wikipedia.org/wiki/Fletcher%27s_checksum

import sys

data = map(ord, sys.argv[1])
ckA = ckB = 0

for b in data:
    ckA = (ckA + b) & 0xf
    ckB = (ckB + ckA) & 0xf
print((ckB << 4) | ckA )
