private byte[] encrypt(byte[] m,NTRUEncryptionPublicKeyParameters pubKey){
  IntegerPolynomial pub=pubKey.h;
  int N=params.N;
  int q=params.q;
  int maxLenBytes=params.maxMsgLenBytes;
  int db=params.db;
  int bufferLenBits=params.bufferLenBits;
  int dm0=params.dm0;
  int pkLen=params.pkLen;
  int minCallsMask=params.minCallsMask;
  boolean hashSeed=params.hashSeed;
  byte[] oid=params.oid;
  int l=m.length;
  if (maxLenBytes > 255) {
    throw new IllegalArgumentException("llen values bigger than 1 are not supported");
  }
  if (l > maxLenBytes) {
    throw new DataLengthException("Message too long: " + l + ">"+ maxLenBytes);
  }
  while (true) {
    byte[] b=new byte[db / 8];
    random.nextBytes(b);
    byte[] p0=new byte[maxLenBytes + 1 - l];
    byte[] M=new byte[bufferLenBits / 8];
    System.arraycopy(b,0,M,0,b.length);
    M[b.length]=(byte)l;
    System.arraycopy(m,0,M,b.length + 1,m.length);
    System.arraycopy(p0,0,M,b.length + 1 + m.length,p0.length);
    IntegerPolynomial mTrin=IntegerPolynomial.fromBinary3Sves(M,N);
    byte[] bh=pub.toBinary(q);
    byte[] hTrunc=copyOf(bh,pkLen / 8);
    byte[] sData=buildSData(oid,m,l,b,hTrunc);
    Polynomial r=generateBlindingPoly(sData,M);
    IntegerPolynomial R=r.mult(pub,q);
    IntegerPolynomial R4=(IntegerPolynomial)R.clone();
    R4.modPositive(4);
    byte[] oR4=R4.toBinary(4);
    IntegerPolynomial mask=MGF(oR4,N,minCallsMask,hashSeed);
    mTrin.add(mask);
    mTrin.mod3();
    if (mTrin.count(-1) < dm0) {
      continue;
    }
    if (mTrin.count(0) < dm0) {
      continue;
    }
    if (mTrin.count(1) < dm0) {
      continue;
    }
    R.add(mTrin,q);
    R.ensurePositive(q);
    return R.toBinary(q);
  }
}

private byte [ ] encrypt ( byte [ ] m , NTRUEncryptionPublicKeyParameters pubKey ) { IntegerPolynomial pub = pubKey . h ; int N = params . N ; int q = params . q ; int maxLenBytes = params . maxMsgLenBytes ; int db = params . db ; int bufferLenBits = params . bufferLenBits ; int dm0 = params . dm0 ; int pkLen = params . pkLen ; int minCallsMask = params . minCallsMask ; boolean hashSeed = params . hashSeed ; byte [ ] oid = params . oid ; int l = m . length ; if ( maxLenBytes > 255 ) { throw new IllegalArgumentException ( "llen values bigger than 1 are not supported" ) ; } if ( l > maxLenBytes ) { throw new DataLengthException ( "Message too long: " + l + ">" + maxLenBytes ) ; } while ( true ) { byte [ ] b = new byte [ db / 8 ] ; random . nextBytes ( b ) ; byte [ ] p0 = new byte [ maxLenBytes + 1 - l ] ; byte [ ] M = new byte [ bufferLenBits / 8 ] ; System . arraycopy ( b , 0 , M , 0 , b . length ) ; M [ b . length ] = ( byte ) l ; System . arraycopy ( m , 0 , M , b . length + 1 , m . length ) ; System . arraycopy ( p0 , 0 , M , b . length + 1 + m . length , p0 . length ) ; IntegerPolynomial mTrin = IntegerPolynomial . fromBinary3Sves ( M , N ) ; byte [ ] bh = pub . toBinary ( q ) ; byte [ ] hTrunc = copyOf ( bh , pkLen / 8 ) ; byte [ ] sData = buildSData ( oid , m , l , b , hTrunc ) ; Polynomial r = generateBlindingPoly ( sData , M ) ; IntegerPolynomial R = r . mult ( pub , q ) ; IntegerPolynomial R4 = ( IntegerPolynomial ) R . clone ( ) ; R4 . modPositive ( 4 ) ; byte [ ] oR4 = R4 . toBinary ( 4 ) ; IntegerPolynomial mask = MGF ( oR4 , N , minCallsMask , hashSeed ) ; mTrin . add ( mask ) ; mTrin . mod3 ( ) ; if ( mTrin . count ( - 1 ) < dm0 ) { continue ; } if ( mTrin . count ( 0 ) < dm0 ) { continue ; } if ( mTrin . count ( 1 ) < dm0 ) { continue ; } R . add ( mTrin , q ) ; R . ensurePositive ( q ) ; return R . toBinary ( q ) ; } }
encrypts a message . < br / > see p1363 . 1 section 9 . 2 . 2 .
