2
$\begingroup$

For the sake of curiosity and fun, i have implemented a C# program that operate as deck dealer on 40 cards deck (following the Fisher Yates shuffeling algorithm https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle).

The fun part is that i have used the "faulted" rng that the language provide (small seed compared to cards permutation space and not cryptogaphically secure) and now i am trying to figure out how to write a program that can infer deck permutation only seeing a small fraction (a fifth) of the generation.

So in my scenario, deck dealer program shuffle 40 cards and assign them at each round to one of the 5 player. How can i recostruct the permutation if i see only one player cards? i need some hint here (because seems to me that the shuffling procedure hide a lot of the problem in the pseudo random number generator, so i have no idea how to exploit the problem of that generator and seed). I would premise that i am not a expert on cryptanalysis, just an entusiast

Here the program i wrote :

class Program
{
    private static Random _rng = new Random();

    static void Main(string[] args)
    {

        for( int i = 0; i < 10; i++)
        {
            Program.ShuffelingAlgorithm();
            Console.WriteLine("\r\n\r\n");
        }
        Console.ReadKey();
    }

    private static void ShuffelingAlgorithm ()
    {
        List<int>[] players = { new List<int>(), new List<int>(), new List<int>(), new List<int>(), new List<int>() };
        int[] cards = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 };

        for (int i = 39; i >= 0; i--)
        {
            int next = _rng.Next(0, i);

            int choosen = cards[next];
            players[i % 5].Add(choosen);

            cards[next] = cards[i];
        }

        foreach (var player in players)
        {
            foreach (int card in player)
                Console.Write(card + "\t");

            Console.WriteLine();
        }
    }
}
$\endgroup$
1
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – fgrieu Nov 18 '20 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.