Beispiel #1
0
        static void Main(string[] args)
        {
            // SBox
            Dictionary <string, string> sbox = new Dictionary <string, string>()
            {
                { "0000", "1110" },
                { "0001", "0100" },
                { "0010", "1101" },
                { "0011", "0001" },
                { "0100", "0010" },
                { "0101", "1111" },
                { "0110", "1011" },
                { "0111", "1000" },
                { "1000", "0011" },
                { "1001", "1010" },
                { "1010", "0110" },
                { "1011", "1100" },
                { "1100", "0101" },
                { "1101", "1001" },
                { "1110", "0000" },
                { "1111", "0111" }
            };

            // Bitpermutations-Tabelle
            Dictionary <int, int> bitPermutation = new Dictionary <int, int>()
            {
                { 0, 0 },
                { 1, 4 },
                { 2, 8 },
                { 3, 12 },
                { 4, 1 },
                { 5, 5 },
                { 6, 9 },
                { 7, 13 },
                { 8, 2 },
                { 9, 6 },
                { 10, 10 },
                { 11, 14 },
                { 12, 3 },
                { 13, 7 },
                { 14, 11 },
                { 15, 15 }
            };

            Spn    mySpn    = new Spn(4, 4, 4, 32, "00111010100101001101011000111111", 4, sbox, bitPermutation);
            Ctr    ctr      = new Ctr("00111010100101001101011000111111", 16, mySpn);
            string klartext = ctr.Decrypt(@"00000100110100100000101110111000000000101000111110001110011111110110000001010001010000111010000000010011011001110010101110110000", false);

            System.Console.WriteLine("-- Klartext als BitString --");
            System.Console.WriteLine(klartext);

            var data = klartext.GetBytesFromBinaryString();
            var text = Encoding.ASCII.GetString(data);

            System.Console.WriteLine("-- Klartext als Text --");
            System.Console.WriteLine(text);

            System.Console.ReadLine();
        }
Beispiel #2
0
        public void SpnIntilizationUserString()
        {
            string expected = "spn=";
            Spn    Spn      = new Spn("UserString");

            expected += "UserString";
            Assert.AreEqual(expected, Spn.GetPartUrl());
        }
Beispiel #3
0
        public void SpnGetPartUrlMax()
        {
            double dLat = 91;
            double dLon = 181;

            Spn    Spn    = new Spn(dLat, dLon);
            string result = $"spn={dLon_max.ToString().Replace(',', '.')}" +
                            $",{dLat_max.ToString().Replace(',', '.')}";

            Assert.AreEqual(result, Spn.GetPartUrl());
        }
Beispiel #4
0
        public void SpnGetPartUrlNegative()
        {
            double dLat = -1;
            double dLon = -0.005;

            Spn    Spn    = new Spn(dLat, dLon);
            string result = $"spn={dLon_def.ToString().Replace(',', '.')}" +
                            $",{dLat_def.ToString().Replace(',', '.')}";

            Assert.AreEqual(result, Spn.GetPartUrl());
        }
Beispiel #5
0
        public void SpnGetPartUrlStandart()
        {
            double dLat = 53.1235654456;
            double dLon = 93.5498495156;

            Spn    Spn    = new Spn(dLat, dLon);
            string result = $"spn={dLon.ToString().Replace(',', '.')}" +
                            $",{dLat.ToString().Replace(',', '.')}";

            Assert.AreEqual(result, Spn.GetPartUrl());
        }
Beispiel #6
0
        public SpnTwoTest()
        {
            _m   = 4;
            _n   = 4;
            _r   = 4;
            _s   = 32;
            _key = "00010001001010001000110000000000";
            _roundKeyPosition = 4;
            _plainText        = "0001001010001111";
            _chiffretext      = "1010111010110100";

            _sbox = new Dictionary <string, string>()
            {
                { "0000", "1110" },
                { "0001", "0100" },
                { "0010", "1101" },
                { "0011", "0001" },
                { "0100", "0010" },
                { "0101", "1111" },
                { "0110", "1011" },
                { "0111", "1000" },
                { "1000", "0011" },
                { "1001", "1010" },
                { "1010", "0110" },
                { "1011", "1100" },
                { "1100", "0101" },
                { "1101", "1001" },
                { "1110", "0000" },
                { "1111", "0111" }
            };

            _bitPermutation = new Dictionary <int, int>()
            {
                { 0, 0 },
                { 1, 4 },
                { 2, 8 },
                { 3, 12 },
                { 4, 1 },
                { 5, 5 },
                { 6, 9 },
                { 7, 13 },
                { 8, 2 },
                { 9, 6 },
                { 10, 10 },
                { 11, 14 },
                { 12, 3 },
                { 13, 7 },
                { 14, 11 },
                { 15, 15 }
            };

            spn = new Spn(_r, _n, _m, _s, _key, _roundKeyPosition, _sbox, _bitPermutation);
        }
Beispiel #7
0
 public void Dispose()
 {
     spn  = null;
     _r   = default(int);
     _n   = default(int);
     _m   = default(int);
     _s   = default(int);
     _key = default(string);
     _roundKeyPosition = default(int);
     _sbox             = null;
     _bitPermutation   = null;
     _plainText        = default(string);
     _chiffretext      = default(string);
 }
Beispiel #8
0
        public SpnOneTest()
        {
            _m   = 3;
            _n   = 4;
            _r   = 3;
            _s   = 24;
            _key = "000110101111110000000111";
            _roundKeyPosition = 4;
            _plainText        = "111101010110";
            _chiffretext      = "000101111010";

            _sbox = new Dictionary <string, string>()
            {
                { "0000", "0101" },
                { "0001", "0100" },
                { "0010", "1101" },
                { "0011", "0001" },
                { "0100", "0011" },
                { "0101", "1100" },
                { "0110", "1011" },
                { "0111", "1000" },
                { "1000", "1010" },
                { "1001", "0010" },
                { "1010", "0110" },
                { "1011", "1111" },
                { "1100", "1001" },
                { "1101", "1110" },
                { "1110", "0000" },
                { "1111", "0111" }
            };

            _bitPermutation = new Dictionary <int, int>()
            {
                { 0, 4 },
                { 1, 5 },
                { 2, 8 },
                { 3, 9 },
                { 4, 0 },
                { 5, 1 },
                { 6, 10 },
                { 7, 11 },
                { 8, 2 },
                { 9, 3 },
                { 10, 6 },
                { 11, 7 }
            };

            spn = new Spn(_r, _n, _m, _s, _key, _roundKeyPosition, _sbox, _bitPermutation);
        }
        /// <summary>
        ///     Returns true if RunnerChange instances are equal
        /// </summary>
        /// <param name="other">Instance of RunnerChange to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(RunnerChange other)
        {
            // credit: http://stackoverflow.com/a/10454552/677735
            if (other == null)
            {
                return(false);
            }

            return((Tv == other.Tv || Tv != null && Tv.Equals(other.Tv)) &&
                   (Batb == other.Batb || Batb != null && Batb.SequenceEqual(other.Batb)) &&
                   (Spb == other.Spb || Spb != null && Spb.SequenceEqual(other.Spb)) &&
                   (Bdatl == other.Bdatl || Bdatl != null && Bdatl.SequenceEqual(other.Bdatl)) &&
                   (Trd == other.Trd || Trd != null && Trd.SequenceEqual(other.Trd)) &&
                   (Spf == other.Spf || Spf != null && Spf.Equals(other.Spf)) &&
                   (Ltp == other.Ltp || Ltp != null && Ltp.Equals(other.Ltp)) &&
                   (Atb == other.Atb || Atb != null && Atb.SequenceEqual(other.Atb)) &&
                   (Spl == other.Spl || Spl != null && Spl.SequenceEqual(other.Spl)) &&
                   (Spn == other.Spn || Spn != null && Spn.Equals(other.Spn)) &&
                   (Atl == other.Atl || Atl != null && Atl.SequenceEqual(other.Atl)) &&
                   (Batl == other.Batl || Batl != null && Batl.SequenceEqual(other.Batl)) &&
                   (Id == other.Id || Id != null && Id.Equals(other.Id)) &&
                   (Hc == other.Hc || Hc != null && Hc.Equals(other.Hc)) &&
                   (Bdatb == other.Bdatb || Bdatb != null && Bdatb.SequenceEqual(other.Bdatb)));
        }
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                var hash = 41;
                // Suitable nullity checks etc, of course :)

                if (Tv != null)
                {
                    hash = hash * 59 + Tv.GetHashCode();
                }

                if (Batb != null)
                {
                    hash = hash * 59 + Batb.GetHashCode();
                }

                if (Spb != null)
                {
                    hash = hash * 59 + Spb.GetHashCode();
                }

                if (Bdatl != null)
                {
                    hash = hash * 59 + Bdatl.GetHashCode();
                }

                if (Trd != null)
                {
                    hash = hash * 59 + Trd.GetHashCode();
                }

                if (Spf != null)
                {
                    hash = hash * 59 + Spf.GetHashCode();
                }

                if (Ltp != null)
                {
                    hash = hash * 59 + Ltp.GetHashCode();
                }

                if (Atb != null)
                {
                    hash = hash * 59 + Atb.GetHashCode();
                }

                if (Spl != null)
                {
                    hash = hash * 59 + Spl.GetHashCode();
                }

                if (Spn != null)
                {
                    hash = hash * 59 + Spn.GetHashCode();
                }

                if (Atl != null)
                {
                    hash = hash * 59 + Atl.GetHashCode();
                }

                if (Batl != null)
                {
                    hash = hash * 59 + Batl.GetHashCode();
                }

                if (Id != null)
                {
                    hash = hash * 59 + Id.GetHashCode();
                }

                if (Hc != null)
                {
                    hash = hash * 59 + Hc.GetHashCode();
                }

                if (Bdatb != null)
                {
                    hash = hash * 59 + Bdatb.GetHashCode();
                }

                return(hash);
            }
        }
Beispiel #11
0
        static void Main(string[] args)
        {
            L    l    = new L(true, false, false, true);
            LL   ll   = new LL(56.00848, 92.85302);
            int  z    = 15;
            Bbox bbox = new Bbox(56.01000, 92.85, 56.00580, 92.85778);
            Spn  spn  = new Spn(0.005, 0.005);
            Size size = new Size(450, 450);
            Lang lang = new Lang(Lang.Lang_reg.en_US);

            //Создание карты с слоем пробок
            StaticAPI map1 = new StaticAPI(l, ll, z, size, lang);

            Console.Write("Создание карты с слоем пробок.\n");
            Console.Write(map1.GetPictureURL() + "\n\n");

            //Создание карты с различными метками
            Pm              pm1      = new Pm(56.00922, 92.84895);
            Pm              pm2      = new Pm(56.00956, 92.85569, Pm.Color.do_, Pm.Size.l, 2);
            Pm              pm3      = new Pm(56.00891, 92.85581, Pm.Color.nt, Pm.Size.s, 3);
            Pm2             pm4      = new Pm2(56.00895, 92.85679);
            Pm2             pm5      = new Pm2(56.00702, 92.85713, Pm2.Color.gr, Pm2.Size.l, 5);
            Vk              pm6      = new Vk(56.00690, 92.85552, Vk.Color.bk);
            Vector          pm7      = new Vector(56.00613, 92.85574, Vector.Mark.comma);
            Vector          pm8      = new Vector(56.00574, 92.85283, Vector.Mark.ya_ru);
            Vector          pm9      = new Vector(56.00672, 92.85258, Vector.Mark.home);
            Flag            pm10     = new Flag(56.00661, 92.84937);
            List <MarkBase> listMark = new List <MarkBase>()
            {
                pm1, pm2, pm3, pm4, pm5, pm6, pm7, pm8, pm9, pm10
            };
            Pt        pt   = new Pt(listMark);
            StaticAPI map2 = new StaticAPI(new L(), bbox, pt: pt);

            Console.Write("Создание карты с различными метками.\n");
            Console.Write(map2.GetPictureURL() + "\n\n");

            //Создание спутниковой карты с полилиниями разного цвета
            Polyline polyline1 = new Polyline("0000FF99", 6, new List <Point>()
            {
                new Point(56.00976, 92.85251),
                new Point(56.00519, 92.85328),
                new Point(56.00518, 92.85359),
                new Point(56.00978, 92.85290)
            });
            Polyline polyline2 = new Polyline("FF0000FF", 10, new List <Point>()
            {
                new Point(56.00673, 92.84922),
                new Point(56.00719, 92.85721)
            });
            List <Polyline> listPol = new List <Polyline>()
            {
                polyline1, polyline2
            };
            Pl        pl   = new Pl(listPol);
            StaticAPI map3 = new StaticAPI(
                new L(false, true, true, false),
                ll,
                spn,
                new Size(450, 300),
                scale: 4,
                pl: pl);

            Console.Write("Создание спутниковой карты с полилиниями разного цвета.\n");
            Console.Write(map3.GetPictureURL() + "\n\n");

            //Создание карты с двумя пересекающимися полигонами
            List <Point> listPolygonPoint = new List <Point>()
            {
                new Point(56.00922, 92.84895),
                new Point(56.00956, 92.85569),
                new Point(56.00891, 92.85581),
                new Point(56.00895, 92.85679),
                new Point(56.00702, 92.85713),
                new Point(56.00690, 92.85552),
                new Point(56.00613, 92.85574),
                new Point(56.00574, 92.85283),
                new Point(56.00672, 92.85258),
                new Point(56.00661, 92.84937)
            };
            List <Point> listPolygonPoint2 = new List <Point>()
            {
                new Point(56.00827, 92.85097),
                new Point(56.00819, 92.85516),
                new Point(56.00693, 92.85367),
                new Point(56.00758, 92.85076)
            };
            Polyline     polygons          = new Polygon("F473fFAF", "ec473fF2", 8, listPolygonPoint, listPolygonPoint2);
            List <Point> listPolygonPoint3 = new List <Point>()
            {
                new Point(56.00976, 92.85251),
                new Point(56.00978, 92.85290),
                new Point(56.00518, 92.85359),
                new Point(56.00519, 92.85328)
            };
            Polyline        polygons2   = new Polygon(listPolygonPoint3);
            List <Polyline> listPolygon = new List <Polyline>()
            {
                polygons, polygons2
            };
            Pl        pl2  = new Pl(listPolygon);
            StaticAPI map4 = new StaticAPI(new L(), bbox, pl: pl2);

            Console.Write("Создание карты с двумя пересекающимися полигонами.\n");
            Console.Write(map4.GetPictureURL() + "\n\n");

            //Создание карты со всеми ранее созданными объектами
            List <Polyline> listPolygonPoint4 = new List <Polyline>()
            {
                polyline1, polyline2, polygons, polygons2
            };
            Pl        pl3  = new Pl(listPolygonPoint4);
            StaticAPI map5 = new StaticAPI(
                new L(true, false, true, true),
                bbox,
                new Size(450, 650),
                new Lang(Lang.Lang_reg.ru_RU),
                1.5,
                pt,
                pl3);

            Console.Write("Создание карты со всеми ранее созданными объектами.\n");
            Console.Write(map5.GetPictureURL() + "\n\n");

            Console.ReadLine();
        }