how to convert unicode to readable word

i have done encryption in arduino and pass to java using serial communication coding.I used aes rxtx libraries to communicate between arduino and java. Right now,the encryption show the

output : ŠÉ“RãL^Ï?™M²0Œå

As far as I know, i think it is unicode. how I want to convert it into readable word ?

mport java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import gnu.io.CommPortIdentifier; 
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent; 
import gnu.io.SerialPortEventListener; 
import java.util.Enumeration;




public class SerialTest implements SerialPortEventListener {
    SerialPort serialPort;
        /** The port we're normally going to use. */
    private static final String PORT_NAMES[] = { 
            "/dev/tty.usbserial-A9007UX1", // Mac OS X
                        "/dev/ttyACM0", // Raspberry Pi
            "/dev/ttyUSB0", // Linux
            "COM22", // Windows
    };
    /**
    * A BufferedReader which will be fed by a InputStreamReader 
    * converting the bytes into characters 
    * making the displayed results codepage independent
    */
    private BufferedReader input;
    /** The output stream to the port */
    private OutputStream output;
    /** Milliseconds to block while waiting for port open */
    private static final int TIME_OUT = 2000;
    /** Default bits per second for COM port. */
    private static final int DATA_RATE = 9600;

    public void initialize() {
                // the next line is for Raspberry Pi and 
                // gets us into the while loop and was suggested here was suggested http://www.raspberrypi.org/phpBB3/viewtopic.php?f=81&t=32186
                //System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM0");

        CommPortIdentifier portId = null;
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();

        //First, Find an instance of serial port as set in PORT_NAMES.
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            for (String portName : PORT_NAMES) {
                if (currPortId.getName().equals(portName)) {
                    portId = currPortId;
                    break;
                }
            }
        }
        if (portId == null) {
            System.out.println("Could not find COM port.");
            return;
        }

        try {
            // open serial port, and use class name for the appName.
            serialPort = (SerialPort) portId.open(this.getClass().getName(),
                    TIME_OUT);

            // set port parameters
            serialPort.setSerialPortParams(DATA_RATE,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);

            // open the streams
            input = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
            output = serialPort.getOutputStream();

            // add event listeners
            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

    /**
     * This should be called when you stop using the port.
     * This will prevent port locking on platforms like Linux.
     */
    public synchronized void close() {
        if (serialPort != null) {
            serialPort.removeEventListener();
            serialPort.close();
        }
    }

    /**
     * Handle an event on the serial port. Read the data and print it.
     */
    public synchronized void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            try {
                String inputLine=input.readLine();
                System.out.println(inputLine);



            } catch (Exception e) {
                System.err.println(e.toString());
            }
        }
        // Ignore all the other eventTypes, but you should consider the other ones.
    }

    public static void main(String[] args) throws Exception {
        SerialTest main = new SerialTest();
        main.initialize();
        Thread t=new Thread() {
            public void run() {
                //the following line will keep this app alive for 1000 seconds,
                //waiting for events to occur and responding to them (printing incoming messages to console).
                try {Thread.sleep(10);} catch (InterruptedException ie) {}
            }
        };
        t.start();
        System.out.println("Started");


    }

Above is coding read the serial from java.

what's the code on the arduino side? is the arduino sending the info? is it sending it in unicode??

Is the data rate in your serial monitor set to the same as in the Serial.begin()?

Just asking

The arduino send encrypted data and it in unicode. In arduino i use AESlib and somehow the data sending in unicode. I already clueless and i dont know how to convert it to readble word. Can someone help me?

what's your source code for the encryption?

if you are using this library, have you taken notice of

At the moment only 128bit keys are supported, the blocksize is also fixed at 128bit. This means that the key array and possible iv array should contain exactly 16 bytes (uint8_t or byte). Moreover the amount of bytes to encrypt should be mod 16. (this means you have to take care of padding yourself).

I am using that library and what is the possible way to handle the padding?

Show us your arduino side... We can work from there

Encryption does usually result in binary data (and not in text of whatever form (ascii, unicode, ...)).

So I wonder what you're trying to achieve?

this is the encryption coding in arduino.

#include <hidboot.h>
#include <usbhub.h>
#include <SPI.h>
#include <AESLib.h>  
#include <Base64.h>
#include"Keyboard.h"
 
void aes128_enc_single(const uint8_t* key,void* data);

class KbdRptParser : public KeyboardReportParser
{
  
  protected:
    
    void OnKeyDown  (uint8_t mod, uint8_t key);
    void OnKeyPressed(uint8_t key);
};

void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
 
  uint8_t c = OemToAscii(mod, key);

  if (c)
    OnKeyPressed(c);
}


void KbdRptParser::OnKeyPressed(uint8_t key)
{


      //Converting an int or String to a char array on Arduino
    
      char data[16]; //16 chars == 16 bytes
      String dat1;
      dat1=String(key);
     
      dat1.toCharArray(data,16);
     
      uint8_t keys[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
     
      //encrypted code 
      aes128_enc_single(keys,data);
     
     //Encrypted data 
      Serial.println("encrypted: ");
      Serial.println(data);
};

  USB     Usb;
  //USBHub     Hub(&Usb);
  HIDBoot<USB_HID_PROTOCOL_KEYBOARD>    HidKeyboard(&Usb);


KbdRptParser Prs;



void setup()
{
  Serial.begin( 9600);

  Keyboard.begin();

#if !defined(__MIPSEL__)
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
  Serial.println("Start");

  if (Usb.Init() == -1)
    Serial.println("OSC did not start.");

  HidKeyboard.SetReportParser(0, &Prs);
  
}

void loop()
{

  Usb.Task();
}

So you are using a keyboard connected to your arduino and an HID

each time a character key is pressed on that keyboard, you call OnKeyDown which looks at which modifier key is pressed (like shift) and which character and it returns an extended ASCII character on 8 bits which you store in the uint8_t variable c

then you call the OnKeyPressed() and pass the variable c and there you do something pretty “stupid” (no judgement value, just that it is really useless):

you allocate an array data of 16 chars
you create a String object in which you put your c character (so just 1 byte)
then you ask that String object to give you back that character in character format and put it into your buffer.

So basically what you did is a convoluted and memory intensive way of doing

data[0] = c;
for (int i=1; i<15;i++) data[i] = '\0'; // which gives you the padding to 16 bytes

then you encrypt this 1 byte long text string with aes128_enc_single() and print out the encrypted data and a new line, which your java code reads from the Serial Input and prints exactly as it read it…

So basically your Java code spits out the encrypted char for each press of a key…

So why are you wondering you are reading gibberish on the output of your program?

okay, can the gibberish data converts into something more readable? I already confused right now. since i need to make it readable using Java.

I think you are asking for how to convert raw byte vector into ASCII hex string?

how to do it? i have no idea

You can use

Serial.print(somebyte, HEX); Serial.print(" ");

Which will send a byte in hex representation followed by a space (so you can see the different bytes). It will however be better to do it at the java side (simply read the received bytes and display as HEX values) and that is outside the scope of the forum.

Google is your friend; java byte to hex

You are sending encoded data - you probably need to decode it before presenting it - don't you??