private static void ZKPCracker()
        {
            System.Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            System.Console.Write("\nn: ");
            Integer n = Tools.ToInteger(Console.ReadLine());
            Integer p;

            while (true)
            {
                var t = MathI.RandomI();
                var y = t.ModPow(2, n);
                System.Console.WriteLine($"y: {y.ToHexString()}");
                System.Console.Write("z: ");
                var z = Tools.ToInteger(Console.ReadLine());
                if (y != z || y != -z)
                {
                    p = NumberTheory.GCD(t + z, n);
                    if (p != 1)
                    {
                        break;
                    }
                }
                System.Console.WriteLine("___________________");
            }

            System.Console.WriteLine("\n\nEnd of attack");
            var q = n / p;

            System.Console.WriteLine($"p: {p.ToHexString()}");
            System.Console.WriteLine($"q: {q.ToHexString()}");
            System.Console.WriteLine($"Test n: {(p * q).ToHexString()}");
        }
Beispiel #2
0
        private static object Get()
        {
            if (_math != null)
            {
                return(_math);
            }

            Type   t = typeof(T);
            object m;

            if (t == typeof(sbyte))
            {
                m = new MathI8();
            }
            else if (t == typeof(byte))
            {
                m = new MathU8();
            }
            else if (t == typeof(short))
            {
                m = new MathI16();
            }
            else if (t == typeof(ushort))
            {
                m = new MathU16();
            }
            else if (t == typeof(int))
            {
                m = new MathI();
            }
            else if (t == typeof(uint))
            {
                m = new MathU();
            }
            else if (t == typeof(long))
            {
                m = new MathL();
            }
            else if (t == typeof(ulong))
            {
                m = new MathUL();
            }
            else if (t == typeof(float))
            {
                m = new MathF();
            }
            else if (t == typeof(double))
            {
                m = new MathD();
            }
            else
            {
                m = null;              // TODO: search open assemblies for INumTraits<T> via reflection?
            }
            return(_math = m);
        }
Beispiel #3
0
 public BBSGeneratorBit(Integer?seed)
 {
     if (seed == null)
     {
         this.seed = MathI.RandomI(2);
     }
     else
     {
         this.seed = seed.Value;
     }
 }
Beispiel #4
0
 public BMGeneratorByte(Integer?seed)
 {
     if (seed == null)
     {
         this.seed = MathI.RandomI(0, P);
     }
     else
     {
         this.seed = seed.Value;
     }
 }
        private static void ServerVerify()
        {
            var userA = new RabinProvider();
            var m     = MathI.RandomI(100, 1000);

            System.Console.WriteLine($"Message to cypher: {m.ToHexString()}");

            var signed = userA.Sign(m);

            System.Console.WriteLine($"PublicKey(n, b): ({userA.PublicKey.n.ToHexString()}, \n{userA.PublicKey.b.ToHexString()})");
            System.Console.WriteLine($"Signed(m, s): ({signed.m.ToHexString()}, \n{signed.s.ToHexString()})");
        }
Beispiel #6
0
        private void ChangeVolume(int offset)
        {
            int newValue = MathI.Clamp(_sounds.Volume + offset, 0, 100);

            if (_sounds.Volume != newValue)
            {
                _sounds.Volume = (byte)newValue;
                _sounds.PlaySound(SoundName.Blip5);

                _settings.Settings.Audio.EffectsVolume = _sounds.Volume;

                RefreshVolumeLabel();
            }
        }
        private static void ServerExtra()
        {
            var userA = new RabinProvider();
            var m     = MathI.RandomI(100, 1000);

            System.Console.WriteLine($"Message to cypher: {m.ToHexString()}");

            System.Console.Write("Enter server key(n, b): ");
            var n         = Tools.ToInteger(Console.ReadLine());
            var b         = Tools.ToInteger(Console.ReadLine());
            var key       = (n, b);
            var encrypted = userA.Encrypt(m, key);

            System.Console.WriteLine($"Encrypted: {encrypted.y.ToHexString()}");
            System.Console.WriteLine($"(c1, c2): ({encrypted.c1}, {encrypted.c2})");
        }
Beispiel #8
0
        private bool CanConnectTo(GridAtom target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (Electrons <= 0)
            {
                return(false);
            }

            if (target.Electrons <= 0)
            {
                return(false);
            }

            var differenceX = target.GridX - GridX;
            var differenceY = target.GridY - GridY;

            if (MathI.Abs(differenceX) + MathI.Abs(differenceY) != 1)
            {
                return(false);
            }

            if (differenceX == -1)
            {
                return(LeftConnection == null);
            }
            else if (differenceX == 1)
            {
                return(RightConnection == null);
            }
            else if (differenceY == -1)
            {
                return(TopConnection == null);
            }
            else if (differenceY == 1)
            {
                return(BottomConnection == null);
            }

            return(false);
        }
Beispiel #9
0
        protected override void OnDraw(SpriteBatch batch)
        {
            GraphicsDevice.Clear(AppColors.WindowBackground);

            batch.Begin();

            if (_highscore.Items.Length > 0)
            {
                var posY = 100;
                for (int i = 0; i < MathI.Min(_highscore.Items.Length, AppConstants.TopHighscorePlaces); i++)
                {
                    var item = _highscore.Items[i];

                    var scoreText = item.Score.ToString("n0");
                    var scoreSize = AppContents.DefaultFont.MeasureString(scoreText);

                    batch.DrawBitmapFont(AppContents.DefaultFont,
                                         new Vector2(100, posY),
                                         (1 + i).ToString(),
                                         AppColors.Descriptions);

                    batch.DrawBitmapFont(AppContents.DefaultFont,
                                         new Vector2(160, posY),
                                         item.User,
                                         AppColors.Texts);

                    batch.DrawBitmapFont(AppContents.DefaultFont,
                                         new Vector2(GraphicsDevice.Viewport.Width - scoreSize.X - 100, posY),
                                         scoreText,
                                         AppColors.Texts);

                    posY += AppContents.DefaultFont.Data.LineHeight;
                }
            }
            else
            {
                batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(100, 100), "Empty", AppColors.Texts);
            }

            batch.End();
        }
        private static void Extra()
        {
            var userA = new RabinProvider();
            var userB = new RabinProvider();
            var m     = MathI.RandomI(100, 1000);

            System.Console.WriteLine($"Message to cypher: {m.ToHexString()}");

            var encrypted = userA.Encrypt(m, userB.PublicKey);
            var decrypted = userB.Decrypt(encrypted);

            System.Console.WriteLine($"Encrypted: {encrypted.y.ToHexString()}");
            System.Console.WriteLine($"(c1, c2): ({encrypted.c1}, {encrypted.c2})");
            System.Console.WriteLine($"Decrypted: {decrypted.ToHexString()}\n");

            var signed   = userA.Sign(m);
            var verified = userB.Verify(signed, userA.PublicKey);

            System.Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            System.Console.WriteLine($"\nSigned: {signed.s}");
            System.Console.WriteLine($"Verification result: {verified}");
        }