public BasicResult Detokenize(BasicRequest request, TokenTableSet table)
 {
     try
     {
         return(DetokenizeAsync(new List <BasicRequest> {
             request
         }, table).Result[0]);
     }
     catch (Exception ex)
     {
         throw ex.InnerException;
     }
 }
 private void Decrypt(BasicRequest request)
 {
     if (_settings.Encrypt)
     {
         var compressedFlatArray = _encryption.DecryptString(request.Source);
         var flatArray           = _compression.Decompress(compressedFlatArray);
         var doubleArray         = flatArray.Split('|').Select(o => Convert.ToInt32(o)).ToArray();
         var unicodeString       = new String(doubleArray.Select(o => (char)o).ToArray());
         var split = unicodeString.Split(new[] { "[ENDSEED]" }, StringSplitOptions.None);
         request.Seed   = split[0].Split('|').Select(o => Convert.ToInt32(o)).ToList();
         request.Source = split[1];
     }
 }
        private BasicResult DetokeniseCycle(TokenTableSet table, BasicRequest request, BasicResult result)
        {
            var seed = -1;

            if (_settings.Behaviour == Behaviour.RandomSeedInconsistent && !_settings.SeedPerCycle)
            {
                seed = request.Seed[0];
            }

            for (int i = 0; i < _settings.Cycles; i++)
            {
                if (_settings.Behaviour == Behaviour.RandomSeedInconsistent && _settings.SeedPerCycle)
                {
                    seed = request.Seed[i];
                }

                result = Encode(result.Value, table.ReverseTable, seed);
            }

            return(result);
        }
        private async Task DetokenizeString(TokenTableSet table, ConcurrentBag <BasicResult> results, BasicRequest request)
        {
            Decrypt(request);

            if (request.Seed != null)
            {
                request.Seed.Reverse();
            }
            var result = new BasicResult {
                Value = request.Source
            };

            result = await Task.Run(() => DetokeniseCycle(table, request, result));

            result.Action      = ActionType.Detokenize;
            result.SourceValue = request.Source;
            results.Add(result);
        }