Repair key generating function