Exemple #1
0
        static void Main(string[] args)
        {
            if (!_TheFlagCanBeCapturedWithoutReversing())
            {
                return;
            }

            Console.WriteLine("Transmitting flag...");

            var ipe = new IPEndPoint(IPAddress.Broadcast, 6969);
            var c   = new UdpClient {
                EnableBroadcast = true
            };

            while (true)
            {
                for (int i = 0; i < _indexes.Length; i++)
                {
                    var p = new FlagPacket()
                    {
                        SequenceSize   = (byte)_indexes.Length,
                        SequenceNumber = _indexes[i],
                        FlagByte       = _pieces[i]
                    };

                    var b = p.ToBytes();

                    c.Send(b, b.Length, ipe);

                    Thread.Sleep(500);
                }
            }
        }
Exemple #2
0
        public static FlagPacket FromBytes(byte[] bytes)
        {
            if (bytes.Length < 7)
            {
                return(null);
            }

            var magicNumbers = Encoding.ASCII.GetString(bytes.Take(4).ToArray());

            if (magicNumbers != "flag")
            {
                return(null);
            }

            var p = new FlagPacket()
            {
                SequenceSize   = bytes[5],
                SequenceNumber = bytes[6],
                FlagByte       = bytes[7]
            };

            return(p);
        }