Esempio n. 1
0
        private async Task TokenizeString(TokenTableSet table, ConcurrentBag <BasicResult> results, string source)
        {
            var seeds  = new List <int>();
            var result = new BasicResult {
                Value = source
            };

            result = await Task.Run(() => TokenizeCycle(table, seeds, result));

            result.Action = ActionType.Tokenize;

            result.SourceValue = source;
            Encrypt(seeds, result);
            results.Add(result);
        }
Esempio n. 2
0
 private void Encrypt(List <int> seeds, BasicResult result)
 {
     if (_settings.Encrypt)
     {
         var seed                = string.Join("|", seeds);
         var fullString          = seed + "[ENDSEED]" + result.Value;
         var doubleArray         = fullString.Select(c => (int)c).ToArray();
         var flatArray           = string.Join("|", doubleArray);
         var compressedFlatArray = _compression.Compress(flatArray);
         result.Value = _encryption.EncryptString(compressedFlatArray);
     }
     else
     {
         result.Seed = seeds;
     }
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private BasicResult TokenizeCycle(TokenTableSet table, List <int> seeds, BasicResult result)
        {
            var currentSeed = -1;

            if (_settings.Behaviour == Behaviour.RandomSeedInconsistent && !_settings.SeedPerCycle)
            {
                currentSeed = GetSeed(table.ForwardTable.Count);
                seeds.Add(currentSeed);
            }

            for (int i = 0; i < _settings.Cycles; i++)
            {
                if (_settings.Behaviour == Behaviour.RandomSeedInconsistent && _settings.SeedPerCycle)
                {
                    currentSeed = GetSeed(table.ForwardTable.Count);
                    seeds.Add(currentSeed);
                }
                result = Encode(result.Value, table.ForwardTable, currentSeed);
            }

            return(result);
        }
Esempio n. 5
0
        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);
        }