Solution of the phase problem is central to crystallographic structure determination. An oversampling method is proposed, based on the hybrid inputoutput algorithm (HIO) [Fienup (1982). Appl. Opt.21, 27582769], to retrieve the phases of reflections in crystallography. This method can extend low-resolution structures to higher resolution for structure determination of proteins without additional sample preparation. The method requires an envelope of the protein which divides a unit cell into the density region where the proteins are located and the non-density region occupied by solvents. After a few hundred to a few thousand iterations, the correct phases and density maps are recovered. The method has been used successfully in several cases to retrieve the phases from the experimental X-ray diffraction data and the envelopes of proteins constructed from structure files downloaded from the Protein Data Bank. It is hoped that this method will greatly facilitate the ab initio structure determination of proteins.