<commit_before># Copyright 2017 <NAME>

import re

password_re = re.compile(r'^(?P<salt_index>[01]\d)(?P<encrypted_text>[0-9a-f]{1,25})', re.I)


TRANSLATION_KEY='<KEY>'

# Following https://pen-testing.sans.org/resources/papers/gcih/cisco-ios-type-7-password-vulnerability-100566

def decode(password):
    decoded_password = ''
    if not password_re.match(password):
        return 'Invalid Type 7 Password'
    salt= int(password[0:2])
    for password_index in range(2,len(password),2):
        decoded_password += chr(int(password[password_index] \
            + password[password_index+1], 16) \
            ^ ord(TRANSLATION_KEY[salt]))
        salt += 1
        if salt==53:salt=0

    return decoded_password<commit_msg>code comments and readability<commit_after># Copyright 2017 <NAME>

import re

password_re = re.compile(r'^(?P<salt_index>[01]\d)(?P<encrypted_text>[0-9a-f]{1,25})', re.I)


TRANSLATION_KEY_MAP = '<KEY>'

# Following https://pen-testing.sans.org/resources/papers/gcih/cisco-ios-type-7-password-vulnerability-100566

def decode(password):
    decoded_password = ''
    if not password_re.match(password):
        return 'Invalid Type 7 Password'

    # Example Password:
    #   Encoded: <PASSWORD>
    #   Decoded: password

    # "<PASSWORD>36435C0D" -> "04" -> 4
    translation_key_index = int(password[0:2])

    # Example is decoding the 'p' from 'password'
    for password_index in range(2,len(password),2):

        # Step 1
        # Get the encoded value

        # Encoded '044B0A151C36435C0D' -> '4B'
        encoded_value = password[password_index:password_index + 2]
        
        # Hex to integer '4B' -> 75
        encoded_value = int(encoded_value, 16)

        # Step 2
        # Get the translation key

        # 'dsfd;kfoA,.iyewrkldJKDHSUBsgvca69834ncxv9873254k;fg87'[4] -> ';'
        translation_key = TRANSLATION_KEY_MAP[translation_key_index]

        # Unicode code point of the tranlation key character
        # ';' -> 59
        translation_key = ord(translation_key)

        # Step 3
        # Preform the decode

        # XOR (^) 75 ^ 59 -> 112
        decoded_value = encoded_value ^ translation_key

        # decoded_password += chr(int(password[password_index] \
        #     + password[password_index+1], 16) \
        #     ^ ord(TRANSLATION_KEY[salt]))
        # salt += 1

        # char(112) -> 'p'
        decoded_password += chr(decoded_value)

        # Step 4:
        # Setup for the next round of decoding
        
        translation_key_index += 1

        if translation_key_index == 53:
            translation_key_index = 0

    return decoded_password
{'fraction_non_alphanumeric': 0.12239484653277757, 'fraction_numerical': 0.045850701023114816, 'mean_word_length': 2.755334281650071, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1276571', 'n_tokens_mistral': 978, 'n_tokens_neox': 857, 'n_words': 169}