Exemple #1
0
 public MainController()
 {
     Generator       = new CFGenerator();
     Provinces       = new List <string>();
     ForeignCounties = new List <string>();
     CurrentProviceMunicipalities = new List <string>();
 }
Exemple #2
0
        public void CheckDigitTest()
        {
            Person p = new Person
            {
                Name         = "Andrea Luciano",
                Surname      = "Damico",
                DateOfBirth  = new DateTime(1990, 5, 3),
                PlaceOfBirth = new ItalianMunicipality("BRONTE", "B202"),
                Gender       = 'M'
            };
            CFGenerator gen = new CFGenerator(p);

            gen.GenerateFiscalCode();
            Assert.AreEqual(gen.CheckDigit, 'A');
        }
Exemple #3
0
        public void CodiceTest()
        {
            Person p = new Person
            {
                Name         = "Gianfranco",
                Surname      = "Damico",
                DateOfBirth  = new DateTime(1955, 12, 4),
                Gender       = 'M',
                PlaceOfBirth = new ItalianMunicipality("BRONTE", "B202")
            };
            CFGenerator gen = new CFGenerator(p);

            gen.GenerateFiscalCode();
            Assert.AreEqual("DMCGFR55T04B202I", gen.FiscalCode);
        }
Exemple #4
0
        public void DateAndGenderTest()
        {
            Person p = new Person
            {
                Name         = "Andrea Luciano",
                Surname      = "Damico",
                DateOfBirth  = new DateTime(1990, 5, 3),
                Gender       = 'M',
                PlaceOfBirth = new ItalianMunicipality("BRONTE", "B202")
            };
            CFGenerator gen = new CFGenerator(p);

            gen.GenerateFiscalCode();
            Assert.AreEqual("DMCNRL90E03B202A", gen.FiscalCode);
        }
Exemple #5
0
        public static void DoInstructions(Chunk chunk, List <Instruction> instructions)
        {
            instructions = instructions.ToList();

            CFGenerator generator = new CFGenerator();
            Random      r         = new Random();

            for (int idx = instructions.Count - 1; idx >= 0; idx--)
            {
                Instruction i = instructions[idx];
                switch (i.OpCode)
                {
                case Opcode.Lt:
                case Opcode.Le:
                case Opcode.Eq:
                {
                    if (r.Next(2) == 1)
                    {
                        i.A = i.A == 0 ? 1 : 0;
                        Instruction nJmp = generator.NextJMP(chunk, instructions[idx + 2]);
                        chunk.Instructions.Insert(chunk.InstructionMap[i] + 1, nJmp);
                    }

                    break;
                }

                case Opcode.Test:
                {
                    if (r.Next(2) == 1)
                    {
                        i.C = i.C == 0 ? 1 : 0;
                        Instruction nJmp = generator.NextJMP(chunk, instructions[idx + 2]);
                        chunk.Instructions.Insert(chunk.InstructionMap[i] + 1, nJmp);
                    }

                    break;
                }
                }
            }

            chunk.UpdateMappings();
        }
Exemple #6
0
        private void btnVerifica_Click(object sender, EventArgs e)
        {
            if (!CheckTextBox())
            {
                return;
            }
            string s = txtCF.Text.ToUpper();
            var    c = CFGenerator.CalculateCheckDigit(s.Substring(0, 15));

            if (c != s.Last())
            {
                epConvalida.SetError(txtCF, "Codice fiscale non valido.");
                MessageBox.Show("Il codice fiscale inserito non è valido", "Controllo non superato", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                epConvalida.SetError(txtCF, "");
                MessageBox.Show("Il codice fiscale inserito è valido", "Controllo superato", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemple #7
0
        public static void DoInstructions(Chunk chunk, List <Instruction> Instructions)
        {
            Instructions = Instructions.ToList();
            CFGenerator cg = new CFGenerator();
            Random      r  = new Random();

            for (int i = Instructions.Count - 1; i >= 0; i--)
            {
                used.Clear();
                Instruction instr = Instructions[i];

                List <Instruction> newInstructions = new List <Instruction>();

                switch (instr.OpCode)
                {
                case Opcode.Eq:
                case Opcode.Lt:
                case Opcode.Le:
                {
                    Instruction[] AddTVGroup(Instruction test)
                    {
                        Instruction cmp1, cmp2;

                        {
                            cmp1 = new Instruction(test);
                            Instruction target = chunk.Instructions[chunk.InstructionMap[test] + 1];

                            Instruction jmpCorrect = cg.NextJMP(chunk, (Instruction)target.RefOperands[0]);
                            Instruction jmpJunk    = cg.NextJMP(chunk, Instructions[r.Next(0, i - 2)]);

                            target.RefOperands[0] = cmp1;
                            chunk.Instructions.AddRange(new[] { cmp1, jmpCorrect, jmpJunk });
                        }

                        {
                            cmp2 = new Instruction(test);

                            Instruction target = chunk.Instructions[chunk.InstructionMap[test] + 2];

                            Instruction jmpCorrect = cg.NextJMP(chunk, target);
                            Instruction jmpJunk    = cg.NextJMP(chunk, Instructions[r.Next(0, i - 2)]);
                            Instruction jmpStart   = cg.NextJMP(chunk, cmp2);

                            chunk.Instructions.Insert(chunk.InstructionMap[target], jmpStart);
                            chunk.Instructions.AddRange(new[] { cmp2, jmpJunk, jmpCorrect });
                        }

                        chunk.UpdateMappings();
                        return(new[] { cmp1, cmp2 });
                    }

                    List <Instruction> tv1 = AddTVGroup(instr).ToList();
                    for (int j = 0; j < 3; j++)
                    {
                        List <Instruction> tv2 = new List <Instruction>();
                        foreach (Instruction ins in tv1)
                        {
                            tv2.AddRange(AddTVGroup(ins));
                        }
                        tv1 = tv2;
                    }
                    break;
                }

                case Opcode.Test:
                case Opcode.TestSet:
                {
                    Instruction[] AddTVGroup(Instruction test)
                    {
                        Instruction test1, test2;

                        {
                            test1 = new Instruction(test);

                            Instruction target = chunk.Instructions[chunk.InstructionMap[test] + 1];

                            Instruction jmpCorrect = cg.NextJMP(chunk, (Instruction)target.RefOperands[0]);
                            Instruction jmpJunk    = cg.NextJMP(chunk, Instructions[r.Next(0, i - 2)]);

                            target.RefOperands[0] = test1;
                            chunk.Instructions.AddRange(new[] { test1, jmpCorrect, jmpJunk });
                        }

                        {
                            test2 = new Instruction(test);

                            Instruction target = chunk.Instructions[chunk.InstructionMap[test] + 2];

                            Instruction jmpCorrect = cg.NextJMP(chunk, target);
                            Instruction jmpJunk    = cg.NextJMP(chunk, Instructions[r.Next(0, i - 2)]);
                            Instruction jmpStart   = cg.NextJMP(chunk, test2);

                            chunk.Instructions.Insert(chunk.InstructionMap[target], jmpStart);
                            chunk.Instructions.AddRange(new[] { test2, jmpJunk, jmpCorrect });
                        }

                        chunk.UpdateMappings();
                        return(new[] { test1, test2 });
                    }

                    List <Instruction> tv1 = AddTVGroup(instr).ToList();
                    for (int j = 0; j < 3; j++)
                    {
                        int x = tv1.Count;
                        for (var index = 0; index < x; index++)
                        {
                            Instruction ins = tv1[index];
                            tv1.AddRange(AddTVGroup(ins));
                        }
                    }
                    break;
                }
                }
            }
            chunk.UpdateMappings();
        }