PHP, 158 chars
Newlines have been added to stop the code block gaining scrollbars, they can safely be removed.
for($i=52,$x='shdcKQJT98765432A';$i--;$c[]=$x[4+$i%13].$x[$i/13]); while(ord($i=fgetc(STDIN)))$c[$i]^=$c[$a]^=$c[$i]^=$c[$a=2+($a+++$i)%50]; die(join(' ',$c)); Before I get told to add a <?php, let it be known you can invoke PHP without this tag quite easily, using: cat golf.php | php -a
De-golfed and commented:
// Abuse of the for construct to save a bit of space, and to make things more obscure looking in general. for ( // Card suit and number are reversed because we're using a decrementor to count // down from 52, instead of up to 52 $i = 52, $x = 'shdcKQJT98765432A'; // Condition AND per-loop decrement $i--; // Add a new element to the array comprising of $i mod 13 + 4 (to skip suit ids) // followed by simply $i divided by 13 to pick a suit id. $c[] = $x[4 + $i % 13] . $x[$i / 13] ); while( // Assignment inside the condition, a single character from input. ord($i = fgetc(STDIN)) ) // In-place swap. Shorter than using a single letter temporary variable. // This is the pseudo-random shuffle. $c[$i] ^= $c[$a] ^= $c[$i] ^= $c[ // We use the input (0 or 1) to identify one of two swap locations at the // start of the array. The input is also added to an accumulator (to make // the increments "random") that represents a swap destination. $a = 2 + ($a++ + $i) % 50 ]; // Dramatic way of doing "echo" in the same space. die( join(' ', $c) ); There are two expected errors, that do not affect the output of the program.
The first is because $a is not initialised, but the NULL is converted to 0 and the program continues.
The second is because the character stream seems to get a newline from somewhere, even if it's not supplied (good ol' PHP), and that is an undefined index in the array. It's the last character of input, and does not affect output.