static void Main(string[] args) { try { LZWCompress lZW = new LZWCompress(); Console.WriteLine("Escribe el string a comprimir"); string text = Console.ReadLine(); Console.WriteLine("Se ha guardado el string con éxito para comprimir"); string CompressedText = lZW.CompressText(text); Console.WriteLine("El resultado de la compresión es el siguiente:"); Console.WriteLine(CompressedText); Console.WriteLine("¿Desea descomprimirlo? | Presione 'Y'. De lo contrario, presione cualquier otra tecla."); if (Console.ReadKey().Key == ConsoleKey.Y) { Console.Clear(); Console.WriteLine("El resultado de la descompresión es el siguiente:"); Console.WriteLine(lZW.DecompressText(CompressedText)); Console.ReadLine(); } Console.WriteLine("Feliz día!"); Console.ReadLine(); } catch { Console.WriteLine("Inserte un string válido"); Console.ReadLine(); Console.Clear(); } }
public void EmptyAlphabetNonEmptyStringEncryptionTest() { string empty = string.Empty; var zipper = new LZWCompress(empty); zipper.Encrypt("a"); }
public byte[] Encode(byte[] content) { var lzw = new LZWCompress(); var input = Encoding.ASCII.GetString(content); var output = lzw.Compress(input); var joined = string.Join(" ", output.Select(n => n)); return(Encoding.ASCII.GetBytes(joined)); }
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)); }
private void LZWCompressButton_Click_1(object sender, EventArgs e) { LZWCompress _lzwCompress = new LZWCompress(this); IReadFileController _readTextFileController = new ReadFileController(); IFileOperationsController _fileOperationController = new FileOperationsController(); string compressedFilePath = null; compressedFilePathRichTextBox.Text = filePathRichBox.Text.Remove(filePathRichBox.Text.Length - 4) + "Compressed.txt"; _lzwCompress.LZWCompressFile(filePathRichBox.Text, compressedFilePathRichTextBox.Text, Convert.ToInt16(selectedMaxBitSizeTextbox.Text)); compressedFilePath = filePathRichBox.Text.Remove(filePathRichBox.Text.Length - 4) + "Compressed.txt"; compressedByteSizeTextBox.Text = _fileOperationController.getFileByteSize(compressedFilePath); }
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)); } } } }