generate and check codes