I have this part of my code:
int[] myIntArray = {0x2e80,0x008c,0x0993,0x09c5,0x058b,0x4c9c,0x0390,0x1e96,0x0989,0x0ac4,0x4cad,0x0d93,0x09c5,0x0a84,0x0591,0x04c5,0x058b,0x4c9c,0x0390,0x1ec5,0x0d87,0x0589,0x0591,0x0580,0x1fc4,0x4cb2,0x0591,0x048a,0x1991,0x4c84,0x4c8d,0x1988,0x0e89,0x09c5,0x0e90,0x18c5,0x1e80,0x0d96,0x038b,0x0d87,0x0080,0x4c86,0x038b,0x0a8c,0x0880,0x0286,0x09c5,0x058b,0x4c9c,0x0390,0x1ec5,0x0392,0x02c5,0x1c8a,0x1b80,0x1e96,0x4c9c,0x0390,0x4c86,0x0d8b,0x028a,0x18c5,0x0e80,0x4c96,0x1986,0x0f80,0x1f96,0x0a90,0x00c5,0x0397,0x4c8d,0x0d95,0x1c9c,0x42e5};
for (int i=0; i<=73; i++){
String s1=Decrypt(k,myIntArray[i]);
String s2= s1.substring(2,6);
String s=convertHexToString(s2);
System.out.print(s);
}
That takes hex values from the array and do some operations on it. And its working just fine as i want.
I want to do the same thing but i want to read the values from a file and do the same operations on it, i tried this :
String token1 = "";
Scanner inFile1 = new Scanner(new File("chipertext.txt")).useDelimiter(",\\s*");
List<String> temps = new ArrayList<String>();
while (inFile1.hasNext()) {
token1 = inFile1.next();
temps.add(token1);
}
inFile1.close();
String[] tempsArray = temps.toArray(new String[74]);
int[] myIntArray = new int[tempsArray.length];
for (int i = 0; i < tempsArray.length; i++) {
myIntArray[i] = Integer.parseInt(tempsArray[i]);
}
for (int i=0; i<=73; i++){
String s1=Decrypt(k,myIntArray[i]);
String s2= s1.substring(2,6);
String s=convertHexToString(s2);
System.out.print(s);
}
But i get this error :
Exception in thread "main" java.lang.NumberFormatException: For input string: "0x2e80 0x2e80
0x008c
0x0993
0x09c5
0x058b
0x4c9c
0x0390
0x1e96
0x0989
0x0ac4
0x4cad
0x0d93
0x09c5
0x0a84
0x0591
0x04c5
0x058b
0x4c9c
0x0390
0x1ec5
0x0d87
0x0589
0x0591
0x0580"
the values stored in the file like this :
0x2e80
0x008c
0x0993
0x09c5
0x058b
0x4c9c
0x0390
0x1e96
0x0989
0x0ac4
0x4cad
0x0d93
0x09c5
0x0a84
0x0591
0x04c5
0x058b
0x4c9c
0x0390
0x1ec5
0x0d87
0x0589
0x0591
0x0580
I think this means that that string cant be stored as integer right? then how to do it ? and how it was stored in integer array before ?! i don't know can someone please help me?
WORKING CODE
String token1 = "";
Scanner inFile1 = new Scanner(new File("chipertext.txt"));
List<String> temps = new ArrayList<String>();
while (inFile1.hasNext()) {
token1 = inFile1.next();
temps.add(token1);
}
inFile1.close();
String[] tempsArray = temps.toArray(new String[73]);
int[] myIntArray = new int[tempsArray.length];
for (int i = 0; i < tempsArray.length; i++) {
myIntArray[i] = Integer.parseInt(tempsArray[i].substring(2), 16);
}
for (int i=0; i<=73; i++){
String s1=Decrypt(k,myIntArray[i]);
String s2= s1.substring(2,6);
String s=convertHexToString(s2);
System.out.print(s);
}
Thank you all for the help !!!