# Given a sequence of integers, would applying AES encryption to the sequence produce a unique set of strings?

Let us say that we take a sequence of the integers from a to a+n-1: (a, a+1, a+2, a+n-1), where a and n are picked arbitrarily and have no lower or upper bounds on either, except that a < n, and we apply AES encryption to that sequence, one element at a time, utilizing the same key for each element in the sequence.

Assumption is that we encode the resulting ciphered values as Base64 or some other encoding to produce strings.

Would the resulting set of encrypted strings have any, irrespective of how infinitesimally small, chance for collisions?

Since any cipher must be able to decrypt every message that it encrypts, it follows that, given a fixed key, any cipher must be an injective function:

In mathematics, an injective function or injection or one-to-one function is a function that preserves distinctness: it never maps distinct elements of its domain to the same element of its codomain. In other words, every element of the function's codomain is the image of at most one element of its domain.

Or graphically, think of X as plaintexts and Y as ciphertexts:

Although often ciphers are more than just injective—they're also bijective:

And permutations as well: X and Y are normally the same set. E.g., for AES, X and Y are the sets of 128-bit strings.

• Encryption schemes are generally not bijective (there are generally invalid ciphertexts). In the case of AES, this would depend on which mode of operation and padding schemes are used. – fkraiem Jul 15 '16 at 2:18
• @fkraiem Right. Fixed. – Luis Casillas Jul 15 '16 at 2:54
• to be fair, the description in the question implied that ECB mode was used, in which case bijectivity would hold. – kodlu Jul 15 '16 at 4:02
• Yes indeed it would be bijective. The purpose of this wouldn't be to encrypt the integers, but rather to generate absolutely unique identifiers for a single entity. ECB mode is bad for encryption, but doesn't much matter and is quite perfect for the job. :) – zealoushacker Jul 15 '16 at 4:06