Exemplo n.º 1
0
        public async Task <ActionResult <string> > Post(AK ak)
        {
            BigInteger a;
            uint       k;

            try
            {
                if (ak.a == null || ak.k == null)
                {
                    throw new FormatException();
                }
                a = BitOperation.BinStrToBigInteger(ak.a);
                k = Convert.ToUInt32(ak.k, 10);

                if (k > 31 || ak.a.Length > 32)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                ModelState.AddModelError("Error", "Некорректные параметры");
                return(BadRequest(ModelState));
            }

            return(await Task.Run(() => BitOperation.BigIntegerToBinStr(BitOperation.GetBit(a, k))));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <string> > Post(AIJ aij)
        {
            BigInteger a;
            uint       i, j;

            try
            {
                if (aij.a == null || aij.i == null || aij.j == null)
                {
                    throw new FormatException();
                }

                a = BitOperation.BinStrToBigInteger(aij.a);
                i = Convert.ToUInt32(aij.i, 10);
                j = Convert.ToUInt32(aij.j, 10);

                if (i > 31 || j > 31 || aij.a.Length > 32)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                ModelState.AddModelError("Error", "Некорректные параметры");
                return(BadRequest(ModelState));
            }

            return(await Task.Run(() => BitOperation.BigIntegerToBinStr(BitOperation.SwapBit(a, i, j))));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <string> > Post(AIL ail)
        {
            BigInteger a;
            uint       i, l;

            try
            {
                if (ail.a == null || ail.i == null || ail.l == null)
                {
                    throw new FormatException();
                }
                a = BitOperation.BinStrToBigInteger(ail.a);
                i = Convert.ToUInt32(ail.i, 10);
                l = Convert.ToUInt32(ail.l, 10);

                if (i > l)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                ModelState.AddModelError("Error", "Некорректные параметры");
                return(BadRequest(ModelState));
            }

            return(await Task.Run(() => BitOperation.BigIntegerToBinStr(BitOperation.GlueBits(a, i, l))));
        }
Exemplo n.º 4
0
        public async Task <ActionResult <string> > Post(AM am)
        {
            BigInteger a;
            uint       m;

            try
            {
                if (am.a == null || am.m == null)
                {
                    throw new FormatException();
                }

                a = BitOperation.BinStrToBigInteger(am.a);
                m = Convert.ToUInt32(am.m, 10);

                if (m > 32 || am.a.Length > 32)
                {
                    throw new FormatException();
                }
            }
            catch (FormatException)
            {
                ModelState.AddModelError("Error", "Некорректные параметры");
                return(BadRequest(ModelState));
            }

            return(await Task.Run(() => BitOperation.BigIntegerToBinStr(BitOperation.ZeroSmallBits(a, m))));
        }
Exemplo n.º 5
0
        public async Task <ActionResult <string> > Post(APN apn)
        {
            BigInteger a;
            uint       p, n;

            try
            {
                if (apn.a == null || apn.p == null || apn.n == null)
                {
                    throw new FormatException();
                }

                a = BitOperation.BinStrToBigInteger(apn.a);
                p = Convert.ToUInt32(apn.p, 10);
                n = Convert.ToUInt32(apn.n, 10);
            }
            catch (FormatException)
            {
                ModelState.AddModelError("Error", "Некорректные параметры");
                return(BadRequest(ModelState));
            }

            return(await Task.Run(() => BitOperation.BigIntegerToBinStr(BitOperation.CycleShiftRight(a, p, n))));
        }