import re


def fix_name_caps_for_output(name):
    """Returns a version of the given algorithm name with capitalization fixed."""
    # It's important that this must only change the capitalization of the
    # name, not any of its text, otherwise future runs won't be able to
    # match this name with the name coming from the device.

    # We current make the following capitalization fixes
    # DESede (not DESEDE)
    # FOOwithBAR (not FOOWITHBAR or FOOWithBAR)
    # Hmac (not HMAC)
    name = re.sub('WITH', 'with', name, flags=re.I)
    name = re.sub('DESEDE', 'DESede', name, flags=re.I)
    name = re.sub('HMAC', 'Hmac', name, flags=re.I)
    return name