def METHOD_NAME(edata: bytes, nlkm: bytes, ch, xp: bool):
    if xp:
        hmac_md5 = HMAC.new(nlkm, ch)
        rc4key = hmac_md5.digest()
        rc4 = ARC4.new(rc4key)
        data = rc4.encrypt(edata)  # lgtm [py/weak-cryptographic-algorithm]
    else:
        # Based on code from http://lab.mediaservice.net/code/cachedump.rb
        aes = AES.new(nlkm[16:32], AES.MODE_CBC, ch)
        data = b""
        for i in range(0, len(edata), 16):
            buf = edata[i : i + 16]
            if len(buf) < 16:
                buf += (16 - len(buf)) * b"\00"
            data += aes.decrypt(buf)
    return data