I need to implement a decrypt method in c++ from a Java encrypted string passed to me from a server. The Java encrypted method is this:
 public String crypt (String strMsg)throws CryptUtilException{
    byte bytePosition;
    int intMsgLen = strMsg.length();
    int intKeyLen = strKey.length();
    byte[] aByteMsg = strMsg.getBytes();
    byte[] aByteOutMsg = new byte[intMsgLen];
    if (intMsgLen==0) {
        throw new CryptUtilException("In String is null.");
    } else{
        for (int i=0; i<intMsgLen; i++) {
            bytePosition = (byte) (i%intKeyLen);
            aByteOutMsg[i] = (byte)((aByteMsg[i] - iCharOffSet) + (byte) strKey.charAt(bytePosition) + bytePosition);
            if (aByteOutMsg [i] < 0) aByteOutMsg [i] = (byte) (aByteOutMsg [i] + 128);
        }
        String strOutMsg = new String (aByteOutMsg);
        return strOutMsg;
    }
}
My work colleague use that code for encrypt and the following code for decrypt a string and suggest my to replicate this Java code into my C++ project:
public String decrypt (String strMsg)throws CryptUtilException{
    byte bytePosition;
    int intMsgLen = strMsg.length();
    int intKeyLen = strKey.length();
    byte[] aByteMsg = strMsg.getBytes();
    byte[] aByteOutMsg = new byte[intMsgLen];
    if (intMsgLen==0) {
        throw new CryptUtilException("In String is null.");
    } else{
        for (int i=0; i<intMsgLen; i++) {
            bytePosition = (byte) (i%intKeyLen);
            aByteOutMsg[i] = (byte)((aByteMsg[i] + iCharOffSet) - (byte) strKey.charAt(bytePosition) - bytePosition);
            if (aByteOutMsg [i] < 0) aByteOutMsg [i] = (byte) (aByteOutMsg [i] + 128);
        }
        String strOutMsg = new String (aByteOutMsg);
        return strOutMsg;
    }
}
I have a lot of difficulty doing it because I don't find a valid method for replicate the Java getBytes() method. In addition, I have a very old version of C++ and for this I can't use the "byte" or the "wstring_convert" method and I'm not working on windows OS.