Its the formula for the last hex digit. I don't know how the first 3 digits are computed.
Code:
((input%16)+((input%4)<=1)*4+(((input-1)%4)>=2)*8)%16
So 25% of the answer at least. It works for all values you have given and should work for any possible value.