As far as I know there is no algorithm that you can use. There is an algorithm which I list below, however, the DES keys are only known by the bank so you would not be able to generate it. I tried a couple of those CVV2 generators you can find online and they either calculated the wrong CVV2 code or were malware.
Primary Account Number (PAN), a 4-digit Expiration Date, a 3-digit Service Code, and a pair of DES keys (CVKs).