In this paper we study the problem of finding maximally sized subsets of binary strings (codes) of equal length that are immune to a given number r of repetitions, in the sense that no two strings in the code can give rise to the same string after r repetitions. We propose explicit number theoretic constructions of such subsets. In the case of r = 1 repetition, the proposed construction is asymptotically optimal. For r ≥ 1, the proposed construction is within a constant factor of the best known upper bound on the cardinality of a set of strings immune to r repetitions. Inspired by these constructions, we then develop a prefixing method for correcting any prescribed number r of repetition errors in an arbitrary binary linear block code. The proposed method constructs for each string in the given code a carefully chosen prefix such that the the resulting strings are all of the same length and such that despite up to any r repetitions in the concatenation of the prefix and the codew...