  The flux of ultrahigh energy cosmic rays reaching the Earth is affected by
the interactions with the cosmic radiation backgrounds as well as with the
magnetic fields that are present along their trajectories. We combine the
SimProp cosmic ray propagation code with a routine that allows to account for
the average effects of a turbulent magnetic field on the direction of
propagation of the particles. We compute in this way the modification of the
spectrum which is due to the magnetic horizon effect, both for primary nuclei
as well as for the secondary nuclei resulting from the photo-disintegration of
the primary ones. We also provide analytic parameterizations of the attenuation
effects, as a function of the magnetic field parameters and of the density of
cosmic ray sources, which make it possible to obtain the expected spectra in
the presence of the magnetic fields from the spectra that would be obtained in
the absence of magnetic fields. The discrete nature of the distribution of
sources with finite density also affects the spectrum of cosmic rays at the
highest energies where the flux is suppressed due to the interactions with the
radiation backgrounds, and parameterizations of these effects are obtained.
