public void encrypting() { String plainString; char plainChar; int padInt = 0; char cipherChar; String newS = ""; // while( encrypt.hasNextLine( ) ) // { plainString = encrypt.nextLine(); for (int i = 0; i < plainString.length(); i++) { plainChar = plainString.charAt(i); System.out.print(plainChar); try { padInt = pad.read(); } catch (Exception e) { System.out.println(e.getMessage()); } cipherChar = (char) ((plainChar + padInt) % 128); newS = newS + cipherChar; } // } System.out.println(""); System.out.println("Output (plaintext): "); System.out.println(newS); out.print(newS); out.close(); try { pad.reset(); } catch (Exception e) { System.out.println(e.getMessage()); } }
public void decrypting() { String cipherString; char cipherChar; int padInt = 0; char plainChar; String newS = ""; while (decrypt.hasNextLine()) { cipherString = decrypt.nextLine(); for (int i = 0; i < cipherString.length(); i++) { cipherChar = cipherString.charAt(i); System.out.print(cipherChar); try { padInt = pad.read(); } catch (Exception e) { System.out.println(e.getMessage()); } plainChar = (char) ((cipherChar - padInt + 128) % 128); newS = newS + plainChar; } } System.out.println(""); System.out.println("Output (plaintext): "); System.out.println(newS); try { pad.reset(); } catch (Exception e) { System.out.println(e.getMessage()); } }