RSA implementation using java

后端 未结 4 1278
我在风中等你
我在风中等你 2021-02-06 18:39

I am implementing RSA in java I have encountered a code which is given below it is showing plaintext in numeric form after decrypting the plaintext, but I want it in simple engl

4条回答
  •  一向
    一向 (楼主)
    2021-02-06 18:56

    Instead of this (which only reads the first character):

    int plaintext;
    plaintext = System.in.read();
    bplaintext = BigInteger.valueOf((long) plaintext);
    

    Use this (to read the string):

    byte[] plaintext;
    plaintext = new Scanner(System.in).nextLine().getBytes();
    bplaintext = new BigInteger(plaintext);
    

    Then add this to the end (to convert the decrypted BigInteger back to a string)

    System.out.println("Original String: " + new String(bplaintext.toByteArray()));
    

提交回复
热议问题