An approach to finding codes for use in direct sequence spread spectrum communications systems is described. It is based upon an analogy between codes having auto-and cross-correlation properties desirable for spread spectrum systems, and certain dynamical systems encountered in ergodic theory called systems with Lebesgue spectrum. Such systems are associated with collections of orthogonal functions and these functions can be used to generate collections of time series with zero cross-correlation functions. To generate codewords we must use truncated versions of these time series, for which the cross-correlations are no longer precisely zero: these truncated sequences correspond to periodic orbits of the dynamical system. The method for finding a code from a suitable periodic orbit is described, and an example, using a simple dynamical system known as the doubling map, is worked through in some detail.