Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.crypto.rainbow.util;

This class is needed for the conversions while encoding and decoding, as well as for comparison between arrays of some dimensions
  
  public class RainbowUtil
  {

    
This function converts an one-dimensional array of bytes into a one-dimensional array of int

Parameters:
in the array to be converted
Returns:
out the one-dimensional int-array that corresponds the input
 
     public static int[] convertArraytoInt(byte[] in)
     {
         int[] out = new int[in.length];
         for (int i = 0; i < in.lengthi++)
         {
             out[i] = in[i] & .;
         }
         return out;
     }

    
This function converts an one-dimensional array of bytes into a one-dimensional array of type short

Parameters:
in the array to be converted
Returns:
out one-dimensional short-array that corresponds the input
 
     public static short[] convertArray(byte[] in)
     {
         short[] out = new short[in.length];
         for (int i = 0; i < in.lengthi++)
         {
             out[i] = (short)(in[i] & .);
         }
         return out;
     }

    
This function converts a matrix of bytes into a matrix of type short

Parameters:
in the matrix to be converted
Returns:
out short-matrix that corresponds the input
 
     public static short[][] convertArray(byte[][] in)
     {
         short[][] out = new short[in.length][in[0].length];
         for (int i = 0; i < in.lengthi++)
         {
             for (int j = 0; j < in[0].lengthj++)
             {
                 out[i][j] = (short)(in[i][j] & .);
             }
         }
         return out;
     }

    
This function converts a 3-dimensional array of bytes into a 3-dimensional array of type short

Parameters:
in the array to be converted
Returns:
out short-array that corresponds the input
 
     public static short[][][] convertArray(byte[][][] in)
     {
         short[][][] out = new short[in.length][in[0].length][in[0][0].length];
         for (int i = 0; i < in.lengthi++)
         {
             for (int j = 0; j < in[0].lengthj++)
             {
                 for (int k = 0; k < in[0][0].lengthk++)
                 {
                     out[i][j][k] = (short)(in[i][j][k] & .);
                 }
             }
         }
         return out;
     }

    
This function converts an array of type int into an array of type byte

Parameters:
in the array to be converted
Returns:
out the byte-array that corresponds the input
 
     public static byte[] convertIntArray(int[] in)
     {
         byte[] out = new byte[in.length];
         for (int i = 0; i < in.lengthi++)
        {
            out[i] = (byte)in[i];
        }
        return out;
    }


    
This function converts an array of type short into an array of type byte

Parameters:
in the array to be converted
Returns:
out the byte-array that corresponds the input
    public static byte[] convertArray(short[] in)
    {
        byte[] out = new byte[in.length];
        for (int i = 0; i < in.lengthi++)
        {
            out[i] = (byte)in[i];
        }
        return out;
    }

    
This function converts a matrix of type short into a matrix of type byte

Parameters:
in the matrix to be converted
Returns:
out the byte-matrix that corresponds the input
    public static byte[][] convertArray(short[][] in)
    {
        byte[][] out = new byte[in.length][in[0].length];
        for (int i = 0; i < in.lengthi++)
        {
            for (int j = 0; j < in[0].lengthj++)
            {
                out[i][j] = (byte)in[i][j];
            }
        }
        return out;
    }

    
This function converts a 3-dimensional array of type short into a 3-dimensional array of type byte

Parameters:
in the array to be converted
Returns:
out the byte-array that corresponds the input
    public static byte[][][] convertArray(short[][][] in)
    {
        byte[][][] out = new byte[in.length][in[0].length][in[0][0].length];
        for (int i = 0; i < in.lengthi++)
        {
            for (int j = 0; j < in[0].lengthj++)
            {
                for (int k = 0; k < in[0][0].lengthk++)
                {
                    out[i][j][k] = (byte)in[i][j][k];
                }
            }
        }
        return out;
    }

    
Compare two short arrays. No null checks are performed.

Parameters:
left the first short array
right the second short array
Returns:
the result of the comparison
    public static boolean equals(short[] leftshort[] right)
    {
        if (left.length != right.length)
        {
            return false;
        }
        boolean result = true;
        for (int i = left.length - 1; i >= 0; i--)
        {
            result &= left[i] == right[i];
        }
        return result;
    }

    
Compare two two-dimensional short arrays. No null checks are performed.

Parameters:
left the first short array
right the second short array
Returns:
the result of the comparison
    public static boolean equals(short[][] leftshort[][] right)
    {
        if (left.length != right.length)
        {
            return false;
        }
        boolean result = true;
        for (int i = left.length - 1; i >= 0; i--)
        {
            result &= equals(left[i], right[i]);
        }
        return result;
    }

    
Compare two three-dimensional short arrays. No null checks are performed.

Parameters:
left the first short array
right the second short array
Returns:
the result of the comparison
    public static boolean equals(short[][][] leftshort[][][] right)
    {
        if (left.length != right.length)
        {
            return false;
        }
        boolean result = true;
        for (int i = left.length - 1; i >= 0; i--)
        {
            result &= equals(left[i], right[i]);
        }
        return result;
    }
New to GrepCode? Check out our FAQ X