The origin of the most energetic particles in nature, the ultra-high-energy (UHE) cosmic rays, is still a mystery. Only the most energetic of these have sufficiently small angular deflections to be used for directional studies, and their flux is so low that even the 3,000 km^2 Pierre Auger detector registers only about 30 cosmic rays per year of these energies. A method to provide an even larger aperture is to use the lunar Askaryan technique, in which ground-based radio telescopes search for the nanosecond radio flashes produced when a cosmic ray interacts with the Moons surface. The technique is also sensitive to UHE neutrinos, which may be produced in the decays of topological defects from the early universe. Observations with existing radio telescopes have shown that this technique is technically feasible, and established the required procedure: the radio signal should be searched for pulses in real time, compensating for ionospheric dispersion and filtering out local radio interference, and candidate events stored for later analysis. For the Square Kilometre Array (SKA), this requires the formation of multiple tied-array beams, with high time resolution, covering the Moon, with either SKA1-LOW or SKA1-MID. With its large collecting area and broad bandwidth, the SKA will be able to detect the known flux of UHE cosmic rays using the visible lunar surface - millions of square km - as the detector, providing sufficient detections of these extremely rare particles to address the mystery of their origin.