Esempio n. 1
0
        public void GetOptimalBitsCount()
        {
            Assert.AreEqual(5, BaseN.GetOptimalBitsCount2(32, out var charsCountInBits));
            Assert.AreEqual(6, BaseN.GetOptimalBitsCount2(64, out charsCountInBits));
            Assert.AreEqual(32, BaseN.GetOptimalBitsCount2(85, out charsCountInBits));
            Assert.AreEqual(13, BaseN.GetOptimalBitsCount2(91, out charsCountInBits));

            StringBuilder builder = new StringBuilder();

            for (int i = 2; i <= 256; i++)
            {
                var    bits  = BaseBigN.GetOptimalBitsCount2((uint)i, out charsCountInBits, 512);
                double ratio = (double)bits / charsCountInBits;

                builder.AppendLine(bits + "	" + charsCountInBits + "	"+ ratio.ToString("0.0000000"));
            }
            string str = builder.ToString();
        }
Esempio n. 2
0
 public void EncodeDecodeBaseBigNMaxCompression()
 {
     byte testByte = 157;
     List<byte> bytes = new List<byte>();
     for (uint radix = 2; radix < 1000; radix++)
     {
         var baseN = new BaseBigN(StringGenerator.GetAlphabet((int)radix), 256, null, false, false, true);
         int testBytesCount = Math.Max((baseN.BlockBitsCount + 7) / 8, baseN.BlockCharsCount);
         bytes.Clear();
         for (int i = 0; i <= testBytesCount + 1; i++)
         {
             var array = bytes.ToArray();
             var encoded = baseN.Encode(array);
             var decoded = baseN.Decode(encoded);
             CollectionAssert.AreEqual(array, decoded);
             bytes.Add(testByte);
         }
     }
 }
Esempio n. 3
0
        public void EncodeDecodeBaseBigN()
        {
            byte        testByte = 157;
            List <byte> bytes    = new List <byte>();

            for (uint radix = 2; radix < 1000; radix++)
            {
                var baseN          = new BaseBigN(StringGenerator.GetAlphabet((int)radix), 256);
                int testBytesCount = Math.Max((baseN.BlockBitsCount + 7) / 8, baseN.BlockCharsCount);
                bytes.Clear();
                for (int i = 0; i <= testBytesCount + 1; i++)
                {
                    var array   = bytes.ToArray();
                    var encoded = baseN.Encode(array);
                    var decoded = baseN.Decode(encoded);
                    CollectionAssert.AreEqual(array, decoded);
                    bytes.Add(testByte);
                }
            }
        }
Esempio n. 4
0
 private Base GetMethod()
 {
     Base method = null;
     string alphabet = tbAlphabet.Text;
     if (tbSpecialChar.Text.Length > 1)
         throw new ArgumentException("Special char should contains one symbol");
     char special = string.IsNullOrWhiteSpace(tbSpecialChar.Text) ? (char)0 : tbSpecialChar.Text[0];
     Encoding textEncoding = cmbTextEncoding.SelectedItem != null ?
         (Encoding)((ComboBoxItem)cmbTextEncoding.SelectedItem).Value : null;
     bool parallel = cbParallel.Checked;
     switch (cmbMethod.SelectedItem.ToString())
     {
         case "Base32":
             method = new Base32(alphabet, special, textEncoding);
             break;
         case "Base64":
             method = new Base64(alphabet, special, textEncoding, parallel);
             break;
         case "Base128":
             method = new Base128(alphabet, special, textEncoding);
             break;
         case "Base256":
             method = new Base256(alphabet, special, textEncoding);
             break;
         case "Base1024":
             method = new Base1024(alphabet, special, textEncoding);
             break;
         case "Base4096":
             method = new Base4096(alphabet, special, textEncoding);
             break;
         case "ZBase32":
             method = new ZBase32(alphabet, special, textEncoding);
             break;
         case "Base85":
             method = new Base85(alphabet, special, cbPrefixPostfix.Checked, textEncoding);
             break;
         case "Base91":
             method = new Base91(alphabet, special, textEncoding);
             break;
         case "BaseN":
             method = new BaseN(alphabet, (uint)nudMaxBitsCount.Value, textEncoding, cbReverseOrder.Checked, parallel);
             break;
         case "BaseBigN":
             method = new BaseBigN(alphabet, (uint)nudMaxBitsCount.Value, textEncoding,
                 cbReverseOrder.Checked, parallel, cbMaxCompression.Checked);
             break;
     }
     tbBitsPerChars.Text = method.BlockBitsCount + "/" + method.BlockCharsCount;
     tbRatio.Text = ((double)method.BlockBitsCount / method.BlockCharsCount).ToString("0.000000");
     nudAlphabetLength.Value = method.CharsCount;
     return method;
 }
Esempio n. 5
0
        private Base GetMethod()
        {
            Base   method   = null;
            string alphabet = tbAlphabet.Text;

            if (tbSpecialChar.Text.Length > 1)
            {
                throw new ArgumentException("Special char should contains one symbol");
            }
            char     special      = string.IsNullOrWhiteSpace(tbSpecialChar.Text) ? (char)0 : tbSpecialChar.Text[0];
            Encoding textEncoding = cmbTextEncoding.SelectedItem != null ?
                                    (Encoding)((ComboBoxItem)cmbTextEncoding.SelectedItem).Value : null;
            bool parallel = cbParallel.Checked;

            switch (cmbMethod.SelectedItem.ToString())
            {
            case "Base32":
                method = new Base32(alphabet, special, textEncoding);
                break;

            case "Base64":
                method = new Base64(alphabet, special, textEncoding, parallel);
                break;

            case "Base128":
                method = new Base128(alphabet, special, textEncoding);
                break;

            case "Base256":
                method = new Base256(alphabet, special, textEncoding);
                break;

            case "Base1024":
                method = new Base1024(alphabet, special, textEncoding);
                break;

            case "Base4096":
                method = new Base4096(alphabet, special, textEncoding);
                break;

            case "ZBase32":
                method = new ZBase32(alphabet, special, textEncoding);
                break;

            case "Base85":
                method = new Base85(alphabet, special, cbPrefixPostfix.Checked, textEncoding);
                break;

            case "Base91":
                method = new Base91(alphabet, special, textEncoding);
                break;

            case "BaseN":
                method = new BaseN(alphabet, (uint)nudMaxBitsCount.Value, textEncoding, cbReverseOrder.Checked, parallel);
                break;

            case "BaseBigN":
                method = new BaseBigN(alphabet, (uint)nudMaxBitsCount.Value, textEncoding,
                                      cbReverseOrder.Checked, parallel, cbMaxCompression.Checked);
                break;
            }
            tbBitsPerChars.Text     = method.BlockBitsCount + "/" + method.BlockCharsCount;
            tbRatio.Text            = ((double)method.BlockBitsCount / method.BlockCharsCount).ToString("0.000000");
            nudAlphabetLength.Value = method.CharsCount;
            return(method);
        }