Example #1
0
        public List <List <UInt64> > GeneratePuzzles(UInt64 Pattern)
        {
            List <List <UInt64> > CAllPuzzles = new List <List <UInt64> >();
            List <UInt64>         IDs         = new List <UInt64>();
            List <UInt64>         Keys        = new List <UInt64>();

            Random r = new Random();

            for (int i = 0; i < Program.PuzzleNr; i++)
            {
                UInt64 Key1 = MyRandom.NextMyInt(r);
                UInt64 ID, Key;
                ID  = MyRandom.NextMyInt(r) + (UInt64)i;
                Key = MyRandom.NextMyInt(r) + (UInt64)i;

                AllPuzzles.Add(new List <UInt64>()
                {
                    Pattern, ID, Key
                });

                UInt64 CPattern = Encryption.Encrypt(Pattern, Key1);
                UInt64 C_ID     = Encryption.Encrypt(ID, Key1);
                UInt64 C_Key    = Encryption.Encrypt(Key, Key1);
                CAllPuzzles.Add(new List <UInt64>()
                {
                    CPattern, C_ID, C_Key
                });
            }

            return(CAllPuzzles);
        }
Example #2
0
        static void Main(string[] args)
        {
            X      X       = new X();
            Y      Y       = new Y();
            Random r       = new Random();
            UInt64 Pattern = MyRandom.NextMyInt(r);

            Stopwatch             stopwatch  = Stopwatch.StartNew();
            List <List <UInt64> > AllPuzzles = X.GeneratePuzzles(Pattern);

            stopwatch.Stop();
            Console.WriteLine("Generating puzzles in ms: " + stopwatch.ElapsedMilliseconds);

            Stopwatch stopwatch1 = Stopwatch.StartNew();

            Y.GetTheKey(AllPuzzles, Pattern);
            stopwatch1.Stop();
            Console.WriteLine("Geting key in ms: " + stopwatch1.ElapsedMilliseconds);

            UInt64 Message = 2222212322 % lenght;
            UInt64 Ciphertext;
            UInt64 ID;

            Console.WriteLine("Y wants to send the message: " + Message);

            Stopwatch stopwatch2 = Stopwatch.StartNew();

            Ciphertext = Y.Encrypt(Message);
            Console.WriteLine("He sends ciphertext: " + Ciphertext);
            ID = Y.ID;
            Console.WriteLine("X understood: " + X.Decrypt(Ciphertext, ID));
            stopwatch2.Stop();
            Console.WriteLine("En- and Decryption in ms: " + stopwatch2.ElapsedMilliseconds);

            Console.ReadKey();
        }