Example #1
0
        public static byte[] StripPadding(byte[] input, PaddingType paddingtype, int blocksize)
        {
            int validBytes = StripPadding(input, input.Length, paddingtype, blocksize);

            byte[] buf = new byte[validBytes];
            Array.Copy(input, buf, validBytes);
            return(buf);
        }
Example #2
0
 public void GetPadding(PaddingType paddingOut)
 {
     Interop.Actor.GetPadding(SwigCPtr, PaddingType.getCPtr(paddingOut));
     if (NDalicPINVOKE.SWIGPendingException.Pending)
     {
         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #3
0
 private int _getOverlayToRemove(int overlayNumber, PaddingType paddingType, int x, int y)
 {
     if (_fieldMapNumber == 312 && paddingType == PaddingType.Down &&
         overlayNumber == 2 && x < 17 && y == 12)
     {
         return(5);
     }
     return(-1);
 }
Example #4
0
        public void Conv2D(Tensor kernels, int stride, PaddingType padding, Tensor result)
        {
            Debug.Assert(Depth == kernels.Depth);

            int outputWidth = 0, outputHeight = 0, paddingX = 0, paddingY = 0;

            GetPaddingParams(padding, Width, Height, kernels.Width, kernels.Height, stride, out outputHeight, out outputWidth, out paddingX, out paddingY);

            Op.Conv2D(this, kernels, stride, paddingX, paddingY, result);
        }
Example #5
0
 public Padding(Tile originalTile, Overlay originalOverlay, List <Overlay> overlayList, PaddingCoords paddingCoords,
                PaddingCoords paddingCoordsSelf, PaddingType paddingType)
 {
     _originalTile          = originalTile;
     _originalOverlay       = originalOverlay;
     _overlayList           = overlayList;
     this.paddingCoords     = paddingCoords;
     this.paddingCoordsSelf = paddingCoordsSelf;
     this.type = paddingType;
 }
Example #6
0
        public Tensor Conv2D(Tensor kernels, int stride, PaddingType padding)
        {
            int outputWidth = 0, outputHeight = 0, paddingX = 0, paddingY = 0;

            GetPaddingParams(padding, Width, Height, kernels.Width, kernels.Height, stride, out outputHeight, out outputWidth, out paddingX, out paddingY);

            Tensor result = new Tensor(new Shape(outputWidth, outputHeight, kernels.BatchSize, BatchSize));

            Conv2D(kernels, stride, padding, result);
            return(result);
        }
Example #7
0
        public void Pool(int filterSize, int stride, PoolType type, PaddingType padding, Tensor result)
        {
            int outWidth = 0, outHeight = 0, paddingX = 0, paddingY = 0;

            GetPaddingParams(padding, Width, Height, filterSize, filterSize, stride, out outHeight, out outWidth, out paddingX, out paddingY);

            Debug.Assert(result.Width == outWidth);
            Debug.Assert(result.Height == outHeight);
            Debug.Assert(result.BatchSize == BatchSize);

            Op.Pool(this, filterSize, stride, type, paddingX, paddingY, result);
        }
Example #8
0
        public Tensor Pool(int filterSize, int stride, PoolType type, PaddingType padding)
        {
            int outWidth = 0, outHeight = 0, paddingX = 0, paddingY = 0;

            GetPaddingParams(padding, Width, Height, filterSize, filterSize, stride, out outHeight, out outWidth, out paddingX, out paddingY);

            Tensor result = new Tensor(new Shape(outWidth, outHeight, Depth, BatchSize));

            Pool(filterSize, stride, type, padding, result);

            return(result);
        }
Example #9
0
        public void PaddingTypeConstructorWithParameters()
        {
            tlog.Debug(tag, $"PaddingTypeConstructorWithParameters START");

            var testingTarget = new PaddingType(0.0f, 0.0f, 0.0f, 0.0f);

            Assert.IsNotNull(testingTarget, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget, "Should be an instance of PaddingType type.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PaddingTypeConstructorWithParameters END (OK)");
        }
Example #10
0
        public void PaddingTypeGetHashCode()
        {
            tlog.Debug(tag, $"PaddingTypeGetHashCode START");

            var testingTarget = new PaddingType();

            Assert.IsNotNull(testingTarget, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget, "Should be an instance of PaddingType type.");

            Assert.GreaterOrEqual(testingTarget.GetHashCode(), 0, "Should be true");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PaddingTypeGetHashCode END (OK)");
        }
		public void AddDataElement(string fieldValue, int length, PaddingType paddingType, char paddingChar) {

			string newString = fieldValue;

			while (newString.Length < length && paddingType != PaddingType.NoPadding) {
				if (paddingType == PaddingType.PadLeft) {
					newString = paddingChar + newString;
				} else {
					newString = newString + paddingChar;
				}
			}

			_dataElements.Add(StringUtils.Left(newString, length));
		}
Example #12
0
        public void PaddingTypeStart()
        {
            tlog.Debug(tag, $"PaddingTypeStart START");

            var testingTarget = new PaddingType();

            Assert.IsNotNull(testingTarget, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget, "Should be an instance of PaddingType type.");

            testingTarget.Start = 20.0f;
            Assert.AreEqual(20.0f, testingTarget.Start, "Should be equal!");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PaddingTypeStart END (OK)");
        }
Example #13
0
 /// <summary>
 /// Converts a value into a byte array using the specified data format
 /// and returns the number of bytes written.
 /// </summary>
 /// <exception cref="SerializationException">
 /// Thrown if the type is not serializable.
 /// </exception>
 public static int Write <T>(T obj, FileFormat fmt, out byte[] data,
                             bool bigEndian      = false,
                             PaddingType padding = PaddingType.Default, byte[] paddingBytes = null)
 {
     using (DataBuffer stream = new DataBuffer()
     {
         BigEndian = bigEndian,
         PaddingType = padding,
         PaddingBytes = paddingBytes
     })
     {
         int bytesWritten = stream.GenericWrite(obj, fmt);
         data = stream.GetBuffer();
         return(bytesWritten);
     }
 }
Example #14
0
        public void PaddingTypeSet()
        {
            tlog.Debug(tag, $"PaddingTypeSet START");

            var testingTarget = new PaddingType();

            Assert.IsNotNull(testingTarget, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget, "Should be an instance of PaddingType type.");

            testingTarget.Set(0.0f, 0.0f, 20.0f, 30.0f);
            Assert.AreEqual(testingTarget.Start, 0.0f, "should be equal.");
            Assert.AreEqual(testingTarget.End, 0.0f, "should be equal.");
            Assert.AreEqual(testingTarget.Top, 20.0f, "should be equal.");
            Assert.AreEqual(testingTarget.Bottom, 30.0f, "should be equal.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"PaddingTypeSet END (OK)");
        }
Example #15
0
 public ConvolutionConfig(int[][] matrix, int offset, int factor, PaddingType type)
 {
     this.matrix = matrix;
     if (matrix != null)
     {
         width  = matrix[0].Length;
         height = matrix.Length;
     }
     else
     {
         width = height = 0;
     }
     this.offset      = offset;
     this.factor      = factor;
     this.paddingType = type;
     yRadius          = (int)Math.Floor(height / 2.0);
     xRadius          = (int)Math.Floor(width / 2.0);
 }
Example #16
0
 public Conv3D(int filters, Tuple <int, int, int> kernalSize, int strides = 1, PaddingType padding = PaddingType.Same, Tuple <int, int, int> dialationRate = null,
               ActType activation = ActType.Linear, BaseInitializer kernalInitializer = null, BaseRegularizer kernalRegularizer = null,
               BaseConstraint kernalConstraint = null, bool useBias = true, BaseInitializer biasInitializer = null, BaseRegularizer biasRegularizer = null, BaseConstraint biasConstraint = null)
     : base("conv3d")
 {
     Filters           = filters;
     KernalSize        = kernalSize;
     Strides           = strides;
     Padding           = padding;
     DialationRate     = dialationRate ?? Tuple.Create(1, 1, 1);
     Act               = activation;
     UseBias           = useBias;
     KernalInitializer = kernalInitializer ?? new GlorotUniform();
     BiasInitializer   = biasInitializer ?? new Zeros();
     KernalConstraint  = kernalConstraint;
     BiasConstraint    = biasConstraint;
     KernalRegularizer = kernalRegularizer;
     BiasRegularizer   = biasRegularizer;
 }
        /// <summary>
        ///     Add padding to the string.
        /// </summary>
        /// <param name="str">
        ///     The string.
        /// </param>
        /// <param name="paddingType">
        ///     The type of padding to add.
        /// </param>
        /// <returns>
        ///     The padded string.
        /// </returns>
        public static string WithPadding(this string str, PaddingType paddingType)
        {
            if (str == null)
            {
                return(null);
            }

            if (paddingType == PaddingType.Leading)
            {
                return(" " + str);
            }

            if (paddingType == PaddingType.Trailing)
            {
                return(str + " ");
            }

            return(str);
        }
Example #18
0
 public Conv1D(uint filters, uint kernalSize, uint strides = 1, PaddingType padding = PaddingType.Same, uint dilationRate = 1,
               ActivationType activation       = ActivationType.Linear, BaseInitializer kernalInitializer = null, BaseRegularizer kernalRegularizer = null,
               BaseConstraint kernalConstraint = null, bool useBias = true, BaseInitializer biasInitializer = null, BaseRegularizer biasRegularizer = null,
               BaseConstraint biasConstraint   = null)
     : base("conv1d")
 {
     Filters           = filters;
     KernalSize        = kernalSize;
     Strides           = strides;
     Padding           = padding;
     DilationRate      = dilationRate;
     Activation        = activation;
     UseBias           = useBias;
     KernalInitializer = kernalInitializer ?? new GlorotUniform();
     BiasInitializer   = biasInitializer ?? new Zeros();
     KernalConstraint  = kernalConstraint;
     BiasConstraint    = biasConstraint;
     KernalRegularizer = kernalRegularizer;
     BiasRegularizer   = biasRegularizer;
 }
Example #19
0
        public void Equals_CHECK_RETURN_VALUE()
        {
            tlog.Debug(tag, $"PaddingTypeDispose START");

            var testingTarget1 = new PaddingType(0.0f, 0.0f, 20.0f, 30.0f);

            Assert.IsNotNull(testingTarget1, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget1, "Should be an instance of PaddingType type.");

            var testingTarget2 = new PaddingType(0.0f, 0.0f, 20.0f, 30.0f);

            Assert.IsNotNull(testingTarget2, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget2, "Should be an instance of PaddingType type.");

            var testingTarget3 = new PaddingType(10.0f, 0.0f, 20.0f, 30.0f);

            Assert.IsNotNull(testingTarget3, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget3, "Should be an instance of PaddingType type.");

            bool flagTrue = testingTarget1.Equals(testingTarget2);

            Assert.IsTrue(flagTrue, "Should be true!");

            bool flagFalse = testingTarget1.Equals(testingTarget3);

            Assert.IsFalse(flagFalse, "Should be false!");

            // object is null
            Assert.IsFalse(testingTarget1.Equals(null));

            // object is not a PaddingType
            using (Size size = new Size(100, 200))
            {
                Assert.IsFalse(testingTarget1.Equals(size));
            }

            testingTarget1.Dispose();
            testingTarget2.Dispose();
            testingTarget3.Dispose();
            tlog.Debug(tag, $"PaddingTypeDispose END (OK)");
        }
Example #20
0
        public void PaddingTypeDispose()
        {
            tlog.Debug(tag, $"PaddingTypeDispose START");

            var testingTarget = new PaddingType();

            Assert.IsNotNull(testingTarget, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget, "Should be an instance of PaddingType type.");

            try
            {
                testingTarget.Dispose();
            }
            catch (Exception e)
            {
                tlog.Error(tag, "Caught Exception" + e.ToString());
                LogUtils.Write(LogUtils.DEBUG, LogUtils.TAG, "Caught Exception" + e.ToString());
                Assert.Fail("Caught Exception" + e.ToString());
            }

            tlog.Debug(tag, $"PaddingTypeDispose END (OK)");
        }
Example #21
0
 public Conv2D(int filters,
               int[] kernel_size                       = null,
               int[] strides                           = null,
               PaddingType padding                     = PaddingType.Valid,
               DataFormatType?data_format              = null,
               int[] dilation_rate                     = null,
               IActivationFunction activation          = null,
               bool use_bias                           = true,
               IWeightInitializer kernel_initializer   = null,
               IWeightInitializer bias_initializer     = null,
               IWeightRegularizer kernel_regularizer   = null,
               IWeightRegularizer bias_regularizer     = null,
               IWeightRegularizer activity_regularizer = null,
               IWeightConstraint kernel_constraint     = null,
               IWeightConstraint bias_constraint       = null,
               int?[] input_shape                      = null)
     : base(rank: 2,
            filters: filters,
            kernel_size: kernel_size,
            strides: strides,
            padding: padding,
            data_format: data_format,
            dilation_rate: dilation_rate,
            activation: activation,
            use_bias: use_bias,
            kernel_initializer: kernel_initializer,
            bias_initializer: bias_initializer,
            kernel_regularizer: kernel_regularizer,
            bias_regularizer: bias_regularizer,
            activity_regularizer: activity_regularizer,
            kernel_constraint: kernel_constraint,
            bias_constraint: bias_constraint,
            input_shape: input_shape)
 {
     this.input_spec = new List <InputSpec> {
         new InputSpec(ndim: 4)
     };
 }
Example #22
0
        public void PaddingTypeEquality()
        {
            tlog.Debug(tag, $"PaddingTypeEquality START");

            var testingTarget1 = new PaddingType(0.0f, 0.0f, 20.0f, 30.0f);

            Assert.IsNotNull(testingTarget1, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget1, "Should be an instance of PaddingType type.");

            var testingTarget2 = new PaddingType(0.0f, 0.0f, 20.0f, 30.0f);

            Assert.IsNotNull(testingTarget2, "Can't create success object PaddingType");
            Assert.IsInstanceOf <PaddingType>(testingTarget2, "Should be an instance of PaddingType type.");

            bool flag = false;

            if (testingTarget1 == testingTarget2)
            {
                flag = true;
            }
            Assert.IsTrue(flag, "Should be true!");

            // If both are null
            PaddingType testingTarget3 = null;
            PaddingType testingTarget4 = null;

            Assert.IsTrue(testingTarget3 == testingTarget4);

            // If one is null, but not both
            PaddingType testingTarget5 = null;

            Assert.IsFalse(testingTarget5 == testingTarget1);

            testingTarget1.Dispose();
            testingTarget2.Dispose();
            tlog.Debug(tag, $"PaddingTypeEquality END (OK)");
        }
        public void Padding(PaddingType mode, byte[] seq)
        {
            byte[] data;
            using (DataBuffer wb = new DataBuffer()
            {
                PaddingType = mode, PaddingBytes = seq
            })
            {
                wb.Pad(100);
                data = wb.GetBuffer();
                Assert.True(data.Length > 0);
            }

            switch (mode)
            {
            case PaddingType.Zero:
            {
                Assert.Equal(0, data.Sum(x => x));
                break;
            }

            case PaddingType.Random:
            {
                Assert.NotEqual(0, data.Sum(x => x));
                break;
            }

            case PaddingType.Pattern:
            {
                for (int i = 0; i < data.Length; i++)
                {
                    Assert.Equal(seq[i % seq.Length], data[i]);
                }
                break;
            }
            }
        }
Example #24
0
 internal static void GetPaddingParams(PaddingType type, int width, int height, int kernelWidth, int kernelHeight, int stride, out int outHeight, out int outWidth, out int paddingX, out int paddingY)
 {
     if (type == PaddingType.Valid)
     {
         outWidth  = (int)Math.Floor((width - kernelWidth) / (float)stride + 1);
         outHeight = (int)Math.Floor((height - kernelHeight) / (float)stride + 1);
         paddingX  = 0;
         paddingY  = 0;
     }
     else if (type == PaddingType.Same)
     {
         outWidth  = width / stride;
         outHeight = height / stride;
         paddingX  = (int)Math.Floor((float)kernelWidth / 2);
         paddingY  = (int)Math.Floor((float)kernelHeight / 2);
     }
     else //if (type == ConvType.Full)
     {
         outWidth  = (width + (kernelWidth - 1)) / stride;
         outHeight = (height + (kernelHeight - 1)) / stride;
         paddingX  = kernelWidth - 1;
         paddingY  = kernelHeight - 1;
     }
 }
Example #25
0
        /// <summary>
        ///     Does the location represent a place where an attribute can be created or replaced by a completion?
        /// </summary>
        /// <param name="location">
        ///     The XML location.
        /// </param>
        /// <param name="element">
        ///     The element whose attribute will be completed.
        /// </param>
        /// <param name="replaceAttribute">
        ///     The attribute (if any) that will be replaced by the completion.
        /// </param>
        /// <param name="needsPadding">
        ///     An <see cref="PaddingType"/> value indicating what sort of padding (if any) is required before / after the attribute.
        /// </param>
        /// <param name="onElementWithPath">
        ///     If specified, the location's element must have the specified path.
        /// </param>
        /// <returns>
        ///     <c>true</c>, if the location represents an element that can be replaced by completion; otherwise, <c>false</c>.
        /// </returns>
        public static bool CanCompleteAttribute(this XmlLocation location, out XSElement element, out XSAttribute replaceAttribute, out PaddingType needsPadding, XSPath onElementWithPath = null)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            replaceAttribute = null;
            needsPadding     = PaddingType.None;

            XSAttribute attribute;

            if (location.IsAttribute(out attribute) && !location.IsValue())
            {
                element = attribute.Element;
                if (location.Position == attribute.Start)
                {
                    // Since we're on an existing attribute, we'll add a new attribute after it.
                    attribute    = null;
                    needsPadding = PaddingType.Trailing;
                }
            }
            else if (location.IsElementBetweenAttributes(out element))
            {
                if (element.Attributes.Count > 0)
                {
                    // Check if we're directly before an attribute.
                    foreach (XSAttribute currentAttribute in element.Attributes)
                    {
                        if (location.Position == currentAttribute.End)
                        {
                            needsPadding = PaddingType.Leading;
                        }
                        else
                        {
                            continue;
                        }

                        break;
                    }
                }
                else if (location.Position == element.NameRange.End) // We're directly after the name.
                {
                    needsPadding = PaddingType.Leading;
                }
            }
            else if (location.IsElement(out element))
            {
                // Check if we're directly after the name.
                if (location.Position != element.NameRange.End)
                {
                    return(false);
                }

                needsPadding = PaddingType.Leading;
            }
            else
            {
                return(false);
            }

            if (onElementWithPath != null && !element.Path.Matches(onElementWithPath))
            {
                return(false);
            }

            replaceAttribute = attribute;

            return(true);
        }
		public void AddDataElement(double fieldValue, int length, int numDecimalPlaces, PaddingType paddingType, char paddingChar) {
			AddDataElement(fieldValue.ToString("F" + numDecimalPlaces), length, paddingType, paddingChar);
		}
Example #27
0
        /// <summary>
        /// Encrypts/Decrypts using OFB
        /// </summary>
        /// <param name="blockCipher"></param>
        /// <param name="cipherAction"></param>
        /// <param name="inputStream"></param>
        /// <param name="outputStream"></param>
        /// <param name="key"></param>
        /// <param name="iv"></param>
        /// <param name="padding"></param>
        /// <param name="stop"></param>
        /// <param name="progressChanged"></param>
        /// <param name="lastInputBlock"></param>
        /// <param name="blocksize"></param>
        public static void ExecuteOFB(BlockCipher blockCipher,
                                      CipherAction cipherAction,
                                      ref ICrypToolStream inputStream,
                                      ref ICrypToolStream outputStream,
                                      byte[] key,
                                      byte[] iv,
                                      PaddingType padding,
                                      ref bool stop,
                                      ProgressChanged progressChanged,
                                      ref byte[] lastInputBlock,
                                      int blocksize = 8)
        {
            using (CStreamReader reader = inputStream.CreateReader())
            {
                using (CStreamWriter writer = new CStreamWriter())
                {
                    byte[] lastBlock = iv;
                    int    readcount = 0;

                    while (reader.Position < reader.Length && !stop)
                    {
                        //we always try to read a complete block
                        byte[] inputBlock = new byte[blocksize];
                        readcount = 0;
                        while ((readcount += reader.Read(inputBlock, readcount, blocksize - readcount)) < blocksize &&
                               reader.Position < reader.Length && !stop)
                        {
                            ;
                        }
                        if (stop)
                        {
                            return;
                        }

                        //Show progress in UI
                        progressChanged(reader.Position, reader.Length);

                        byte[] outputblock = null;
                        //we read a complete block
                        if (readcount == blocksize)
                        {
                            //Compute XOR with lastblock for OFB mode
                            if (cipherAction == CipherAction.Encrypt)
                            {
                                outputblock = blockCipher(lastBlock, key);
                                lastBlock   = outputblock;
                                outputblock = XOR(outputblock, inputBlock);
                            }
                            else
                            {
                                outputblock = blockCipher(lastBlock, key);
                                lastBlock   = outputblock;
                                outputblock = XOR(outputblock, inputBlock);
                            }
                        }
                        //we read an incomplete block, thus, we are at the end of the stream
                        else if (readcount > 0)
                        {
                            //Compute XOR with lastblock for CFB mode
                            if (cipherAction == CipherAction.Encrypt)
                            {
                                byte[] block = new byte[blocksize];
                                Array.Copy(inputBlock, 0, block, 0, readcount);
                                outputblock = blockCipher(lastBlock, key);
                                outputblock = XOR(outputblock, block);
                            }
                            else
                            {
                                byte[] block = new byte[blocksize];
                                Array.Copy(inputBlock, 0, block, 0, readcount);
                                outputblock = blockCipher(inputBlock, key);
                                outputblock = XOR(outputblock, lastBlock);
                            }
                        }

                        //check if it is the last block and we decrypt, thus, we have to remove the padding
                        if (reader.Position == reader.Length && cipherAction == CipherAction.Decrypt && padding != PaddingType.None)
                        {
                            int valid = StripPadding(outputblock, blocksize, padding, blocksize);
                            if (valid != blocksize)
                            {
                                byte[] newoutputblock = new byte[valid];
                                Array.Copy(outputblock, 0, newoutputblock, 0, valid);
                                outputblock = newoutputblock;
                            }
                            else if (valid == 0)
                            {
                                outputblock = null;
                            }
                        }

                        //if we crypted something, we output it
                        if (outputblock != null)
                        {
                            writer.Write(outputblock, 0, outputblock.Length);
                            //if we wrote to the stream, we memorize the last input block for the visualization
                            lastInputBlock = inputBlock;
                        }
                    }

                    writer.Flush();
                    outputStream = writer;
                }
            }
        }
		public void AddDataElement(int fieldValue, int length, PaddingType paddingType, char paddingChar) {
			AddDataElement("" + fieldValue, length, paddingType, paddingChar);
		}
        public void CanCompleteAttribute(string testFileName, int line, int column, string expectedElementName, PaddingType expectedPadding)
        {
            Position testPosition = new Position(line, column);

            string            testXml   = LoadTestFile("TestFiles", testFileName + ".xml");
            TextPositions     positions = new TextPositions(testXml);
            XmlDocumentSyntax document  = Parser.ParseText(testXml);

            XmlLocator  locator  = new XmlLocator(document, positions);
            XmlLocation location = locator.Inspect(testPosition);

            Assert.NotNull(location);

            XSPath elementPath = XSPath.Parse(expectedElementName);

            XSElement   element;
            XSAttribute replaceAttribute;
            PaddingType needsPadding;

            Assert.True(
                location.CanCompleteAttribute(out element, out replaceAttribute, out needsPadding, onElementWithPath: elementPath),
                "CanCompleteAttribute"
                );
            Assert.NotNull(element);
            Assert.Null(replaceAttribute);
            Assert.Equal(expectedPadding, needsPadding);
        }
Example #30
0
 public MaxPooling3D(Tuple <uint, uint, uint> poolSize = null, uint strides = 1, PaddingType padding = PaddingType.Same)
     : base("maxpooling3d")
 {
     PoolSize = poolSize ?? Tuple.Create <uint, uint, uint>(2, 2, 2);
     Strides  = strides;
     Padding  = padding;
 }
Example #31
0
 /// <summary>
 /// Specifies the padding properties for a padding field.
 /// </summary>
 /// <param name="type">Type of padding the field represents.</param>
 /// <param name="length">Length of the padding field.</param>
 public PaddingAttribute(PaddingType type, int length)
 {
     // Initialize fields.
     this.Type   = type;
     this.Length = length;
 }
Example #32
0
 public static ICrypToolStream AppendPadding(ICrypToolStream input, PaddingType paddingtype, int blocksize)
 {
     return(new CStreamWriter(AppendPadding(StreamToByteArray(input), paddingtype, blocksize)));
 }
Example #33
0
        public static byte[] AppendPadding(byte[] input, PaddingType paddingtype, int blocksize)
        {
            long l = blocksize - (input.Length % blocksize);

            if (paddingtype == PaddingType.None)
            {
                if (l % blocksize != 0)
                {
                    throw new Exception("Input must be a multiple of blocksize (" + blocksize + " bytes) if no padding is used.");
                }
                return(input);
            }
            else if (paddingtype == PaddingType.Zeros)
            {
                l %= blocksize; // add no zeros if message length is multiple of blocksize
            }

            byte[] buf = new byte[input.Length + l];
            Array.Copy(input, buf, input.Length);

            switch (paddingtype)
            {
            case PaddingType.Zeros:
                for (int i = 0; i < l; i++)
                {
                    buf[input.Length + i] = 0x00;
                }
                break;

            case PaddingType.OneZeros:
                buf[input.Length] = 0x01;
                for (int i = 1; i < l; i++)
                {
                    buf[input.Length + i] = 0x00;
                }
                break;

            case PaddingType.PKCS7:
                for (int i = 0; i < l; i++)
                {
                    buf[input.Length + i] = (byte)l;
                }
                break;

            case PaddingType.ISO10126:
                Random random = new Random();
                for (int i = 0; i < l; i++)
                {
                    buf[input.Length + i] = (byte)random.Next(256);
                }
                buf[buf.Length - 1] = (byte)l;
                break;

            case PaddingType.ANSIX923:
                for (int i = 0; i < l; i++)
                {
                    buf[input.Length + i] = 0;
                }
                buf[buf.Length - 1] = (byte)l;
                break;
            }

            return(buf);
        }