when encoding,file now open towrite file in binary mode to ensure that when the decoding function reads the file, it will read the same chars. Also added a bit of debugging features