1

I have a java text file named "text_in.txt" which contains

IDESOFMARCH

which is 11 characters in length, how do I go about finding the length of this file and appending an 'X' character to the end of H so that the text may be broken up into blocks of 2 characters each to be used for RSA encryption/decryption.

Example: ID ES OF MA RC HX

I have a main() which calls the encrypt method from my rsa.java file (files, private, public keys)

code.encrypt(files, 17, 2773);

files contains "text_in.txt" and "text_out.txt" and a boolean true which opens both files.

The main is calling this:

public void encrypt(FileInOut files, int e, int n) {



//Get the in file length and add a 'X' if uneven character blocks
    if((files.length() % 2) == 1)
      files.write("X");

//Print a 0 in the encrypted file to represent the end of a line
    if(files != char)
      files.write("0");
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
KrakenJaws
  • 155
  • 12
  • 1
    Why not use valid cryptographic padding instead? Much more reliable than doing it yourself. – connorp Sep 15 '15 at 03:20
  • possible duplicate of [Best way to read a text file in Java?](http://stackoverflow.com/questions/4716503/best-way-to-read-a-text-file-in-java) – Artjom B. Sep 15 '15 at 09:32

1 Answers1

1

Well borrowing an answer from Reading a plain text file in Java

String str = new String(Files.readAllBytes(Paths.get("text_in.txt")));
int len = str.length();
Community
  • 1
  • 1
WillShackleford
  • 6,918
  • 2
  • 17
  • 33