0

I have 2 programs using a process to communicate with each other. My program is meant to allow a user to encrypt any password from their history - however it is not allowing me to change the value of what I am trying to encrypt. I understand how the processes communicate, but for some reason changing the value is not working.

My history

 public static int History(LinkedList<String> listy){
        Scanner s = new Scanner(System.in);
        int input;
        String selection;
        System.out.println("--------------------");
        System.out.println("       History      ");
        for(int i = 0; i < listy.size(); i++){
            System.out.println(i + ".) " + listy.get(i));
        }
        System.out.println("Please make a selection: ");
        input = s.nextInt();

        selection = listy.get(input);
        System.out.println("--------------------");
        return input;
    }

Here is my encrypt:

String mode;
        Scanner s = new Scanner(System.in);
        String passkey = "";
        //String answer = "";
        mode = s.next();
        String encryptedMsg = "";

            while(!mode.equals("QUIT")){
                if(mode.equals("PASSKEY")){
                    passkey = s.next();
                    passkey = passkey.toUpperCase();
                    encryptedMsg = encrypt(passkey);
                }
            if(mode.equals("ENCRYPT")){
                System.out.println(encrypt(passkey) + " is the password encrypted");
            }else if(mode.equals("DECRYPT")){
                System.out.println(decrypt(encryptedMsg) + " is the password decrypted");
            }
            mode = s.next();
        }

and here is my call to change the passkey being encrypted:

else if(mode.equals("ENCRYPT")){
                        toLogger.println("ENCRYPT");
                        String thisPasskey;
                        System.out.println("Would you like to see your password history? Enter (Y/N)");
                        mode = s.next();
                        if(mode.equals("Y")){
                            //History(listykenz);
                            System.out.println("Current passkey being encrypted...");
                            //thisPasskey = History(listykenz);
                            int index = History(listykenz);
                            System.out.println(listykenz.get(index));
                            toEncrypt.println(listykenz.get(index));
                            toEncrypt.flush();
                            toEncrypt.println("ENCRYPT");
                            toEncrypt.flush();
                            System.out.println(fromEncrypt.nextLine());
                            toEncrypt.flush();
                            toLogger.flush();
                        }else if(mode.equals("N")) {
                            System.out.println("Current passkey being encrypted...");
                            thisPasskey = listykenz.getLast();
                            System.out.println(thisPasskey);
                            toEncrypt.println(thisPasskey);
                            toEncrypt.println("ENCRYPT");
                            toEncrypt.flush();
                            System.out.println(fromEncrypt.nextLine());
                            toLogger.flush();
                            toEncrypt.flush();
                        }
                        toLogger.flush();
                    }

Thank you

  • 1
    What part of this very long code snippet is "not allowing" you to change the value, and what value (variable) are we talking about exactly? Could you indicate clearly in the code what value is not changing? – markspace Oct 05 '22 at 17:43
  • 1
    *I have 2 programs using a process to communicate with each other.* I think not. What you might have is two independent Java programs using stdin and stdout. You can't communicate like that. The most you could do is pipe output of the one to the stdin of the other *in the same terminal*. That would be a messier and more complex way of performing similar functionality using *one application alone*. Inter-process communication is something specialized and *not* done using Java – g00se Oct 05 '22 at 17:49
  • Just an aside, I believe Java's named pipes implement IPC: https://stackoverflow.com/questions/634564/how-to-open-a-windows-named-pipe-from-java – markspace Oct 05 '22 at 18:09
  • @markspace I am trying to let the user pick which passkey they wanted encrypted. There is a method history that is a linked list full of all of the available passwords. If you try to change which password you want to be encrypted, It keeps returning the same value –  Oct 05 '22 at 19:32
  • Which variable is that? Where is that in the code exactly? – markspace Oct 05 '22 at 19:40
  • history is supposed to output the index of the option that the user selects, and then encrypt is supposed to decrypt the string at that index in the linkedlist, my problem is - once you encrypy one string - it wont let you encryot a different string without restarting the program @markspace –  Oct 05 '22 at 21:47

0 Answers0