Please, help me to find a mistake. I have a class file. I take a byte code of this class and encrypt it by Caesar cipher. I have several arguments of command prompt:
- class file: which we encrypt,
- class file: in which the output will transmit
- key: the number which we add to every number of byte code of the first argument.
I want simply to encrypt the first argument with a zero key, output will transmit to second argument, and then I want to run a second file (second argument).
I compile:
javac Caesar.java
Run:
java Caesar HelloWorld.class Hello1.class 0
(attention - I use zero key, so, file shouldn't be changed)
And run the second file, And I see such mistake:
julia@julia-Aspire-5680 ~/zagruzchik $ java Hello1 Exception in thread "main" java.lang.NoClassDefFoundError: Hello1 (wrong name: HelloWorld) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
My source code:
import java.io.*;
import static java.lang.System.out;
/**
encript by caesar chipher
*/
public class Caesar {
public static void main(String[]args) {
if (args.length == 3)
{
}
else {
System.out.println("USAGE: java Caesar in out key");
return;
}
try ( //class which will be ciphered
FileInputStream in = new FileInputStream(args[0])) {
//in output will go encripted byte code of file
FileOutputStream out = new FileOutputStream(args[1]);
//this is key
int key = Integer.parseInt(args[2]);
int ch;
//in cycle encript byte code
while ((ch = in.read()) != -1) {
byte c = (byte)(ch + key);
out.write(c);
}
}
catch(IOException exception)
{
}
out.close();
}
}