def decrypt_string()

in nightMARE/src/nightmare/malware/lobshot/crypto.py [0:0]


def decrypt_string(encrypted_string: bytes) -> bytes:
    """
    The function decrypt a string using LOBSHOT custom decryption algorithm
    :param encrypted_string: Encrypted string we want to decrypt
    :return: Decrypted string
    """

    buffer = bytearray([0 for _ in range(len(encrypted_string) // 2)])

    flag = False
    z = 0
    index = 0
    index2 = 2

    for i, x in enumerate(encrypted_string):
        try:
            y = encrypted_string[index + 1] - 0x61
            index += 2

            if flag:
                buffer[i] = 0x53 ^ z ^ (y | (16 * encrypted_string[index2] - 16)) & 0xFF
                index2 += 2
            else:
                flag = True
                z = y | (16 * (x - 1)) & 0xFF
        except (IndexError, ValueError):
            continue

    buffer = buffer[1:]
    return bytes(buffer)