Esempio n. 1
0
        static void Main(string[] args)
        {
            NumericArray <Rational> numericArray = new NumericArray <Rational>();

            numericArray.Add(new Rational(1, 8));
            numericArray.Add(new Rational(1, 4));
            numericArray.Add(new Rational(1, 2));
            // place for 3/5
            numericArray.Add(new Rational(3, 4));
            numericArray.Add(new Rational(1, 4));
            Console.WriteLine("Numetic Array of Rational: ");
            Console.WriteLine(numericArray);

            Console.WriteLine("Size: " + numericArray.Size());
            Console.WriteLine("Max: " + numericArray.GetMax());
            Console.WriteLine("Min: " + numericArray.GetMin());

            Console.WriteLine("Greater than 3/5 (count): " + numericArray.HowManyIsGreaterThan(new Rational(3, 5)));
            Console.WriteLine("Lesser than 3/5 (count): " + numericArray.HowManyIsLesserThan(new Rational(3, 5)));

            Console.WriteLine("Greater than 1/2 (count): " + numericArray.HowManyIsGreaterThan(new Rational(1, 2)));
            Console.WriteLine("Lesser than 1/2 (count): " + numericArray.HowManyIsLesserThan(new Rational(1, 2)));

            String                  filepath        = "data.txt";
            String                  pattern         = "[0-9]+/[0-9]+";
            RationalFactory         rationalFactory = new RationalFactory();
            NumericArray <Rational> numericArray2   = new NumericArray <Rational>(filepath, pattern, rationalFactory);

            Console.WriteLine();
            Console.WriteLine("NumericArray2, created from file: ");
            Console.WriteLine(numericArray2);

            Polynom <Rational> polynom1 = new Polynom <Rational>(numericArray);
            Polynom <Rational> polynom2 = new Polynom <Rational>(numericArray2);

            Console.WriteLine();
            Console.WriteLine("Polynom1:");
            Console.WriteLine(polynom1);
            Console.WriteLine("Polynom2:");
            Console.WriteLine(polynom2);
            Console.WriteLine("Sum:");
            Console.WriteLine(polynom1 + polynom2);

            Console.WriteLine();
            Console.WriteLine("Trying to operate with rational with zero denominator:");
            try
            {
                Rational r = new Rational("3/0");
                Console.WriteLine(r);
                Console.WriteLine(r.GetDouble());
            } catch (Exception ex)
            {
                Console.WriteLine("Exception catched: " + ex.ToString());
            }
            Console.Read();
        }
Esempio n. 2
0
        protected override void OnEVH()
        {
            switch (step)
            {
            case 1:
                parallism             = encVal.Length;
                scaleBits             = new byte[parallism];
                kip_minus_2_times_kmi = new NumericArray();
                party.receiver.ReceiveFrom(PartyType.KH, line, this, kip_minus_2_times_kmi);
                break;

            case 2:
                var enc_kip_eip = new NumericArray(parallism * Config.KeyBits);
                for (int p = 0; p < parallism; ++p)
                {
                    //System.Diagnostics.Debug.Assert(encVal[p].GetEncType() == EncryptionType.AddMod);
                    scaleBits[p] = encVal[p].GetScaleBits();
                    int offset = p * Config.KeyBits;
                    var emi    = new Numeric[Config.KeyBits];
                    for (int i = 0; i < Config.KeyBits; ++i)
                    {
                        emi[i] = encVal[p].ModPow(i);
                        emi[i].ResetScaleBits();
                        enc_kip_eip[offset + i] = emi[i] + kip_minus_2_times_kmi[offset + i];
                    }
                }
                eci = new NumericArray();
                new LessZeroOnEVH(party, line, this, enc_kip_eip, eci, Config.KeyBits).Run();
                break;

            case 3:
                Numeric[] enc_kf_a = new Numeric[parallism];
                for (int p = 0; p < parallism; ++p)
                {
                    int        offset = p * Config.KeyBits;
                    BigInteger bi     = BigInteger.Zero;
                    for (int i = Config.KeyBits - 1; i >= 0; --i)
                    {
                        bi = (bi << 1) + eci[offset + i].GetUnsignedBigInteger();
                    }
                    enc_kf_a[p] = new Numeric(bi, scaleBits[p]);
                    //System.Diagnostics.Debug.WriteLine("EVH    EncVal: " + encVal[p]);
                    //System.Diagnostics.Debug.WriteLine("EVH CarryBits: " + enckf[p]);
                    enc_kf_a[p] ^= encVal[p];
                    //System.Diagnostics.Debug.WriteLine("EVH   Results: " + enckf[p]);
                    enc_kf_a[p].SetScaleBits(scaleBits[p]);
                    //enckf[p].SetEncType(EncryptionType.XOR);
                }
                result.SetArray(enc_kf_a);
                caller.Run();
                break;

            default:
                throw new Exception();
            }
        }
Esempio n. 3
0
        protected override void OnKH()
        {
            switch (step)
            {
            case 1:
                parallism = key.Length;
                scaleBits = new byte[parallism];
                Numeric[] kip = new Numeric[Config.KeyBits * parallism], kip_minus_2_times_kmi = new Numeric[Config.KeyBits * parallism];
                for (int p = 0; p < parallism; ++p)
                {
                    //System.Diagnostics.Debug.Assert(key[p].GetEncType() == EncryptionType.AddMod);
                    scaleBits[p] = key[p].GetScaleBits();
                    int offset = p * Config.KeyBits;
                    var kmi    = new Numeric[Config.KeyBits];
                    for (int i = 0; i < Config.KeyBits; ++i)
                    {
                        kmi[i] = key[p].ModPow(i);
                        kmi[i].ResetScaleBits();
                        kip[offset + i] = Utility.NextUnsignedNumeric(0);
                        kip_minus_2_times_kmi[offset + i] = kip[offset + i] - kmi[i];
                    }
                }
                var toEVH = Message.AssembleMessage(line, opType, false, kip_minus_2_times_kmi);
                party.sender.SendTo(PartyType.EVH, toEVH);
                kci = new NumericArray();
                new LessZeroOnKH(party, line, this, new NumericArray(kip), kci, Config.KeyBits).Run();
                break;

            case 2:
                Numeric[] kf = new Numeric[parallism];
                for (int p = 0; p < parallism; ++p)
                {
                    int        offset = p * Config.KeyBits;
                    BigInteger bi     = BigInteger.Zero;
                    for (int i = Config.KeyBits - 1; i >= 0; --i)
                    {
                        bi = (bi << 1) + kci[offset + i].GetUnsignedBigInteger();
                    }
                    kf[p] = new Numeric(bi, scaleBits[p]);
                    //System.Diagnostics.Debug.WriteLine("KH        Key: " + key[p]);
                    //System.Diagnostics.Debug.WriteLine("KH  CarryBits: " + kf[p]);
                    kf[p] ^= key[p];
                    //System.Diagnostics.Debug.WriteLine("KH    Results: " + kf[p]);
                    kf[p].SetScaleBits(scaleBits[p]);
                    //kf[p].SetEncType(EncryptionType.XOR);
                }
                result.SetArray(kf);
                caller.Run();
                break;

            default:
                throw new Exception();
            }
        }
        public void ToDelimitedString_WithAllProperties_ReturnsCorrectlySequencedFields()
        {
            IType hl7Type = new NumericArray
            {
                Value1 = 1,
                Value2 = 2,
                Value3 = 3,
                Value4 = 4
            };

            string expected = "1^2^3^4";
            string actual   = hl7Type.ToDelimitedString();

            Assert.Equal(expected, actual);
        }
        public void FromDelimitedString_WithAllProperties_ReturnsCorrectlyInitializedFields()
        {
            IType expected = new NumericArray
            {
                Value1 = 1,
                Value2 = 2,
                Value3 = 3,
                Value4 = 4
            };

            IType actual = new NumericArray();

            actual.FromDelimitedString("1^2^3^4");

            expected.Should().BeEquivalentTo(actual);
        }