public static byte[] encode(byte[] source){

    //the length of the original array
    int len = source.length;
    //the offset. Where conversion should start
    int off = 0;
    //specified options
    int options = 0;

    //determine the length for the target array
    int newLen = len * 4 / 3;
    //System.out.println("newLen: " + newLen);
    //determine if the length of the original array is module 3
    int padding = 0;
    if ( (len % 3) == 1){
      //System.out.println("len % 3 is 1");
      padding = 3;
    }
    if ( (len % 3) == 2){
      //System.out.println("len % 3 is 2");
      padding = 2;
    }

    //System.out.println("padding: " + padding);
    //determine the number of break lines to be added
    int breaks = newLen / 76;
    //System.out.println("breaks: " + breaks);
    //determine the real size for the encoded array
    int finalSize = newLen + padding + breaks;
    //System.out.println("finalSize: " + finalSize);
    //the encoded array
    byte[] encodedArray = new byte[finalSize];

    //to keep track of the position in the original array of bytes
    int i = 0;
    //to keep track of the position in the new array of bytes (encoded array)
    int j = 0;
    //this variable is to avoid going out of the limits of the array when
    //the number of bytes is not module of 3
    //this is taken care in the "if" statement after the "for" statement
    int len2 = len - 2;
    int lineLength = 0;

    //increments d by 3 (because the algorithm takes 3 bytes to be coneverted), and
    //increments e by 4 (because the 3 bytes are represented using 4 bytes in base64)
    //the "for" loop goes through the original array taking 3 bytes at a time, and
    //converting them into 4 bytes into the encoded array. It takes care of the break lines
    for(i=0; i < len2; i+=3, j+=4){
      //encode from the "source" array, starting in the position "i" the next "3" bytes,
      //and write the encoded bytes to the "encodedArray" starting in the position "j"
      encode3Bytes(source, i, 3, encodedArray, j);
      //increments by 4 because we have added 4 bytes
      lineLength += 4;
      //if the line has reached the 76 characters, then add '\n'
      if(lineLength == MAX_LINE_LENGTH ){
        encodedArray[j+4] = NEW_LINE_CHAR;
        //increments e by 1 because of the new line character, and reset lineLength
        j++;
        lineLength = 0;
      }// end if: lineLength = 76
    }// end for

    //If the array has more elements, it will be necessary to add
    //some padding characters (it can have 1 or 2 more elements)
    if( i < len ){
      //encode from the "source" array, starting in the position "i" the next "len-i" bytes,
      //and write the encoded bytes to the "encodedArray" starting in the position "j"
      //As this is he last sentence, the number of bytes to be encoded can be 1 or 2
      encode3Bytes(source, i, len - i, encodedArray, j);
      j += 4;
    }// end if

    return encodedArray;

  }//encode