-4

I am trying to run a java code for a Vigenere cipher.

When running the code I get an error for file not found. The code is:

Vignere.java

package vigeneregui;

import java.util.Scanner;

/**
 * @author AnupamGenius
 */
public class Vigenere {
    private String EnDekey;

    public Vigenere(String key) {
        setKey(key);
    }

    public void setKey(String key) {
        if (key == null) {
            this.EnDekey = "";
            return;
        }

        char[] digit = key.toUpperCase().toCharArray();
        StringBuilder sb = new StringBuilder(digit.length);

        for (char c : digit) {
            if (c >= 'A' && c <= 'Z') sb.append(c);
        }

        this.EnDekey = sb.toString();
    }

    /**
     * Encode a message according to the key already registered
     */
    public String Encrypt(String clear) {
        // ignore if null
        if (clear == null)
            return "";
        // ignore if key length == 0
        if (EnDekey.length() == 0)
            return clear.toUpperCase();

        char[] String_digits = clear.toLowerCase().toCharArray(); // build a string with the repeated key at least the size of our message
        String Key_Long = EnDekey;

        while (Key_Long.length() < clear.length())
            Key_Long += EnDekey;

        for (int i = 0; i < String_digits.length; i++) {
            if (String_digits[i] < 'a' || String_digits[i] > 'z')
               continue;

            char offset = Key_Long.charAt(i);
            int nbShift = offset - 'A';
            String_digits[i] = Character

Error

C:\Users\Student\Documents\Security Exercise 1>"C:\Program Files\Java\jdk-12.0.2\bin"\javac E1Code1.java
error:file not found: E1Code.java

E1Code is in the Security Exercise 1 directory.

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
Pythos
  • 3
  • 3
  • 2
    Better re-format the code section to make it readable. – user1783732 Sep 11 '19 at 18:29
  • Of course `javac E1Code1.java` is going to fail if there is no file named `E1Code1.java` in the current directory. That is not a Java problem; the command `type E1Code1.java` would fail for the same reason. – VGR Sep 11 '19 at 18:42
  • Possible duplicate of [How to run a .class file that is part of a package from cmd?](https://stackoverflow.com/questions/18139756/how-to-run-a-class-file-that-is-part-of-a-package-from-cmd) – Mr. Polywhirl Sep 11 '19 at 19:07
  • Try running... `javac vigeneregui\Vigenere` since it is inside a package and make sure that `Vigenere.java` exists in the `C:\Users\Student\Documents\Security Exercise\vigeneregui` directory. You should be able to run it via: `java vigeneregui.Vigenere` – Mr. Polywhirl Sep 11 '19 at 19:09

1 Answers1

-2

Please the location of the directory you are in. The file may not be present from the current directory where you are running javac command

Dhrumil Panchal
  • 406
  • 5
  • 11