简体   繁体   中英

getting a String sequence from an ascii sequence in java

I'm trying to create a java project for the RSA cryptography, but I have a problem in converting a long ASCII sequence to a String sequence, for the last part for getting the plainText in cryptography.

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    String hj = w2.getText();
    String longue;
    BigInteger rg, tfd;
    String gh = "";
    String e = "", rtyu = "", hjk = "";
    longue = String.valueOf(h);
    int kl = longue.length();
    int jh = hj.length();
    int nb = jh / (kl);
    int gc = jh - (kl) * nb;
    for (int uy = 0; uy < nb; uy++) {
        rg = new BigInteger(hj.substring((uy * (kl)), ((uy + 1) * ((kl)))));
        tfd = new BigInteger(String.valueOf(rg.modPow(des, h)));

        e+= String.valueOf(tfd);
    }
    jTextArea1.setText(e);
    byte[] byt;
    byt = e.getBytes();

... }

I want to know what I can do after that for converting ae to its value in characters?

Example: I want to convert this ASCII sequence 656667 to characters for getting the value "ABC",

Assuming the input is well-formed, this java 8 solution will work for you:

String unconverted = "656667";

String converted = IntStream.range(0, unconverted.length() / 2)
    .map(i -> Integer.parseInt(unconverted.substring(i * 2, (i * 2) + 2)))
    .collect(
        StringBuilder::new,
        StringBuilder::appendCodePoint,
        StringBuilder::append)
    .toString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM