Exemple #1
0
        public string GetDeckCode()
        {
            BitArray unitWithTransportCount = new BitArray(5, false);
            BitArray bargesCount            = new BitArray(4, false);

            unitWithTransportCount = ConvertToBigEndianBitArray(transportedUnits.Count, 5);
            bargesCount            = ConvertToBigEndianBitArray(superTransportedUnits.Count, 4);
            BitArray deck = new BitArray(0);

            deck.Append(deckType).Append(CatA).Append(bargesCount).Append(unitWithTransportCount);

            foreach (SuperTransportedUnitStruct superTransportedUnit in superTransportedUnits)
            {
                BitArray vetCode            = ConvertToBigEndianBitArray(superTransportedUnit.Veterancy, 3);
                BitArray unitCode           = ConvertToBigEndianBitArray(superTransportedUnit.Unit, 11);
                BitArray transportCode      = ConvertToBigEndianBitArray(superTransportedUnit.Transport, 11);
                BitArray superTransportCode = ConvertToBigEndianBitArray(superTransportedUnit.SuperTransport, 11);

                deck.Append(vetCode).Append(unitCode).Append(transportCode).Append(superTransportCode);
            }

            deck.Append(GetTransportedUnitsCodes());

            deck.Append(GetUnitsCodes());

            deck = AddPadding(deck);

            return(Convert.ToBase64String(BitArrayToByteArray(deck)));
        }
Exemple #2
0
        private BitArray ImediateFormat(OperationEnum operation, List <string> parts)
        {
            var result = new BitArray(0);

            result = result.Append(new BitArray(new int[1] {
                (int)operation
            }).Trim(6));

            var register1String = parts[1].Trim(new char[] { '$', ',' });

            if (Enum.TryParse(register1String, true, out RegisterEnum register))
            {
                result = result.Append(new BitArray(new int[1] {
                    (int)register
                }).Trim(5));
            }

            var register2String = parts[2].Trim(new char[] { '$', ',' });

            if (Enum.TryParse(register2String, true, out RegisterEnum register2))
            {
                result = result.Append(new BitArray(new int[1] {
                    (int)register2
                }).Trim(5));
            }

            if (Int32.TryParse(parts[3], out int refe))
            {
                result = result.Append(new BitArray(new int[1] {
                    refe
                }).Trim(16));
            }

            return(result);
        }
Exemple #3
0
        private BitArray JumpFormat(OperationEnum operation, List <string> parts)
        {
            var result = new BitArray(0);

            result = result.Append(new BitArray(new int[1] {
                (int)operation
            }).Trim(6));
            if (Int32.TryParse(parts[1], out int refe))
            {
                result = result.Append(new BitArray(new int[1] {
                    refe
                }).Trim(26));
            }
            return(result);
        }
        private BitArray dataEncoding(BitArray baContent, bool isFile = false)
        {
            BitArray baToSteg;
            // Get the file extension
            bool isGif = txtStegFilePath.Text.ToLower().EndsWith(".gif");

            if (isGif)
            {
                BitArray baContlen = baContent.Length.ToBinary();
                baToSteg = baContlen.Append(baContent);
            }
            else
            {
                // The content type to encode string or file
                int      secLevel  = (int)sldSecLevel.Value;
                BitArray baSecLev  = secLevel.ToBinary();
                BitArray baIsFile  = new BitArray(new bool[] { isFile });
                BitArray baData    = baSecLev.Append(baIsFile).Append(baContent);
                BitArray baDataLen = baData.Length.ToBinary();
                baToSteg = baDataLen.Append(baData);
            }
            // Current slots available
            tbxSlotsUsed.Text = baToSteg.Length.ToString("##,###0", CultureInfo.InvariantCulture).Replace(",", " ");
            if (checkCurrentSliderValue())
            {
                MessageBox.Show("Message too long for this image.", "StegImageUI", MessageBoxButton.OK, MessageBoxImage.Information);
                return(null);
            }
            return(baToSteg);
        }
Exemple #5
0
        /// <summary>
        /// Extension method to scan a byte from current bitarray
        /// </summary>
        /// <param name="current">current bit array</param>
        /// <param name="byteOut">output parameter for byte extraction</param>
        /// <returns>bitarray with scanned bits removed</returns>
        public static BitArray nextByte(this BitArray current, out byte byteOut)
        {
            bool[] bools = new bool[current.Count];
            current.CopyTo(bools, 0);

            if (bools.Length < 8)
            {
                throw new Exception("Not enough bits in bitarray");
            }

            BitArray scanByte = new BitArray(0);

            for (int k = 8 - 1; k >= 0; k--)
            {
                scanByte = scanByte.Append(bools[k]);
            }

            byte[] _byteOut = new byte[1];
            scanByte.CopyTo(_byteOut, 0);
            byteOut = _byteOut[0];

            bools   = bools.RemoveAt(0, 8);
            current = new BitArray(bools);
            return(current);
        }
Exemple #6
0
        /// <summary>
        ///     生成子密钥
        /// </summary>
        /// <param name="key">密钥</param>
        /// <returns></returns>
        private static BitArray[] GenerateKeys(BitArray key)
        {
            //置换选择1 64位->56位
            key = SwapSelect1(key);
            //Debug.WriteLine(key.PrintInBinary());

            BitArray[] output = new BitArray[16];

            BitArray c = new BitArray(28);
            BitArray d = new BitArray(28);

            c.SetRange(0, 28, key);
            d.SetRange(0, 28, key, 28);

            //Debug.WriteLine(c.PrintInBinary());
            //Debug.WriteLine(d.PrintInBinary());

            for (int i = 0; i < 16; i++)
            {
                //密钥产生
                //循环左移
                c = c.ROL(LeftShiftTime[i]);
                d = d.ROL(LeftShiftTime[i]);
                //Debug.WriteLine("i:{2} C:{0} D:{1}", c.PrintInBinary(), d.PrintInBinary(), i+1);
                //置换选择2
                output[i] = SwapSelect2(c.Append(d));
                //Debug.WriteLine(output[i].PrintInBinary());
                //Debug.WriteLine("C:{0} D:{1} out:{2}",c.PrintInHex(),d.PrintInHex(),output[i].PrintInHex());
            }
            return(output);
        }
Exemple #7
0
        /// <summary>
        /// Extension method to scan a byte array from current bitarray
        /// </summary>
        /// <param name="current">current bit array</param>
        /// <param name="bytesOut">output parameter for byte array extraction</param>
        /// <param name="numBytes">number of bytes to scan from bitarray</param>
        /// <returns>bitarray with scanned bits removed</returns>
        public static BitArray nextBytes(this BitArray current, out byte[] bytesOut, int numBytes)
        {
            bool[] bools = new bool[current.Count];
            current.CopyTo(bools, 0);

            if (bools.Length < numBytes * 8)
            {
                throw new Exception("Not enough bits in bitarray");
            }

            BitArray scanBytes = new BitArray(0);

            for (int k = numBytes * 8 - 1; k >= 0; k--)
            {
                scanBytes = scanBytes.Append(bools[k]);
            }

            byte[] _bytesOut = new byte[numBytes];
            scanBytes.CopyTo(_bytesOut, 0);
            Array.Reverse(_bytesOut, 0, _bytesOut.Length);
            bytesOut = _bytesOut;

            bools   = bools.RemoveAt(0, numBytes * 8);
            current = new BitArray(bools);
            return(current);
        }
Exemple #8
0
        /// <summary>
        /// Extension method to scan an integer from current bitarray
        /// </summary>
        /// <param name="current">current bit array</param>
        /// <param name="intOut">output parameter for integer extraction</param>
        /// <param name="numBits">number of bits to scan for integer</param>
        /// <returns>bitarray with scanned bits removed</returns>
        public static BitArray nextInt(this BitArray current, out int intOut, int numBits)
        {
            bool[] bools = new bool[current.Count];
            current.CopyTo(bools, 0);

            if (numBits > 32)
            {
                throw new Exception("Integer cannot be longer than 32 bits");
            }
            if (bools.Length < numBits)
            {
                throw new Exception("Not enough bits in bitarray");
            }

            BitArray scanInt = new BitArray(0);

            for (int k = numBits - 1; k >= 0; k--)
            {
                scanInt = scanInt.Append(bools[k]);
            }

            int[] _intOut = new int[1];
            scanInt.CopyTo(_intOut, 0);
            intOut = _intOut[0];

            bools   = bools.RemoveAt(0, numBits);
            current = new BitArray(bools);
            return(current);
        }
Exemple #9
0
        public bool WriteData(string text)
        {
            if (text.Length > ImageBytesMax)
            {
                return(false);
            }

            BitArray bits = new BitArray(0);

            bits = bits.Append(Conversion.AsciiStrToByteArray(text));

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Color pixelCol = srcBitmap.GetPixel(x, y);
                    byte  newR     = pixelCol.R;
                    byte  newG     = pixelCol.G;
                    byte  newB     = pixelCol.B;

                    if (bits.Length > 0)
                    {
                        bool nextBit1;
                        bits = bits.nextBit(out nextBit1);
                        newR = (byte)(nextBit1 ? pixelCol.R | 0x01 : pixelCol.R & 0xFE);
                    }
                    else
                    {
                        newR = (byte)(pixelCol.R & 0xFE);
                    }
                    if (bits.Length > 0)
                    {
                        bool nextBit2;
                        bits = bits.nextBit(out nextBit2);
                        newG = (byte)(nextBit2 ? pixelCol.G | 0x01 : pixelCol.G & 0xFE);
                    }
                    else
                    {
                        newG = (byte)(pixelCol.G & 0xFE);
                    }
                    if (bits.Length > 0)
                    {
                        bool nextBit3;
                        bits = bits.nextBit(out nextBit3);
                        newB = (byte)(nextBit3 ? pixelCol.B | 0x01 : pixelCol.B & 0xFE);
                    }
                    else
                    {
                        newB = (byte)(pixelCol.B & 0xFE);
                    }
                    Color newCol = Color.FromArgb(newR, newG, newB);
                    srcBitmap.SetPixel(x, y, newCol);
                }
            }

            BytesAvailable = ImageBytesMax - text.Length;
            srcBitmap.Save(bitmapPath);

            return(true);
        }
Exemple #10
0
        public string Decrypt(string cipher, string key)
        {
            cipher = string.Join(string.Empty,
                                 cipher.Select(
                                     c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')
                                     )
                                 );

            key = string.Join(string.Empty,
                              key.Select(
                                  c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')
                                  )
                              );

            var keyBits = new BitArray(key.Select(c => c == '1').ToArray());

            var result = "";

            //split the string into blocks of 64 bits
            var output = Enumerable.Range(0, cipher.Length / 64)
                         .Select(x => cipher.Substring(x * 64, 64)).ToList();


            var newInput = output.ToArray();

            var subKeys = _key.GenerateKeys(keyBits).Reverse().ToArray();

            for (var i = 0; i < newInput.Length; i++)
            {
                var bits = new BitArray(newInput[i].Select(c => c == '1').ToArray());
                //Initial Permutation
                var chunk = _des.InitialPermutation(bits);

                //split the chunk in two halves 32 bit each
                var sides = chunk.Split();

                _leftSide  = sides[0];
                _rightSide = sides[1];



                _leftSide = sides[1];
                _tempLeft = sides[0];

                for (var j = 0; j < 16; j++)
                {
                    _rightSide = _des.RoundFunction(_rightSide, subKeys[j]); //rn = f(rn-1,kn)
                    _rightSide = _tempLeft.Xor(_rightSide);                  //rn = ln-1 xor rn

                    _tempLeft = _leftSide;
                    _leftSide = _rightSide;
                }

                var finalPerm = _rightSide.Append(_tempLeft);
                finalPerm = _des.FinalPermutation(finalPerm);
                result   += BinaryStringToHexString(finalPerm);
            }
            return(result);
        }
Exemple #11
0
 public static BitArray PadRemaining(this BitArray current, bool padBit, int len = 0)
 {
     if (len > 0)
     {
         while (current.Length != len)
         {
             current = current.Append(padBit);
         }
     }
     else
     {
         while (current.Length % 8 != 0)
         {
             current = current.Append(padBit);
         }
     }
     return(current);
 }
Exemple #12
0
        public BinaryTree <Frequencytem <T> > Compute <T>(IList <Frequencytem <T> > items)
        {
            //头一次碰到普通BinaryTree应用。

            var queue = new BinanyHeap <BinaryTreeNode <Frequencytem <T> > >
                        (
                items.Select(i => new BinaryTreeNode <Frequencytem <T> >()
            {
                Data = i
            }).ToList()
                , (a, b) => a.Data.Frequency < b.Data.Frequency
                        );

            for (int i = 1; i < items.Count; i++)
            {
                var childRoot = new BinaryTreeNode <Frequencytem <T> >();

                childRoot.Left  = queue.Extract();
                childRoot.Right = queue.Extract();
                childRoot.Data  = new Frequencytem <T>()
                {
                    Frequency = childRoot.Left.Data.Frequency
                                + childRoot.Right.Data.Frequency
                };

                queue.Insert(childRoot);
            }

            //也是头一次用
            var oneBit  = new BitArray(1, true);
            var zeroBit = new BitArray(1, false);

            var tree = new BinaryTree <Frequencytem <T> >(queue.Extract());

            tree.Preorder(tree.Root, (node) =>
            {
                var code = node.Data.Code;


                if (node == tree.Root)
                {
                    code = new BitArray(0);
                }

                if (node.Left != null)
                {
                    node.Left.Data.Code = zeroBit.Append(code);
                }
                if (node.Right != null)
                {
                    node.Right.Data.Code = oneBit.Append(code);
                }
            }
                          );

            return(tree);
        }
        public BitArray ToBitArray()
        {
            BitArray bitArray = new BitArray(ChannelCountSize);
            int      arrayPos = 0;

            bitArray.SetBits(ref arrayPos, (byte)(Channels.Length - 1), ChannelCountSize);

            for (int i = 0; i < Channels.Length; i++)
            {
                bitArray = bitArray.Append(Channels[i].HeaderToBits());
            }
            for (int i = 0; i < Channels.Length; i++)
            {
                bitArray = bitArray.Append(new BitArray(Channels[i].Notes));
            }

            return(bitArray);
        }
Exemple #14
0
        public BitArray GetCoefficients()
        {
            BitArray bytes = new BitArray(0);

            for (int i = 0; i < _coefficients.Count; ++i)
            {
                bytes = bytes.Append(GetCoefficient(i));
            }

            return(bytes);
        }
        public BitArray GetAllCoefficientsInBytes()
        {
            BitArray bytes = new BitArray(0);

            for (int i = 0; i < Coefficients.Count; i++)
            {
                bytes = bytes.Append(GetCoefficient(i));
            }

            return(bytes);
        }
Exemple #16
0
        private BitArray GetUnitsCodes()
        {
            BitArray codes = new BitArray(0);

            foreach (UnitStruct unit in units)
            {
                BitArray vetCode  = ConvertToBigEndianBitArray(unit.Veterancy, 3);
                BitArray unitCode = ConvertToBigEndianBitArray(unit.Unit, 11);
                codes.Append(vetCode).Append(unitCode);
            }
            return(codes);
        }
Exemple #17
0
        private BitArray RegisterFormat(OperationEnum operation, List <string> parts)
        {
            var result = new BitArray(6, false);

            var register1String = parts[1].Trim(new char[] { '$', ',' });

            if (Enum.TryParse(register1String, true, out RegisterEnum register))
            {
                var bits = new BitArray(new byte[1] {
                    (byte)register
                });
                bits = bits.Trim(5);

                result = result.Append(bits);
            }

            var register2String = parts[2].Trim(new char[] { '$', ',' });

            if (Enum.TryParse(register2String, true, out RegisterEnum register2))
            {
                var bits = new BitArray(new byte[1] {
                    (byte)register2
                });
                bits = bits.Trim(5);

                result = result.Append(bits);
            }

            var register3String = parts[3].Trim(new char[] { '$', ',' });

            if (Enum.TryParse(register3String, true, out RegisterEnum register3))
            {
                var bits = new BitArray(new byte[1] {
                    (byte)register3
                });
                bits = bits.Trim(5);

                result = result.Append(bits);
            }

            else if (Int16.TryParse(parts[3], out short resultParse)) // valor constante
            {
                result.Append(new BitArray(new int[1] {
                    resultParse
                }));
            }

            result = result.Append(new BitArray(5, false));

            var bitsEX = new BitArray(new byte[1] {
                (byte)operation
            });

            bitsEX = bitsEX.Trim(6);

            result = result.Append(bitsEX);

            return(result);
        }
Exemple #18
0
        private BitArray GetTransportedUnitsCodes()
        {
            BitArray codes = new BitArray(0);

            foreach (TransportedUnitStruct transportedUnit in transportedUnits)
            {
                BitArray vetCode       = ConvertToBigEndianBitArray(transportedUnit.Veterancy, 3);
                BitArray unitCode      = ConvertToBigEndianBitArray(transportedUnit.Unit, 11);
                BitArray transportCode = ConvertToBigEndianBitArray(transportedUnit.Transport, 11);

                codes.Append(vetCode).Append(unitCode).Append(transportCode);
            }
            return(codes);
        }
        public void AppendBitArrayTest()
        {
            var original = new BitArray(new bool[4] {
                true, true, false, false
            });
            var toAppend = new BitArray(new bool[4] {
                true, true, false, false
            });
            var result = original.Append(toAppend);

            Assert.Equal(8, result.Length);
            Assert.True(result[1]);
            Assert.False(result[3]);
            Assert.True(result[4]);
            Assert.False(result[7]);
        }
        private BitArray GenerateKeys(BitArray left, BitArray right, int round)
        {
            BitArray key;
            int      shift;

            if (round == 0 || round == 1 || round == 8 || round == 15)
            {
                shift = 1;
            }
            else
            {
                shift = 2;
            }

            _firstHalf  = ShiftLeft(left, shift);
            _secondHalf = ShiftLeft(right, shift);

            key = _firstHalf.Append(_secondHalf);
            key = PermuteChoice2(key);
            return(key);
        }
Exemple #21
0
        public string ReadData()
        {
            BytesAvailable = ImageBytesMax;
            BitArray bits = new BitArray(0);

            bool[] allBits = new bool[Height * Width * 24];
            int    j       = 0;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Color pixelCol = srcBitmap.GetPixel(x, y);
                    allBits[j++] = (pixelCol.R & 0x01) == 0x01;
                    allBits[j++] = (pixelCol.G & 0x01) == 0x01;
                    allBits[j++] = (pixelCol.B & 0x01) == 0x01;
                }
            }
            bits = bits.Append(allBits);

            byte[] decoded = new byte[ImageBytesMax];
            bits.nextBytes(out decoded, decoded.Length);
            for (int k = 0; k < decoded.Length; k++)
            {
                if (Char.IsControl((char)decoded[k]))
                {
                    decoded         = decoded.Take(k).ToArray();
                    BytesAvailable -= k;
                    break;
                }
                else if (k == decoded.Length - 1)
                {
                    BytesAvailable = 0;
                }
            }

            return(Conversion.BytesToString(decoded));
        }
Exemple #22
0
        /// <summary>
        /// Преобразование строки в hex формате в строку Base64
        /// </summary>
        /// <param name="hexString"></param>
        /// <returns>Строка в формате Base64</returns>
        static string HexToBase64(string hexString)
        {
            byte[]   bytes      = HexToByteArray(hexString);
            BitArray stringBits = new BitArray(0);

            foreach (var b in bytes)
            {
                BitArray bitsInByte = new BitArray(new byte[] { b });
                Reverse(bitsInByte);
                stringBits = stringBits.Append(bitsInByte);
            }

            var bitChunks = stringBits.Split(6);

            StringBuilder resultBuilder = new StringBuilder();

            foreach (var bitChunk in bitChunks)
            {
                Reverse(bitChunk);
                StringBuilder bitRepresentationBuiler = new StringBuilder();
                foreach (var bit in bitChunk)
                {
                    bitRepresentationBuiler.Append((bool)bit ? "1" : "0");
                }

                var base64Result = BitChunkToBase64(bitChunk);
                resultBuilder.Append(base64Result);

                Console.WriteLineFormatted("[{0}] -> Base64: {1}", Color.Gray, new Formatter[] {
                    new Formatter(bitRepresentationBuiler.ToString(), Color.Yellow),
                    new Formatter(base64Result, Color.LawnGreen)
                });
            }

            Console.WriteLine();
            return(resultBuilder.ToString());
        }
Exemple #23
0
        //Preverjanje veljavnosti maske torej, da so enice ločene od ničel.
        public static bool IsValid(IPAddress subnetMask)
        {
            //pridobimo vse dele
            byte[] parts = subnetMask.GetAddressBytes();

            var bitArrayOfFirst  = new BitArray(new[] { parts[0] });
            var bitArrayOfSecond = new BitArray(new[] { parts[1] });
            var bitArrayOfThird  = new BitArray(new[] { parts[2] });
            var bitArrayOfFourth = new BitArray(new[] { parts[3] });

            //obrnemo bite, ker je vrstni red bitov v BitArray od LSB -> MSB (Most Significant Bit)
            bitArrayOfFirst.Reverse();
            bitArrayOfSecond.Reverse();
            bitArrayOfThird.Reverse();
            bitArrayOfFourth.Reverse();

            //spnemo bitna polja
            var bits = bitArrayOfFirst.Append(bitArrayOfSecond).Append(bitArrayOfThird).Append(bitArrayOfFourth);

            //preverjamo, da se po prvi ničli ne pojavi nobena enica
            bool foundZero = false;

            foreach (bool bit in bits)
            {
                if (!bit)
                {
                    foundZero = true;
                }

                if (foundZero && bit)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #24
0
        public Bitmap serializePattern()
        {
            MemoryStream ms = new MemoryStream();

            BinaryWriter br = new BinaryWriter(ms);

            br.Write(padBytes(0));

            byte[] nameBytes = UnicodeEncoding.Unicode.GetBytes(designName);
            int pad = 41 - nameBytes.Length;

            br.Write(nameBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            // These are *1 and 2, the first two bytes of the unique id.
            br.Write(padBytes(2));

            byte[] creatorBytes = UnicodeEncoding.Unicode.GetBytes(creatorName);
            pad = 20 - nameBytes.Length;

            br.Write(creatorBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            // Special bytes 3 and 4.
            br.Write(padBytes(2));

            byte[] cityBytes = UnicodeEncoding.Unicode.GetBytes(cityName);

            pad = 18 - nameBytes.Length;

            br.Write(cityBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            br.Write(padBytes(4));

            for (int i = 0; i < 15; i++)
            {
                br.Write(new byte[]{NewLeafBitmap.findPalIndexInv(this.design.filepal[i])});
            }

            // Special byte 7.
            br.Write(padBytes(1));

            br.Write(new byte[] { (byte)0x0A });
            br.Write(new byte[] { (byte)0x09 });

            br.Write(padBytes(2));

            BitArray halfBytes = new BitArray(1024*4);

            int counter = 0;

            List<byte> blist = new List<byte>();

            for (int i = 0; i < 32; i++)
                for (int j = 0; j < 32; j++)
                {
                    blist.Add((byte)(this.design.falseColor.GetPixel(j,i).ToArgb()));

                }

            int counterR = 0;
            for (int i = 0; i < blist.Count; )
            {
                BitArray halfWord = new BitArray(new byte[] { blist[i] });
                halfBytes[counterR + 4] =     halfWord[0];
                halfBytes[counterR + 5]= halfWord[1];
                halfBytes[counterR + 6] = halfWord[2];
                halfBytes[counterR + 7] = halfWord[3];
                halfWord = new BitArray(new byte[] { blist[i + 1] });
                halfBytes[counterR + 0] = halfWord[0];
                halfBytes[counterR + 1] = halfWord[1];
                halfBytes[counterR + 2] = halfWord[2];
                halfBytes[counterR + 3] = halfWord[3];
                counterR += 8;

                i += 2;
            }

            FileStream fs = File.Open("C:/DATASETS/serialize.txt", FileMode.Create);
               // ms.CopyTo(fs);

            byte[] junk = copyOctetwiseReverse(ms.ToArray());
            BitArray a = new BitArray(junk);

              //  a = a.Append(new BitArray(4));

            BitArray ab = a.Append(halfBytes);

            BitArray header = new BitArray(new byte[]{QR_MAGIC});
            header.Reverse();
            BitArray header2 = new BitArray(new byte[] { 38 });
            header2.Reverse();

            BitArray header3 = new BitArray(4);

            header3.Set(1, true);
            header3.Set(1, true);
            header3.Set(0, true);
            header3.Set(0, true);

            //header = header2.Prepend(header);

             BitArray all = header.Append(header2);
             all = all.Append(header3);

             all = all.Append(ab);

            byte[] omni = all.ToByteArray();

            MessageBox.Show(BitConverter.ToString(omni));

            fs.Write(omni,0,omni.Length);

               // fs.WriteByte(0xEC);
              //  fs.WriteByte(0x11);
               // fs.WriteByte(0xEC);
               // fs.WriteByte(0x11);
            System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1");

            QRCodeWriter qrw = new QRCodeWriter();

               // for (int i = 0; i < omni.Length; i++)
               // {
               //     omni[i] = (byte)((sbyte)omni[i]);
               // }

            Dictionary<EncodeHintType, object> h = new Dictionary<EncodeHintType, object>();
            h.Add(ZXing.EncodeHintType.CHARACTER_SET, "CP437");

            h.Add(ZXing.EncodeHintType.DISABLE_ECI, true);
            h.Add(ZXing.EncodeHintType.ERROR_CORRECTION,ZXing.QrCode.Internal.ErrorCorrectionLevel.H);

            ZXing.QrCode.QrCodeEncodingOptions qrec = new QrCodeEncodingOptions();

            var writer = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = 188,
                    Width = 188,
                    CharacterSet = "CP437",
                    PureBarcode = true,
                    ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.L,
                    DisableECI = false,

                }

            };

            char[] chars = new char[omni.Length];

            for (int i = 0; i < omni.Length; i++)
            {
                chars[i] = (char) omni[i];
            }

            ZXing.Common.BitMatrix bmx =  writer.
               Encode(Encoding.GetEncoding("CP437").GetString(omni));//qrw.encode(new String(), ZXing.BarcodeFormat.QR_CODE, 300, 300);

            //bmx = createBinQRCode(omni, omni.Length, 0);

            fs.Close();

            ms.Close();

              //return bmx.ToBitmap();

               ZXing.BarcodeWriter ss= new ZXing.BarcodeWriter();

               ZXing.IBarcodeWriter reader = new BarcodeWriter();

             ZXing.Rendering.BitmapRenderer bmpr = new ZXing.Rendering.BitmapRenderer();
             MessageBox.Show(Encoding.GetEncoding("CP437").GetString(omni).Substring(0, 10));
             return bmpr.Render(bmx, writer.Format,  Encoding.GetEncoding("CP437").GetString(omni));

            //   Gma.QrCodeNet.Encoding.QrEncoder hi = new Gma.QrCodeNet.Encoding.QrEncoder();
             //  Gma.QrCodeNet.Encoding.QrCode qr = new Gma.QrCodeNet.Encoding.QrCode();
             //

             //  hi.ErrorCorrectionLevel = Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L;

             //  hi.TryEncode(omni, out qr);

             //  SVGRenderer svg = new SVGRenderer(new FixedModuleSize(6, QuietZoneModules.Two), new FormColor(Color.Black), new FormColor(Color.White));

               // FileStream FSX = new FileStream("C:/DATASETS/QR.svg", FileMode.Create);
            //svg.WriteToStream(qr.Matrix, FSX);
              //  FSX.Close();

             // Bitmap bmp2 = new Bitmap(qr.Matrix.Width, qr.Matrix.Height);
             //  for (int i = 0; i < qr.Matrix.Width; i++)
             //      for (int j = 0; j < qr.Matrix.Height; j++)
             //          bmp2.SetPixel(i, j, qr.Matrix.InternalArray[i, j] ? Color.Black : Color.White);

             //  bmp2.Save("C:/DATASETS/gma");

            //   return bmp2;
        }
Exemple #25
0
 public static BitArray Append(this BitArray current, Byte after)
 {
     return(current.Append(new BitArray(new[] { after })));
 }