Esempio n. 1
0
        public void CompareSignature(byte[] memory, byte[] previous, long length)
        {
            diffBits.Clear();
            int[] sig = CreateSignatureTest.TestSignature;
            byte  mem;

            diffLength = 0;
            int counter = 0;

            for (int i = 0; i < sig.Length; i++)
            {
                mem = memory[sig[i]];
                if (mem != previous[sig[i]])
                {
                    diffBits.Add(true);
                    diff[diffLength] = mem;
                    diffLength++;
                    counter = i;
                }
                else
                {
                    diffBits.Add(false);
                }
            }
            diffBits.BitCount = counter;
        }
Esempio n. 2
0
        public static void ShowBitArray()
        {
            var             bitArray = new BitArray(new bool[] { true, false, true, true, false });
            Action <string> showInfo = (action) => {
                Console.WriteLine($"Count = {bitArray.Count}, CountOfReservedElements = {bitArray.CountOfReservedElements}");
                ShowAction(action, bitArray);
            };

            showInfo("Create");
            bitArray.Add(true);
            showInfo("Add true");
            bitArray.Add(false);
            showInfo("Add false");
            bitArray.Add(false);
            showInfo("Add false");
            bitArray.Add(true);
            showInfo("Add true");
            bitArray.IncreaseArray(20);
            showInfo("Increase (20)");
            bitArray[2] = false;
            showInfo("set bitArray[2] = false");
            bitArray[18] = true;
            showInfo("set bitArray[18] = true");
            bitArray[9] = true;
            showInfo("set bitArray[9] = true");
            bitArray[0] = false;
            showInfo("set bitArray[0] = false");
            showInfo($"get bitArray[2] = {bitArray[2]}");
            showInfo($"get bitArray[14] = {bitArray[14]}");
            showInfo($"get bitArray[5] = {bitArray[5]}");
        }
Esempio n. 3
0
        public KeyValuePair <Dictionary <T, BitArray>, BitArray> Encode(T[] data)
        {
            List <Node <T> > nodes = new List <Node <T> >();
            var map = GetMap(data);

            foreach (var item in map)
            {
                nodes.Add(new Node <T>(item.Key, item.Value));
            }

            while (nodes.Count > 1)
            {
                nodes[0].SetBit(false);
                nodes[1].SetBit(true);
                var item = new Node <T>(nodes[0], nodes[1]);
                nodes.Add(item);
                nodes.RemoveAt(0);
                nodes.RemoveAt(0);
                nodes = nodes.OrderBy(x => x.Counter).ToList();
            }

            var      Key = nodes[0].GetBitKeys();
            BitArray ans = new BitArray(0);

            foreach (var item in data)
            {
                ans.Add(Key[item]);
            }

            return(new KeyValuePair <Dictionary <T, BitArray>, BitArray>(Key, ans));
        }
Esempio n. 4
0
        private void Create(string fontFamily)
        {
            Graphics g    = Graphics.FromImage(new Bitmap(100, 100));
            Font     font = new Font(fontFamily, 100, FontStyle.Regular, GraphicsUnit.Pixel);
            string   str  = "";

            SizeF[] sizes = new SizeF[94];
            float   width = 0;

            for (int i = 33; i <= 126; i++)
            {
                str          += (char)i;
                sizes[i - 33] = g.MeasureString((char)i + "", font, 0, StringFormat.GenericTypographic);
                width        += sizes[i - 33].Width;
            }

            Bitmap bmp = new Bitmap(Convert.ToInt32(width), Convert.ToInt32(sizes[0].Height));

            g.Dispose();
            g = Graphics.FromImage(bmp);
            g.DrawString(str, font, new SolidBrush(Color.White), new PointF(), StringFormat.GenericTypographic);

            FileStream   stream = new FileStream("fontatlas.fta", FileMode.Create);
            BinaryWriter writer = new BinaryWriter(stream);

            //header
            writer.Write(new byte[] { (byte)'F', (byte)'T', (byte)'A' }); //filetype
            writer.Write(2.0F);                                           //version
            writer.Write(bmp.Width);                                      //width
            writer.Write(bmp.Height);                                     //height
            writer.Write(str.Length);                                     //char amount
            writer.Write((byte)33);                                       //starting char
            writer.Write(fontFamily);                                     //fontFamily

            BitArray bitArray = new BitArray();

            for (int y = 0; y < bmp.Height; y++)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    var val = bmp.GetPixel(x, y).R;

                    bitArray.Add(val == 255);
                }
            }

            writer.Write(bitArray.GetBytes());

            foreach (var s in sizes)
            {
                writer.Write(s.Width);
            }

            g.Dispose();
            stream.Close();
            bmp.Dispose();
        }
Esempio n. 5
0
        private BitArray FunctionSBox(BitArray array)
        {
            BitArray sBoxedArray = new BitArray(32);

            for (int i = 0; i < 8; i++)
            {
                BitArray temp = array.GetRange(6 * i, 6);
                sBoxedArray.Add(Permutations.Permute(Data.SBox[i], temp));
            }

            return(sBoxedArray);
        }
Esempio n. 6
0
 public List<string> getIPv4Range()
 {
     List<string> ipaddrs = new List<string>();
     BitArray currip = this.calcIPv4FirstAddress();
     BitArray lastip = this.calcIPv4LastAddress();
     while (!currip.bitsEqual(lastip))
     {
         ipaddrs.Add(this.calcIPv4Address(currip));
         currip = currip.Add(1);
     }
     ipaddrs.Add(this.calcIPv4Address(currip) );
     return ipaddrs;
 }