Created check digit calculation function