Add an integer to a set and take it back out
C#

void Encode(HashSet&lt;int&gt; set)
{
    set.Add((set.Single() + 1) % 1001);
}

void Decode(HashSet&lt;int&gt; set)
{
    set.Remove(set.Equals(new HashSet&lt;int&gt;() { 0, 1000 }) ? 0 : set.Max());
}


Works for a set of length 1.