Exemple #1
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public void TwoLevelsOfAnonymousMethods(int y)
            {
                var input  = new int[] { 100, 101, 102, 103 };
                var output = input.Select(item => item.ToString().ToCharArray().Select(c => (int)c + y).Sum().ToString()).ToArray();

                Output.AddRange(output);
            }
Exemple #2
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public void ReuseCapturesInManyAnonymousMethods(int y, int z)
            {
                var input = new int[] { 100, 101 };

                var output1 = input.Select(item => y.ToString() + ":" + item.ToString() + ":" + m_X.ToString()).ToArray();
                var output2 = input.Select(item => z.ToString() + ":" + item.ToString() + ":" + m_X.ToString()).ToArray();

                Output.AddRange(output1);
                Output.AddRange(output2);
            }
Exemple #3
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public void TwoLevelsOfAnonymousMethods2(int y)
            {
                var input  = new int[] { 100, 101, 102, 103 };
                var output = input.Select(
                    delegate(int item) {
                    var q = item * item;
                    return(item.ToString().ToCharArray().Select(c => (int)c + y * q).Sum().ToString());
                }).ToArray();

                Output.AddRange(output);
            }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        public void Merge(ITestContract itc)
        {
            if (itc == null)
            {
                throw new ArgumentNullException();
            }

            if (itc.SecurityLevel == TestCaseSecurityLevel.FullTrust)
            {
                this.SecurityLevel = TestCaseSecurityLevel.FullTrust;
            }

            if (!String.IsNullOrEmpty(itc.Area))
            {
                this.Area = itc.Area;
            }

            if (!String.IsNullOrEmpty(itc.Title))
            {
                if (String.IsNullOrEmpty(this.Title))
                {
                    this.Title = itc.Title;
                }
                else
                {
                    this.Title += "_" + itc.Title;
                }
            }

            if (itc.Disabled)
            {
                this.Disabled = true;
            }

            if (itc.Priority > this.Priority)
            {
                this.Priority = itc.Priority;
            }

            if (itc.Timeout != 0)
            {
                this.Timeout = itc.Timeout;
            }

            Input.AddRange(itc.Input);

            Output.AddRange(itc.Output);

            SupportFiles.AddRange(itc.SupportFiles);
        }
        protected override void entryPointFunctionCall()
        {
            //call sys.init and then call main.
            var callInit = new InstructionData(vmCommmandType.CALL, null, new string[] { "Sys.init", "0" }, "Sys.init", "Sys.init");

            handleFunctionCallingCommand(callInit);


            Output.Add(assembler.CommandType.HALT.ToString());


            var sysInitDefine = new InstructionData(vmCommmandType.FUNCTION, null, new string[] { "Sys.init", "0" }, "Sys.init", "Sys.init");

            handleFunctionCallingCommand(sysInitDefine);

            //for these tests we need to call our function with an argument.
            argsToPush.ToList().ForEach(arg =>
            {
                Output.AddRange(generatePushToStackFromSegment(vmMemSegments.constant, arg.ToString(), null));
            });


            //call the main.main func which is our real entry point.
            var callMain = new InstructionData(vmCommmandType.CALL, null, new string[] { "main.main", argsToPush.Length.ToString() }, "main.main", "main.main");

            handleFunctionCallingCommand(callMain);

            //TODO as part of any VM function we need to push some return value to the stack
            //for now, lets just push the result of main so we can assert our test was successfull.

            Output.AddRange(generateDecrement(stackPointer_symbol, "1", false));
            Output.AddRange(generateMoveAtoTemp());
            Output.Add(assembler.CommandType.LOADAATPOINTER.ToString());
            Output.Add(temp_symbol);
            Output.Add(assembler.CommandType.STOREA.ToString());
            Output.Add(temp_symbol);
            Output.AddRange(this.generatePushToStackFromSymbol(temp_symbol, null));

            var returnFromSysInit = new InstructionData(vmCommmandType.RETURN, null, new string[] { }, "Sys.init", "Sys.init");

            handleFunctionCallingCommand(returnFromSysInit);
        }
Exemple #6
0
        public void EndTurnDone()
        {
            if (!PlayerList[Master].RightFinish)
            {
                return;
            }

            Output.AddRange(Table.Select(p => p.Card1));
            Output.AddRange(Table.Select(p => p.Card2));

            Table.Clear();
            // -- дораздаются карты
            h_GetCards();

            h_CheckGameOver();

            // -- определяются стороны
            Master = Slave;
            Slave  = h_GetNextSide(Master);
            h_SetDefaultRights();
        }
Exemple #7
0
 public override void WriteLine(string value)
 {
     RawString.AppendLine(value);
     Output.AddRange(value.Split(new string[] { NewLine }, StringSplitOptions.None));
 }
Exemple #8
0
        /// <summary>
        /// Generates both training set consisting of feasible and infeasible examples
        /// </summary>
        public void GenerateTrainingData()
        {
            Feasibles = GenerateFeasibleExamples(GlobalVariables.FeasibleExamplesCount);

            // Fill training data
            TrainingData = Feasibles.AddColumnWithValues(1.0);

            // Fill output List
            var tempArr = new double[TrainingData.Count];

            Output.AddRange(tempArr.Select(x => 1));

            _dal.TrainingFeasibleExamples = Feasibles.ToArray();

            GaussianMixtureModel gmm = new GaussianMixtureModel(GlobalVariables.Components);

            gmm = new GaussianMixtureModel(GlobalVariables.Components)
            {
                Initializations = 100,
                MaxIterations   = 10000,
                ParallelOptions = new System.Threading.Tasks.ParallelOptions()
                {
                    MaxDegreeOfParallelism = 1
                },
                Tolerance = 10E-11,
                Options   = new Accord.Statistics.Distributions.Fitting.NormalOptions()
                {
                    Regularization = double.Epsilon
                }
            };

            // Estimate the Gaussian Mixture
            gmm.Learn(_dal.TrainingFeasibleExamples);
            var iterations   = gmm.Iterations;
            var distribution = gmm.ToMixtureDistribution();

            // Get minimal probability of probability density function from distribution (percentile 0)
            var minimalProbability = _dal.TrainingFeasibleExamples
                                     .Select(item => distribution.ProbabilityDensityFunction(item))
                                     .Min();

            // Rescale data range for infeasible example creation
            NewBoundries = BoundryRescaler.Rescale(Feasibles);

            // Generate infeasible examples
            var infeasibles = new List <double[]>();

            while (infeasibles.Count < GlobalVariables.InfeasibleExamplesCount)
            {
                // Generate points within new boundry
                var x = GenerateLimitedInputs(GlobalVariables.Dimensions, NewBoundries);

                // Calculate probability density function value for given input
                var probability = distribution.ProbabilityDensityFunction(x);

                // Check if the value is smaller than smallest probability of all feasible examples
                if (probability > minimalProbability)
                {
                    continue;
                }

                infeasibles.Add(x);

                TrainingData.Add(x.ExtendArrayWithValue(0.0));

                Output.Add(0);
            }

            _dal.TrainingInfeasibleExamples = infeasibles.ToArray();
            _dal.TrainingData = TrainingData.ToArray();
        }
Exemple #9
0
        /// <summary>
        /// En- or decrypt input stream with ChaCha.
        /// </summary>
        /// <param name="key">The secret 128-bit or 256-bit key. A 128-bit key will be expanded into a 256-bit key by concatenation with itself.</param>
        /// <param name="iv">Initialization vector (DJB version: 64-bit, IETF version: 96-bit)</param>
        /// <param name="initialCounter">Initial counter (DJB version: 64-bit, IETF version: 32-bit)</param>
        /// <param name="settings">Chosen Settings in the Plugin workspace. Includes Rounds and Version property.</param>
        /// <param name="input">Input stream</param>
        /// <param name="output">Output stream</param>
        /// <param name="keystreamWriter">Keystream Output stream</param>
        private void Xcrypt(byte[] key, byte[] iv, ulong initialCounter, ChaChaSettings settings, ICryptoolStream input, CStreamWriter output, CStreamWriter keystreamOutput)
        {
            if (!(key.Length == 32 || key.Length == 16))
            {
                throw new ArgumentOutOfRangeException("key", key.Length, "Key must be exactly 128-bit or 256-bit.");
            }
            if (iv.Length != settings.Version.IVBits / 8)
            {
                throw new ArgumentOutOfRangeException("iv", iv.Length, $"IV must be exactly {settings.Version.IVBits}-bit.");
            }
            void AssertCounter(ulong counter, ulong max)
            {
                if (!(0 <= counter && counter <= max))
                {
                    throw new ArgumentOutOfRangeException("initialCounter", counter, $"Initial counter must be between 0 and {max}.");
                }
            }

            if (settings.Version == Version.DJB)
            {
                AssertCounter(initialCounter, ulong.MaxValue);
            }
            else if (settings.Version == Version.IETF)
            {
                AssertCounter(initialCounter, uint.MaxValue);
            }

            // The first 512-bit state. Reused for counter insertion.
            uint[] firstState = State(key, iv, initialCounter, settings.Version);

            // Buffer to read 512-bit input block
            byte[]        inputBytes  = new byte[64];
            CStreamReader inputReader = input.CreateReader();

            // byte size of input
            long inputSize = inputReader.Length;

            // one keystream block is 64 bytes (512 bit)
            TotalKeystreamBlocks = (int)Math.Ceiling((double)(inputSize) / 64);

            ulong blockCounter = initialCounter;
            int   read         = inputReader.Read(inputBytes);

            while (read != 0)
            {
                // Will hold the state during each keystream
                uint[] state = (uint[])firstState.Clone();
                InsertCounter(ref state, blockCounter, settings.Version);
                ChaChaHash(ref state, settings.Rounds);

                byte[] keystream = ByteUtil.ToByteArray(state);
                keystreamOutput.Write(keystream);
                byte[] c = ByteUtil.XOR(keystream, inputBytes, read);
                output.Write(c);

                // Don't add to InputMessage during diffusion run because it won't
                // return a different list during the diffusion run.
                if (!DiffusionExecution)
                {
                    InputMessage.AddRange(inputBytes.Take(read));
                }
                Keystream.AddRange(keystream.Take(read));
                Output.AddRange(c);

                blockCounter++;

                // Read next input block
                read = inputReader.Read(inputBytes);
            }
            inputReader.Dispose();
            output.Flush();
            output.Close();
            output.Dispose();
            keystreamOutput.Flush();
            keystreamOutput.Close();
            keystreamOutput.Dispose();
        }