//Determine the padding length
padding += ((cipherlen -
((msgdata.length + 5 + padding) % cipherlen)) % cipherlen);
// Write the packet length field
message.writeInt(msgdata.length + 1 + padding);
// Write the padding length
message.write(padding);
// Write the message payload