Пример #1
0
        private static void Decode(string filePath, string keyPath)
        {
            string input            = ReadFileContent(filePath);
            var    codeCharacterMap = KeyManager.ReadKey(keyPath);
            var    result           = HuffmanCodingOperations.Decode(input, codeCharacterMap);

            Console.WriteLine(result);
            WriteFileContent("DecodeOutput.txt", result);
        }
Пример #2
0
        private static void Encode(string filePath)
        {
            string input            = ReadFileContent(filePath);
            var    symbols          = HuffmanCodingOperations.AnalyzeSymbols(input);
            var    root             = HuffmanCodingOperations.BuildSymbolTree(symbols);
            var    codeCharacterMap = new Dictionary <char, List <bool> >();

            HuffmanCodingOperations.CreateCharacterMap(root, new List <bool>(), codeCharacterMap);
            KeyManager.SaveKey(codeCharacterMap, "key.txt");
            var    result          = HuffmanCodingOperations.Encode(input, codeCharacterMap);
            string resultFormatted = string.Join("", result.Select(x => x.ToChar()));

            Console.WriteLine(resultFormatted);
            WriteFileContent("EncodeOutput.txt", resultFormatted);
        }