SRL Archive - Senior News and General

Steal RSBot's Thunder?


Smartzkid

2011-02-03 19:20:31

Right now, RSBot is down. Imagine how many people are out there looking for a bot. Now consider how convenient it would be to have the ability to click a button and have RSBot account details instantly saved for SRL scripts to use.

Discuss.

If anyone's interested, here's some hacked together java code that can read RSBot account files (and derivatives, likely). To use it, run it in the command line or pipe it to a text file.


[php]import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.TreeMap;

public class main {

private static final String[] VALID_KEYS = { "password", "pin", "reward", "member", "take_breaks" };

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

String key;
try
{
InetAddress localInetAddress = InetAddress.getLocalHost();
NetworkInterface localNetworkInterface = NetworkInterface.getByInetAddress(localInetAddress);
key = new String(localNetworkInterface.getHardwareAddress());
} catch (Exception localException) {
key = System.getProperty("user.name") + System.getProperty("user.language");
}
Map<String, Map<String,String>> accounts = loadAccounts(key);
String output = accounts.toString();
output = output.replaceAll("}, ", "\n");
output = output.replace('{', ' ');
output = output.substring(1, output.length() - 2);

System.out.println(output);
}

public static String getAccountsFile()
{
String str;
String str1 = System.getProperty("os.name");
if (str1.contains("Windows"))
str = new StringBuilder().append(System.getenv("APPDATA")).append(File.separator).append("RSBot").append("_Accounts.ini").toString();
else
str = new StringBuilder().append(getUnixHome()).append(File.separator).append(".").append("RSBot".toLowerCase()).append("acct").toString();

return str;
}

public static String getUnixHome() {
String str = System.getProperty("user.home");
return str == null ? "~" : str;
}

private static Map<String, Map<String, String>> loadAccounts(String key)
{
TreeMap localTreeMap = new TreeMap();
Object localObject = null;

File localFile = new File(getAccountsFile());
if (localFile.exists()) {
try {
BufferedReader localBufferedReader = new BufferedReader(new FileReader(localFile));

String str2 = "";
String str1;
while ((str1 = localBufferedReader.readLine()) != null) {
if ((str1.startsWith("[")) && (str1.endsWith("]"))) {
if (!str2.isEmpty()) {
localTreeMap.put(fixName(str2), localObject);
}
str2 = str1.trim().substring(1).substring(0, str1.length() - 2);
localObject = new TreeMap();
continue;
}
if ((localObject == null) || (!str1.matches("^\\w+=.+$")) ||
(str2.isEmpty())) {
continue;
}
String[] arrayOfString = str1.trim().split("=");
if (isValidKey(arrayOfString[0])) {
String str3 = arrayOfString[1];
if ((arrayOfString[0].equals("pin")) &&
(!isValidPin(str3))) {
System.out.println("Invalid pin '" + str3 + "' on account: " + str2 + " (ignored)");
str3 = null;
}

if (arrayOfString[0].equals("password")) {
str3 = cipher(str3, false, key);
}
((TreeMap)localObject).put(arrayOfString[0], str3);
}
}

if (!str2.isEmpty()) {
localTreeMap.put(fixName(str2), localObject);
}
localBufferedReader.close();
} catch (Exception localException) {
localException.printStackTrace();
}
}
return (Map<String, Map<String, String>>)localTreeMap;
}

private static boolean isValidPin(String paramString)
{
if (paramString.length() == 4) {
for (int i = 0; i < paramString.length(); i++) {
int j = paramString.charAt(i);
if ((j < 48) || (j > 57)) {
return false;
}
}
return true;
}
return false;
}

private static String fixName(String paramString)
{
if (paramString.charAt(0) > '[') {
paramString = (char)(paramString.charAt(0) - ' ') + paramString.substring(1);
}
if (!paramString.contains("@")) {
paramString = paramString.replaceAll("\\s", "_");
}
return paramString;
}

private static boolean isValidKey(String paramString)
{
for (String str : VALID_KEYS)
if (paramString.equalsIgnoreCase(str))
return true;
return false;
}

private static byte[] SHA1(String paramString) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
localMessageDigest.update(paramString.getBytes("iso-8859-1"), 0, paramString.length());
return localMessageDigest.digest();
}

private static String cipher(String paramString, boolean paramBoolean, String key)
{
if (paramString == null)
return null;
byte[] arrayOfByte1;
try
{
arrayOfByte1 = SHA1(key);
} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
localNoSuchAlgorithmException.printStackTrace();
return paramString;
} catch (UnsupportedEncodingException localUnsupportedEncodingException) {
localUnsupportedEncodingException.printStackTrace();
return paramString;
}
if (paramBoolean) {
Object localObject = "";
byte[] arrayOfByte2 = paramString.getBytes();
for (int i = 0; i < arrayOfByte1.length; i++) {
if (i < paramString.length())
localObject = (String)localObject + (arrayOfByte1 + arrayOfByte2) + "a";
else {
localObject = (String)localObject + arrayOfByte1 + "a";
}
}
return ((String)localObject).substring(0, ((String)localObject).length() - "a".length());
}
String[] localObject = paramString.split("a");
byte[] arrayOfByte2 = new byte[localObject.length];
int i;
for (i = 0; i < arrayOfByte1.length; i++) {
int j = Integer.parseInt(localObject);
if (arrayOfByte1 == j) {
break;
}
arrayOfByte2 = (byte)(j - arrayOfByte1);
}
return (String)new String(arrayOfByte2, 0, i);
}

}
[/php]

Sir R. M8gic1an

2011-02-11 12:14:46

Didn't read it through, but the idea sounds amazing.

If one click (uknowwhatImean) can take RSBot account and make it into DeclarePlayers.simba that would be great.

I've actually been considering DeclarePlayers.simba where you could store information for most scripts

eg


procedure DeclarePlayers;
var
i: integer;
begin
with Players[0] do
begin
Username := 'Sir R. Magician';
Password := '$RL43v3R';
Pin := '1234';
end;

for i := 0 to High(Players) do
begin
with Players[i] do
begin
{$IFDEF MSI_LSW}
SetLength(RocksArray, 3);
RocksArray := [ORE_COAL, ORE_MITH, ORE_ADDY];
{$ENDIF}

{$IFDEF RM_Cook}
SetLength(Processes, 4);
Processes := [COLLECT_WHEAT, COOK_FLOUR, COOK_MIX, COOK_BAKE];
{$ENDIF}
end;
end;
end;

{$DEFINES} can also be done for players individually, or the script can check that all the arguments are valid.

Just read through the first bit, beautifully done… if you have any more RS Related java code by any chance… I'd love to see it :)

~RM

Wizzup?

2011-02-12 05:41:35

We'll really need some working scripts first. MSI doesn't work properly due to Reflection memory leaks.

Smartzkid

2011-02-12 16:35:52

The output from this one can be piped to an appropriate file to generate a (hopefully) working DeclarePlayers procedure.

I can add reward/member fields if someone would be so kind as to show me what the names are for SRL (if they exist?). It's been a while since I did this myself :p

[PHP]import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.TreeMap;

public class main {

private static final String[] VALID_KEYS = { "password", "pin", "reward", "member", "take_breaks" };

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

out("procedure DeclarePlayers;");
out("var");
out(" i: integer;");
out("begin");
String key;

try
{
InetAddress localInetAddress = InetAddress.getLocalHost();
NetworkInterface localNetworkInterface = NetworkInterface.getByInetAddress(localInetAddress);
key = new String(localNetworkInterface.getHardwareAddress());
} catch (Exception localException) {
key = System.getProperty("user.name") + System.getProperty("user.language");
}

Map<String, Map<String,String>> accounts = loadAccounts(key);

out(" SetLength(Players, " + accounts.size() + ");");

Object[] usernames = accounts.keySet().toArray();

for(int i = 0; i < accounts.size(); i++)
{
String u = (String)usernames;
out(" with Players[" + i + "] do");
out(" begin");
out(" Username := '" + u + "';");
out(" Password := '" + accounts.get(u).get("password") + "';");
if(accounts.get(u).containsKey("pin"))
out(" PIN := '" + accounts.get(u).get("pin") + "';");
out(" end;");
}

out("end;");
}

public static void out(String s)
{
System.out.println(s);
//Output to a file in the future -> save people from having to pipe it
}

public static String getAccountsFile()
{
String str;
String str1 = System.getProperty("os.name");
if (str1.contains("Windows"))
str = new StringBuilder().append(System.getenv("APPDATA")).append(File.separator).append("RSBot").append("_Accounts.ini").toString();
else
str = new StringBuilder().append(getUnixHome()).append(File.separator).append(".").append("RSBot".toLowerCase()).append("acct").toString();

return str;
}

public static String getUnixHome() {
String str = System.getProperty("user.home");
return str == null ? "~" : str;
}

private static Map<String, Map<String, String>> loadAccounts(String key)
{
TreeMap localTreeMap = new TreeMap();
Object localObject = null;

File localFile = new File(getAccountsFile());
if (localFile.exists()) {
try {
BufferedReader localBufferedReader = new BufferedReader(new FileReader(localFile));

String str2 = "";
String str1;
while ((str1 = localBufferedReader.readLine()) != null) {
if ((str1.startsWith("[")) && (str1.endsWith("]"))) {
if (!str2.isEmpty()) {
localTreeMap.put(fixName(str2), localObject);
}
str2 = str1.trim().substring(1).substring(0, str1.length() - 2);
localObject = new TreeMap();
continue;
}
if ((localObject == null) || (!str1.matches("^\\w+=.+$")) ||
(str2.isEmpty())) {
continue;
}
String[] arrayOfString = str1.trim().split("=");
if (isValidKey(arrayOfString[0])) {
String str3 = arrayOfString[1];
if ((arrayOfString[0].equals("pin")) &&
(!isValidPin(str3))) {
System.out.println("Invalid pin '" + str3 + "' on account: " + str2 + " (ignored)");
str3 = null;
}

if (arrayOfString[0].equals("password")) {
str3 = cipher(str3, false, key);
}
((TreeMap)localObject).put(arrayOfString[0], str3);
}
}

if (!str2.isEmpty()) {
localTreeMap.put(fixName(str2), localObject);
}
localBufferedReader.close();
} catch (Exception localException) {
localException.printStackTrace();
}
}
return (Map<String, Map<String, String>>)localTreeMap;
}

private static boolean isValidPin(String paramString)
{
if (paramString.length() == 4) {
for (int i = 0; i < paramString.length(); i++) {
int j = paramString.charAt(i);
if ((j < 48) || (j > 57)) {
return false;
}
}
return true;
}
return false;
}

private static String fixName(String paramString)
{
if (paramString.charAt(0) > '[') {
paramString = (char)(paramString.charAt(0) - ' ') + paramString.substring(1);
}
if (!paramString.contains("@")) {
paramString = paramString.replaceAll("\\s", "_");
}
return paramString;
}

private static boolean isValidKey(String paramString)
{
for (String str : VALID_KEYS)
if (paramString.equalsIgnoreCase(str))
return true;
return false;
}

private static byte[] SHA1(String paramString) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
localMessageDigest.update(paramString.getBytes("iso-8859-1"), 0, paramString.length());
return localMessageDigest.digest();
}

private static String cipher(String paramString, boolean paramBoolean, String key)
{
if (paramString == null)
return null;
byte[] arrayOfByte1;
try
{
arrayOfByte1 = SHA1(key);
} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
localNoSuchAlgorithmException.printStackTrace();
return paramString;
} catch (UnsupportedEncodingException localUnsupportedEncodingException) {
localUnsupportedEncodingException.printStackTrace();
return paramString;
}
if (paramBoolean) {
Object localObject = "";
byte[] arrayOfByte2 = paramString.getBytes();
for (int i = 0; i < arrayOfByte1.length; i++) {
if (i < paramString.length())
localObject = (String)localObject + (arrayOfByte1 + arrayOfByte2) + "a";
else {
localObject = (String)localObject + arrayOfByte1 + "a";
}
}
return ((String)localObject).substring(0, ((String)localObject).length() - "a".length());
}
String[] localObject = paramString.split("a");
byte[] arrayOfByte2 = new byte[localObject.length];
int i;
for (i = 0; i < arrayOfByte1.length; i++) {
int j = Integer.parseInt(localObject);
if (arrayOfByte1 == j) {
break;
}
arrayOfByte2 = (byte)(j - arrayOfByte1);
}
return (String)new String(arrayOfByte2, 0, i);
}

} [/php]

Sir R. M8gic1an

2011-02-12 17:17:26

From: Wizzup?
We'll really need some working scripts first. MSI doesn't work properly due to Reflection memory leaks.


MSI works around the clock on one player, hardly 'not properly'

Markus

2011-02-12 21:35:41

Yea, maybe that is for you but my experience is quite different.

Coh3n

2011-02-13 01:44:28

From: Sir R. M8gic1an
MSI works around the clock on one player, hardly 'not properly'

It's different for each user. I can't run it more than 3-4 hours before Simba crashes with the code:8 error.

From: Markus
Yea, maybe that is for you but my experience is quite different.

What problems are you still having? I'll be working on the tracking/timed rocks in the next couple days, but other than that?

Markus

2011-02-13 05:37:20

Code 8..
There's some HUGE memory leak somewhere in the reflection include

Sir R. M8gic1an

2011-02-13 06:06:03

From: Markus
Code 8..
There's some HUGE memory leak somewhere in the reflection include


Just disable reflection, most MSI scripts should run jsut fine without it.

Also, I don't see you posting your best MSI proggy, I see you making every effort to point out every single flaw that needs fixing / improving.

~RM

Wizzup?

2011-02-13 06:18:23

From: Sir R. M8gic1an
Also, I don't see you posting your best MSI proggy, I see you making every effort to point out every single flaw that needs fixing / improving.

~RM


That sounds like a tester directly from heaven for a developer. I'd praise these guys if I were you.


Also, the code 8 error is not an error in Simba directly…

Sir R. M8gic1an

2011-02-13 06:33:33

I didn't complain wizzup. But such a tester should imo also post his best results.

~RM

Coh3n

2011-02-13 15:08:32

From: Markus
Code 8..
There's some HUGE memory leak somewhere in the reflection include

Ah okay, was just making sure it wasn't anything (major) related to reflection.

E: And I don't know, I wrote a private fighter in all reflection and I've run it several times for 6+ hours and never gotten the code:8 error, but I get it almost every time with MSI (either that or SMART goes black).

Sir R. M8gic1an

2011-02-13 19:50:34

Just do whatever you can to steal that thunder. Pump all the guns out. Let's ride this wave. We're stable and growing, and we've got pretty much everything we need and a lot more potential.

There's loads of scripts in public and a few in members. And there's MSI. And there might be more. And reflection makes it all real quick. That's just my $0.07 :)

~RM

n3ss3s

2011-02-13 22:01:35

Did u test it out, I once tried getHardwareAddress() for the same purpose and it returned something closer to arabic than numeric.

Smartzkid

2011-02-13 23:24:26

I didn't check to see what that specific function returns; this is mostly pieced together from decompiled code.

I have verified that it correctly decodes the account information. With a file name change, it should be able to decode RuneDev's account information as well.

Sir R. M8gic1an

2011-02-14 06:24:50

Search for some support higher up, my hands are filled as it is… :)

~RM

Smartzkid

2011-02-18 01:28:34

This code should give an output that will work as MSI's player.txt.

Todo:
  • Output to a file rather than the console
  • Find player.txt
  • Merge with existing player.txt

Is 30 a sane value for the BreakTime variable?

[php]import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.TreeMap;

public class main {

private static final String[] VALID_KEYS = { "password", "pin", "reward", "member", "take_breaks" };

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

String key;

try
{
InetAddress localInetAddress = InetAddress.getLocalHost();
NetworkInterface localNetworkInterface = NetworkInterface.getByInetAddress(localInetAddress);
key = new String(localNetworkInterface.getHardwareAddress());
} catch (Exception localException) {
key = System.getProperty("user.name") + System.getProperty("user.language");
}

Map<String, Map<String,String>> accounts = loadAccounts(key);
out(accounts.toString());
out("[Number of Players]");
out("NumberOfPlayers=" + accounts.size());
out("");

Object[] usernames = accounts.keySet().toArray();

for(int i = 0; i < accounts.size(); i++)
{
String u = (String)usernames;
out("[" + i + "]");
out("Name=" + u);
out("Pass=" + accounts.get(u).get("password"));
out("Active=True");
if(accounts.get(u).containsKey("member") && (accounts.get(u).get("member") == "true"))
out("Member=True");
else
out("Member=False");
if(accounts.get(u).containsKey("pin"))
out("PIN=" + accounts.get(u).get("pin"));
out("Location=0");
if(accounts.get(u).containsKey("take_breaks") && (accounts.get(u).get("take_breaks") == "true"))
out("BreakTime=20");
else
out("BreakTime=0");
out("BreakLoads=0");
out("TotalTime=0");
out("TotalLoads=0");
out("NumberOfScripts=0");
out("");
}
}

public static void out(String s)
{
System.out.println(s);
//Output to a file in the future -> save people from having to pipe it
}

public static String getAccountsFile()
{
String str;
String str1 = System.getProperty("os.name");
if (str1.contains("Windows"))
str = new StringBuilder().append(System.getenv("APPDATA")).append(File.separator).append("RSBot").append("_Accounts.ini").toString();
else
str = new StringBuilder().append(getUnixHome()).append(File.separator).append(".").append("RSBot".toLowerCase()).append("acct").toString();

return str;
}

public static String getUnixHome() {
String str = System.getProperty("user.home");
return str == null ? "~" : str;
}

private static Map<String, Map<String, String>> loadAccounts(String key)
{
TreeMap localTreeMap = new TreeMap();
Object localObject = null;

File localFile = new File(getAccountsFile());
if (localFile.exists()) {
try {
BufferedReader localBufferedReader = new BufferedReader(new FileReader(localFile));

String str2 = "";
String str1;
while ((str1 = localBufferedReader.readLine()) != null) {
if ((str1.startsWith("[")) && (str1.endsWith("]"))) {
if (!str2.isEmpty()) {
localTreeMap.put(fixName(str2), localObject);
}
str2 = str1.trim().substring(1).substring(0, str1.length() - 2);
localObject = new TreeMap();
continue;
}
if ((localObject == null) || (!str1.matches("^\\w+=.+$")) ||
(str2.isEmpty())) {
continue;
}
String[] arrayOfString = str1.trim().split("=");
if (isValidKey(arrayOfString[0])) {
String str3 = arrayOfString[1];
if ((arrayOfString[0].equals("pin")) &&
(!isValidPin(str3))) {
System.out.println("Invalid pin '" + str3 + "' on account: " + str2 + " (ignored)");
str3 = null;
}

if (arrayOfString[0].equals("password")) {
str3 = cipher(str3, false, key);
}
((TreeMap)localObject).put(arrayOfString[0], str3);
}
}

if (!str2.isEmpty()) {
localTreeMap.put(fixName(str2), localObject);
}
localBufferedReader.close();
} catch (Exception localException) {
localException.printStackTrace();
}
}
return (Map<String, Map<String, String>>)localTreeMap;
}

private static boolean isValidPin(String paramString)
{
if (paramString.length() == 4) {
for (int i = 0; i < paramString.length(); i++) {
int j = paramString.charAt(i);
if ((j < 48) || (j > 57)) {
return false;
}
}
return true;
}
return false;
}

private static String fixName(String paramString)
{
if (paramString.charAt(0) > '[') {
paramString = (char)(paramString.charAt(0) - ' ') + paramString.substring(1);
}
if (!paramString.contains("@")) {
paramString = paramString.replaceAll("\\s", "_");
}
return paramString;
}

private static boolean isValidKey(String paramString)
{
for (String str : VALID_KEYS)
if (paramString.equalsIgnoreCase(str))
return true;
return false;
}

private static byte[] SHA1(String paramString) throws NoSuchAlgorithmException, UnsupportedEncodingException {
MessageDigest localMessageDigest = MessageDigest.getInstance("SHA-1");
localMessageDigest.update(paramString.getBytes("iso-8859-1"), 0, paramString.length());
return localMessageDigest.digest();
}

private static String cipher(String paramString, boolean paramBoolean, String key)
{
if (paramString == null)
return null;
byte[] arrayOfByte1;
try
{
arrayOfByte1 = SHA1(key);
} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
localNoSuchAlgorithmException.printStackTrace();
return paramString;
} catch (UnsupportedEncodingException localUnsupportedEncodingException) {
localUnsupportedEncodingException.printStackTrace();
return paramString;
}
if (paramBoolean) {
Object localObject = "";
byte[] arrayOfByte2 = paramString.getBytes();
for (int i = 0; i < arrayOfByte1.length; i++) {
if (i < paramString.length())
localObject = (String)localObject + (arrayOfByte1 + arrayOfByte2) + "a";
else {
localObject = (String)localObject + arrayOfByte1 + "a";
}
}
return ((String)localObject).substring(0, ((String)localObject).length() - "a".length());
}
String[] localObject = paramString.split("a");
byte[] arrayOfByte2 = new byte[localObject.length];
int i;
for (i = 0; i < arrayOfByte1.length; i++) {
int j = Integer.parseInt(localObject);
if (arrayOfByte1 == j) {
break;
}
arrayOfByte2 = (byte)(j - arrayOfByte1);
}
return (String)new String(arrayOfByte2, 0, i);
}

} [/php]

EDIT:
Changed breaking to every 20 minutes

Sir R. M8gic1an

2011-02-18 05:36:18

bresking every 30 mins? I'd suggest put it down to 20, cus if I remember right randoms start popping up after 15 mins / that's when they start 'warming up' your account. This I gathered from a post on here long ago.

~RM

n3ss3s

2011-03-02 16:55:07

I'm trying to convert it to C#, and this part right here is giving me a stack overflow

byteArray22[x] = (byte)(j - byteArray1[x]);

(Had to rename to byteArray22 because of shit reasons)

Any ideas?




j is j, array value is bytearray1[x].

Smartzkid

2011-03-02 18:50:58

Post your code. That's not a stack overflow, just a numerical overflow - it happens because your code is attempting to put a negative number into a byte.

The warning should go away if you wrap the statement with unchecked{ }, but I doubt that will fix the overall calculation.

n3ss3s

2011-03-02 19:19:16

Here -

[php]
byte[] ToSHA1(string p)
{
return new SHA1CryptoServiceProvider().ComputeHash(new System.Text.UTF8Encoding().GetBytes(p));
}

public string cipher(string p, bool b, string k)
{
if (p == null)
return null;
byte[] byteArray1;
try
{
byteArray1 = ToSHA1(k);
} catch (Exception)
{
return p;
}
if (b)
{
Object localObject = null;
byte[] byteArray2 = new System.Text.UTF8Encoding().GetBytes(p);
for (int i = 0; i < byteArray1.Length; i++)
{
if (i < p.Length)
localObject = (string) localObject + (byteArray1 + byteArray2) + "a";
else
localObject = (string) localObject + byteArray1 + "a";
}
return ((string) localObject).Substring(0, ((string) localObject).Length - "a".Length);
}
String[] localObject2 = p.Split('a');
byte[] byteArray22 = new Byte[localObject2.Length];
int x = 0;
for (x = 0; x < byteArray1.Length; x++)
{
int j = Int32.Parse(localObject2[x]);
if (byteArray1[x] == j)
break;
Console.WriteLine("j: "+j+" array value: "+byteArray1[x]);
byte byx = byte.MaxValue;
try
{
byx = (byte) (j - byteArray1[x]);
} catch (Exception e)
{
Console.WriteLine(e.Message);
}
byteArray22[x] = byx;
}
return System.Text.ASCIIEncoding.ASCII.GetString(byteArray22);
}[/php]

Smartzkid

2011-03-02 21:43:58

I can't spend much time on this right now, but here's some information that should help:

C# bytes are unsigned, Java bytes are signed. (wtf SUN?)

C# Key & SHA1
key: 0 10 -51 24 -68 33
Hash: 6 34 67 24 91 54 231 79 180 214 195 142 29 180 157 137 116 37 165 47

Java Key & SHA1
key: 0 10 -51 24 -68 33
SHA1(key): 3 24 151 68 155 185 241 226 28 129 193 157 149 137 95 33 25 247 219 180

Looks like the C# port of SHA1 is not equivalent to the original.

PS: This is handy for output - http://msdn.microsoft.com/en-us/library/848f20dy.aspx

Method

2011-03-02 23:23:17

From: Smartzkid
C# bytes are unsigned, Java bytes are signed. (wtf SUN?)


What's wrong with signed integral types?

Smartzkid

2011-03-02 23:36:39

From: Method
What's wrong with signed integral types?


Nothing in particular, I'm simply used to having my bytes unsigned.

EDIT:

"Unsigned integers were deliberately left out of Java because James Gosling believed that programmers would not understand how unsigned arithmetic works."

Fuck java. I want my unsigned bytes.

The signed types doesn't bother me, but the lack of an unsigned operator does.

n3ss3s

2011-03-03 17:14:29

Didn't help me much since I have pretty much zero understanding about unsigned/signed etc, any ideas on how I should go around this?

Smartzkid

2011-03-03 21:35:18

TBH I just played around with the code a bunch and got no where.

From what I can tell, it's an encoding issue.

My current code:

[php] static byte[] ToSHA1(string p)
{
byte[] b = Encoding.GetEncoding(28591).GetBytes(p);
var sha1 = SHA1Managed.Create();
byte[] bf = sha1.ComputeHash(b);
System.Diagnostics.Debug.Write("Hash: ");
foreach (byte i in bf)
System.Diagnostics.Debug.Write(i + " ");
System.Diagnostics.Debug.WriteLine("");
return bf;
}[/php]

n3ss3s

2011-03-03 22:09:22

Returns the same hash as what I had earlier :/ Oh well…