Exemplo n.º 1
0
        public void EmptyAlphabetNonEmptyStringDecryptionTest()
        {
            string empty    = string.Empty;
            var    unzipper = new LZWDecompress(empty);

            unzipper.Decrypt("0");
        }
Exemplo n.º 2
0
        public byte[] Decode(byte[] content)
        {
            var lzw    = new LZWDecompress();
            var input  = Encoding.ASCII.GetString(content);
            var output = lzw.Decompress(input);

            return(output);
        }
Exemplo n.º 3
0
        public void EmptyStringTest()
        {
            string empty    = string.Empty;
            var    zipper   = new LZWCompress(empty);
            var    zipperPT = new LZWCompressPT(empty);
            var    unzipper = new LZWDecompress(empty);

            Assert.AreEqual(empty, zipper.Encrypt(empty));
            Assert.AreEqual(empty, zipperPT.Encrypt(empty));
            Assert.AreEqual(empty, unzipper.Decrypt(empty));
        }
Exemplo n.º 4
0
        public SourceFile Run(EncodedFile encoded, string outputPath)
        {
            var lzwDecoder     = new LZWDecompress();
            var huffmanDecoder = new HuffmanDecoder(encoded.Header.HuffmanMetadata);

            var bytes   = encoded.Content.ToArray();
            var decoded = huffmanDecoder.Decode(bytes);
            var input   = Encoding.ASCII.GetString(decoded);
            var outLzw  = lzwDecoder.Decompress(input);

            return(new SourceFile(outputPath, outLzw, encoded.Header.SourceExtension));
        }
Exemplo n.º 5
0
        private void LZWDecompressButton_Click_1(object sender, EventArgs e)
        {
            IFileOperationsController _fileOperationController = new FileOperationsController();
            LZWDecompress             _lzwDecompress           = new LZWDecompress(this);


            string decompressedFilePath = compressedFilePathRichTextBox.Text.Remove(compressedFilePathRichTextBox.Text.Length - 14) + "Uncompressed.txt";

            decompressedFileNameTextBox.Text = decompressedFilePath;
            _lzwDecompress.LZWDecompressFile(compressedFilePathRichTextBox.Text, decompressedFilePath, Convert.ToInt16(selectedMaxBitSizeTextbox.Text));
            decompressedByteSizeTextBox.Text = _fileOperationController.getFileByteSize(decompressedFilePath);

            compressedPercentanceTextBox.Text     = _lzwDecompress.getCompressionRatio(double.Parse(compressedByteSizeTextBox.Text), double.Parse(decompressedByteSizeTextBox.Text)) + " %";
            CompressedDataPercentanceTextBox.Text = (100 - Convert.ToDouble(compressedPercentanceTextBox.Text.Remove(compressedPercentanceTextBox.Text.Length - 2))).ToString() + " %";
        }
Exemplo n.º 6
0
        public void AllStringsTest()
        {
            string fullAlphabet = "abcdefghijklmnopqrstuvwxyz";

            int maxAlphabetLength = 12;
            int maxLength         = 6;

            StringBuilder builder = new StringBuilder();

            // For alphabets of different sizes
            for (int alphabetSize = 1; alphabetSize <= maxAlphabetLength; ++alphabetSize)
            {
                string alphabet = fullAlphabet.Substring(0, alphabetSize);
                var    zipper   = new LZWCompress(alphabet);
                var    zipperPT = new LZWCompressPT(alphabet);
                var    unzipper = new LZWDecompress(alphabet);

                // For strings in current alphabet of different size
                for (int strlen = 0; strlen <= maxLength; ++strlen)
                {
                    // Number of all possible strings in current alphabet of current size
                    int strings = (int)Math.Pow(alphabet.Length, strlen);

                    for (int i = 0; i < strings; ++i)
                    {
                        builder.Clear();
                        int mask = i;
                        for (int shift = 0; shift < strlen; ++shift)
                        {
                            builder.Append(alphabet[mask % alphabet.Length]);
                            mask >>= 1;
                        }

                        string message     = builder.ToString();
                        string encrypted   = zipper.Encrypt(message);
                        string encryptedPT = zipperPT.Encrypt(message);
                        Assert.AreEqual(encrypted, encryptedPT);
                        Assert.AreEqual(message, unzipper.Decrypt(encrypted));
                    }
                }
            }
        }