private string Encode()
        {
            byte[]       bytes             = Encoding.UTF8.GetBytes(String);
            BinaryString binaryStr         = BinaryString.FromString(String, Encoding.UTF8);
            BinaryString invertedBinaryStr = binaryStr.InvertBinaries();
            BinaryString reversedBinaryStr = invertedBinaryStr.ReverseBinaries();

            StringBuilder buffer = new StringBuilder();
            int           index;

            foreach (char c in reversedBinaryStr.ToString())
            {
                if (c == '0')
                {
                    index = _random.Next(_charsForZero.Length);
                    buffer.Append(_charsForZero[index]);
                }
                else
                {
                    index = _random.Next(_charsForOne.Length);
                    buffer.Append(_charsForOne[index]);
                }

                if (_random.Next(100) > 100 - InMiddleCharsStrength)
                {
                    index = _random.Next(_charsInTheMiddle.Length);
                    buffer.Append(_charsInTheMiddle[index]);
                }
            }

            return(buffer.ToString());
        }
示例#2
0
        public void BinaryStringTest()
        {
            BinaryString str  = BinaryString.FromString("hello world");
            BinaryString str2 = BinaryString.FromString("hello world");

            Assert.AreEqual(str, str2);
            Assert.AreEqual("0110100001100101011011000110110001101111001000000111011101101111011100100110110001100100", str.ToString());

            BinaryString str3 = BinaryString.FromString("a");

            Assert.AreEqual("01100001", str3.ToString());

            BinaryString invertedStr3 = str3.InvertBinaries();

            Assert.AreEqual("10011110", invertedStr3.ToString());

            BinaryString reversedStr3 = str3.ReverseBinaries();

            Assert.AreEqual("10000110", reversedStr3.ToString());
        }