Storing data in a deck of cards This question has been bugging me for a while now. There are approximately 8e67 unique permutations of a standard, 52 card deck. This theoretically equates to just slightly more than 225 bits of data ($\log_2(52!)$).
So the question is; is it possible to design an algorithm to convert between a sequence of 52 cards and a 226 bit string such that every unique string is a unique number?
Ideally, the algorithm would be reversible. One should be able to go from a deck of cards to a string of data, or from a string of data to a deck of cards.
I wonder, also, if such an algorithm could run in linear time.
Something I thought of, though wasn't able to do anything with, was the notion that all of the cards in order would represent the lowest number, and all of the cards in reverse order would represent the highest number.
1,2,3 -> 0
3,2,1 -> 5

This did help a bit, because it meant I could do things like reverse the 1 and 2 to make the number one. 2,1,3 -> 1 And it wouldn't matter how many numbers come after a reversed sequence. 3,2,1 -> 5 as well as 3,2,1,4,5,6,7,8 -> 5
It gave me some rules as well. Given any two permutations that are nearly identical but differ only by two cards, the set with the higher card first would resolve to a higher number. I.E. 1,2,3,4,5 < 1,2,4,3,5 and 2,1,3 < 3,1,2
For two cards, the table is easy
1,2 -> 0
2,1 -> 1

For three cards there are sequences that obviously fall in line.
1,2,3 -> 0
2,1,3 -> 1
3,2,1 -> 5

 A: You're basically looking at Lehmer code, with a little bit of the factorial number system (aka factoradic) included. Here are the rough algorithms for going in each direction:
Mapping a permutation to an integer
Input: n, an integer
       a = [a_1, a_2, ... a_n] where a_i is the value of the item in the i-th position, minus 1 (so each a_i is a distinct value between 0 and n-1)

Output: N, an integer between 0 and n!-1

N = 0
for each i in 1 to n do
    N := N + (n-i)!*a_i
    for each j in i+1 to n do
        if a_j > a_i then a_j := a_j - 1

Mapping an integer to a permutation
Input: n, an integer
       N, a number between 0 and n!-1

Output: a = [a_1, a_2, ..., a_n] as described above

source := [0, .., n-1]
a := []

for each i in 1 to n do
     next := floor(N / (i-1)!)
     a[i] := source[next]
     source := source[-next] # i.e. remove the chosen element from the source set
     N := N - next

Please note that the above code comes completely unproven. Also, note that the first code is O(n^2), but the second is O(n) assuming you can update source in linear time.
