X-ray crystallography is an experimental technique to estimate the 3D atomic positions of the elements present in a crystal. This technique constructs the 3D structure from the phase of diffracted and patterned X-rays (DPX). Multiple intensity DPX measurements are acquired to solve the phase retrieval problem. The feasibility of implementing this technique depends on solving the phase retrieval problem using expensive multiple valued patterns and the Truncated Wirtinger Flow Algorithm. This paper presents a Stochastic Truncated Wirtinger Flow Algorithm (STWF) which solves the phase retrieval problem based on DPX measurements low-cost boolean block-unblock coded apertures. Several simulations are realized to demonstrate the convergence of the STWF algorithm and the optimal parameters of the boolean coded apertures. The results indicate that given the DPX measurements, the quality of reconstructed phase images using STWF attained up 24:63dB of PSNR.