Esempio n. 1
0
        public async Task DeArchive()
        {
            await Task.Run(async() =>
            {
                BitArray storage = new BitArray(memFile);

                List <byte> list = new List <byte>();
                var dictionary   = await LoadDictionary();
                BitArray token   = new BitArray(0);

                for (int i = 0; i < fileSize; i++)
                {
                    token.Length++;
                    token.Set(token.Length - 1, storage.Get(i));

                    BitArray key;
                    if ((key = dictionary.Keys.Where(o => BitArrayEquals(o, token)).FirstOrDefault()) != null)
                    {
                        list.Add(dictionary[key]);
                        token.Length = 0;
                    }

                    LoadChanged?.Invoke((double)i / (double)(fileSize));
                }

                finalFile = list.ToArray();
            });
        }
Esempio n. 2
0
 public async Task Upload()
 {
     await Task.Run(() =>
     {
         using (FileStream sr = new FileStream(file, FileMode.Open))
         {
             int length = (int)sr.Length;
             memFile    = new byte[length];
             int count;
             int sum = 0;
             while ((count = sr.Read(memFile, sum, length - sum)) > 0)
             {
                 sum += count;
                 LoadChanged?.Invoke((double)sum / (double)length);
             }
         }
     });
 }
Esempio n. 3
0
        public async Task Archive()
        {
            await Task.Run(() =>
            {
                BitArray storage  = new BitArray(memFile);
                storage           = storage.Xor(storage);
                StringAnalizis sa = new StringAnalizis(memFile);
                sa.CountLetters();
                var dictionary = sa.Encrypt();


                int offset = 0;
                foreach (var b in memFile)
                {
                    for (int i = 0; i < dictionary[b].Length; i++)
                    {
                        storage.Set(offset, dictionary[b].Get(i));
                        offset++;
                    }

                    LoadChanged?.Invoke((double)offset / (double)(memFile.Length * 8));
                }

                BitArray final = new BitArray(offset + (8 - (offset % 8)));
                for (int i = 0; i < offset; i++)
                {
                    final.Set(i, storage[i]);
                }

                finalFile = new byte[final.Length / 8];
                final.CopyTo(finalFile, 0);
                fileSize = offset;

                LogDictionary(dictionary);
                SaveDictionary(new InfoBox()
                {
                    Keys = dictionary.Keys.ToArray(), Snippets = dictionary.Values.ToArray(), size = fileSize
                });
            });
        }