Page 1 of 1
Need help from a Java-Programmer
Posted: Sat Dec 15, 2012 9:11 pm
by infratec
Hi together,
I have a small problem:
I need the result of a small piece of java code.
I have no knowledge of java, so my tries with an online compiler failed.
Here is the codesnippet:
Code: Select all
private Static Key b()
{
String str = "7c[@D9ùdR4i7/u&9Maxt";
StringBuilder localStringBuilder = new StringBuilder();
For (int i = 0; i < "4v131M17m19Q10M1555".length(); i++)
If (!Character.isLetter("4v131M17m19Q10M1555".charAt(i)))
{
localStringBuilder.append(str.charAt(Integer.parseInt("4v131M17m19Q10M1555".charAt(i))));
}
Else
{
int j = Integer.parseInt("4v131M17m19Q10M1555".substring(i + 1, i + 3));
localStringBuilder.append(str.charAt(Integer.parseInt(j)));
i += 2;
}
Return new SecretKeySpec(localStringBuilder.toString().getBytes(), "RC4");
}
I reprogrammed it with PB, but I'm not sure if the values are right.
I need the 'localStringBuilder.String' and the Return value to verify my PB version.
Than you very much in advance,
Bernd
Re: Need help from a Java-Programmer
Posted: Sat Dec 15, 2012 9:42 pm
by infratec
Here is my 'java' code:
Code: Select all
import javax.swing.*;
import java.io.*;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.spec.SecretKeySpec;
class Test
{
public static void main(String args[])
{
String str;
try{
FileInputStream fstream = new FileInputStream("test.cfg");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
str = br.readLine();
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
StringBuilder localStringBuilder = new StringBuilder();
for (int i = 0; i < "4v131M17m19Q10M1555".length(); i++)
if (!Character.isLetter("4v131M17m19Q10M1555".charAt(i)))
{
localStringBuilder.append(str.charAt(Integer.parseInt("4v131M17m19Q10M1555".charAt(i))));
}
else
{
int j = Integer.parseInt("4v131M17m19Q10M1555".substring(i + 1, i + 3));
localStringBuilder.append(str.charAt(Integer.parseInt(j)));
i += 2;
}
System.out.println( new SecretKeySpec(localStringBuilder.toString().getBytes(), "RC4"));
}
}
But it gives an error:
cannot find symbol
symbol : method parseInt(char)
I put the string in a file, because the java compiler don't want some of the used characters.
Oh, I tried it with JDK 1.6
Bernd
Re: Need help from a Java-Programmer
Posted: Sat Dec 15, 2012 9:50 pm
by Arctic Fox
Hi Bernd!
With the following piece of Java code I get this result with Java 7:
Code: Select all
Ducati999
[68, 117, 99, 97, 116, 105, 57, 57, 57]
Code: Select all
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.util.Arrays;
public class Main
{
public static void main(String[] args)
{
System.out.println(Arrays.toString(b().getEncoded()));
}
private static Key b()
{
String str = "7c[@D9ùdR4i7/u&9Maxt";
StringBuilder localStringBuilder = new StringBuilder();
for (int i = 0; i < "4v131M17m19Q10M1555".length(); i++)
{
if (!Character.isLetter("4v131M17m19Q10M1555".charAt(i)))
{
localStringBuilder.append(str.charAt(Integer.parseInt(String.valueOf("4v131M17m19Q10M1555".charAt(i)))));
}
else
{
int j = Integer.parseInt("4v131M17m19Q10M1555".substring(i + 1, i + 3));
localStringBuilder.append(str.charAt(Integer.parseInt(String.valueOf(j))));
i += 2;
}
}
System.out.println(localStringBuilder.toString());
return new SecretKeySpec(localStringBuilder.toString().getBytes(), "RC4");
}
}
Re: Need help from a Java-Programmer
Posted: Sat Dec 15, 2012 10:16 pm
by infratec
Hi Arctic Fox,
thanks a lot
In the mean time I got somthing similar with:
Code: Select all
import javax.swing.*;
import java.io.*;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.spec.SecretKeySpec;
public class test
{
public static void main(String args[])
{
String str = "";
try{
FileInputStream fstream = new FileInputStream("test.cfg");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
str = br.readLine();
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
System.out.println(str);
String str2 = "4v131M17m19Q10M1555";
StringBuilder localStringBuilder = new StringBuilder();
for (int i = 0; i < str2.length(); i++)
{
System.out.println(i);
if (!Character.isLetter(str2.charAt(i)))
{
localStringBuilder.append(str.charAt(Integer.parseInt(str2.substring(i, i + 1))));
}
else
{
int j = Integer.parseInt(str2.substring(i + 1, i + 3));
localStringBuilder.append(str.charAt(j));
i += 2;
}
}
System.out.println(localStringBuilder.toString());
System.out.println( new SecretKeySpec(localStringBuilder.toString().getBytes(), "RC4"));
}
}
Ducati999
is shown too.
Only the 'Key' is not shown.
Btw. I used the online compiler at
http://www.innovation.ch/java/java_compile.html
I hope I can now check my PB solution.
Thanks again,
Bernd