I need to use Huffman encoding to compress, it should work properly showing a lot of 1s and 0s which is what it's supposed to return. Instead it returns this: "pbbuMWL62ue+z5RIEFoC", I have no clue where this comes from.
I already tried looking into the code to see if I am converting a byte into something else but I don't see it.
Here's the code:
//part of class Huffman tree which returns compressed bits "supposedly"
public byte[] Encode(string source)
{
List<bool> encodedSource = new List<bool>();
for (int i = 0; i < source.Length; i++)
{
List<bool> encodedSymbol = this.Root.Traverse(source[i], new List<bool>());
encodedSource.AddRange(encodedSymbol);
}
BitArray bits = new BitArray(encodedSource.ToArray());
byte[] result = BitArrayToByteArray(bits);
return result;
}
public static byte[] BitArrayToByteArray(BitArray bits)
{
byte[] ret = new byte[(bits.Length - 1) / 8 + 1];
bits.CopyTo(ret, 0);
return ret;
}
}
//part of the program that gets that return result in comp. cript
if(trabajar.companies != null)
{
List<string> doble = trabajar.companies.Distinct().ToList();
List<Compania> nop = new List<Compania>();
for (int i = 0; i < doble.Count; i++)
{
Compania comp = new Compania();
comp.Name = doble[i];
comp.Libreria.Build(comp.Name + "*" + trabajar.dpi);
comp.cript = comp.Libreria.Encode(comp.Name + "*" + trabajar.dpi);
nop.Add(comp);
}
participante.Search(busqueda, ComparacioDPI).companies = nop;
//object Compania
public class Compania
{
public string Name { get; set; }
public byte[] cript { get; set; }
[JsonIgnore]
public HuffmanTree Libreria = new HuffmanTree();
}
the result should be a bunch of 1s and 0s but what comes out is "cript": "reeYufa5zx/QxC4pDQ=="
I'm not using Encoding.ASCII.GetString(), as I don't want to encode it in ASCII