I'm looking for a definition of algorithm how to calculate CVV/CVC codes?

I know that there are the following inputs:

  • PAN Expiration
  • Date
  • Service Code
  • CVK A/B

But I'm not able to find the specific algorithm definition what should be done exactly to get the 3 digit CVV/CVC code. Is there a documentation somewhere in VISA/Mastercard?

To be clear, I'm not looking into how to forge their existing cards, I would like to calculate code using my own test keys.