• Welcome to Valhalla Legends Archive.
 

[C#]Hashing

Started by shout, December 05, 2004, 10:25 PM

Previous topic - Next topic

shout

Here. Have a working X-Sha-1 for C#.


public static byte[] HashData(byte[] data)
{
uint[] buffer = new uint[128];
Buffer.BlockCopy(data, 0, buffer, 0, data.Length);
int i;
uint a, b, c, d, e, g;
for (i = 0; i < 0x50; i++)
{
buffer[i + 16] = Rol(1, (int)(buffer[i] ^ buffer[i + 8] ^ buffer[i + 2] ^ buffer[i + 13]) % 32);
}

a = 0x67452301u;
b = 0xefcdab89u;
c = 0x98badcfeu;
d = 0x10325476u;
e = 0xc3d2e1f0u;
g = 0x00000000u;

for (i = 0; i < 20; i++)
{
g = buffer[i] + Rol(a, 5) + e + ((b & c) | (~b & d)) + 0x5a827999u;
e = d;
d = c;
c = Rol(b, 30);
b = a;
a = g;
}

for (; i < 40; i++)
{
g = (d ^ c ^ b) + e + Rol(g, 5) + buffer[i] + 0x6ed9eba1u;
e = d;
d = c;
c = Rol(b, 30);
b = a;
a = g;
}

for (; i < 60; i++)
{
g = buffer[i] + Rol(g, 5) + e + ((c & b) | (d & c) | (d & b)) - 0x70e44324u;
e = d;
d = c;
c = Rol(b, 30);
b = a;
a = g;
}

for (; i < 80; i++)
{
g = (d ^ c ^ b) + e + Rol(g, 5) + buffer[i] - 0x359d3e2au;
e = d;
d = c;
c = Rol(b, 30);
b = a;
a = g;
}

uint[] rInts = new uint[5];
rInts[0] = a + 0x67452301u;
rInts[1] = b + 0xefcdab89u;
rInts[2] = c + 0x98badcfeu;
rInts[3] = d + 0x10325476u;
rInts[4] = e + 0xc3d2e1f0u;
byte[] rBytes = new byte[20];
Buffer.BlockCopy(rInts, 0, rBytes, 0, 20);
return rBytes;
}

private static uint Rol(uint n, int shift)
{
return (uint)((n << shift) | (n >> (32 - shift)));
}


Edit: Changed some bad names... from "stuff" to "rInts" and "q" to "rBytes".[/i]

Mephisto

Is it just me or does that look almost exactly like Adron's HashData()?

MyndFyre

Quote from: Mephisto on December 05, 2004, 11:01 PM
Is it just me or does that look almost exactly like Adron's HashData()?

I've never seen Adron's, but -- who cares?  If Adron's is open-source then it should be translatable into other languages.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

shout

#3
Its from bnetauth, couldn't find author so I assumed it was Yobguls.

But all the credit goes to Adron I guess.

Took me about 2 weeks to get this done... overflow checking was on  :P

I will post the password and cdkey stuff as soon as I port it. Mabey I will put it in a nice little .Net dll.

Mephisto


MyndFyre

Quote from: shout on December 06, 2004, 06:31 AM
overflow checking was on  :P

LoL --

unchecked(expression);
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

shout

Quote from: MyndFyre on December 06, 2004, 04:04 PM
Quote from: shout on December 06, 2004, 06:31 AM
overflow checking was on  :P

LoL --

unchecked(expression);

Or just turn overflow checking off for the whole project.

MyndFyre

Quote from: shout on December 06, 2004, 08:53 PM
Quote from: MyndFyre on December 06, 2004, 04:04 PM
Quote from: shout on December 06, 2004, 06:31 AM
overflow checking was on  :P

LoL --

unchecked(expression);

Or just turn overflow checking off for the whole project.

Sometimes that's not optimal.  ;)  You can also do entire unchecked blocks:


unchecked {
  int m = (uint)n;
}


etc. :)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

shout

:p

As the thing above my pic indicates: I am no longer a newbie I have moved to junior member.

MyndFyre

Quote from: shout on December 06, 2004, 09:32 PM
:p

As the thing above my pic indicates: I am no longer a newbie I have moved to junior member.

hehe.  That has nothing to do with what I say.  And I'm not trying to pick on you.  ;)
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

shout

I know I just give everyone shit all the time. Anything I say outside of code blocks should probably not be taken seroiusly.

And neither should my spelling.

Zakath

Quote from: shout on December 06, 2004, 09:32 PM
:p

As the thing above my pic indicates: I am no longer a newbie I have moved to junior member.

There lots of Junior Members. However, there's only one Havoc Wreaker! :)
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

Soul Taker

Quote from: Zakath on December 07, 2004, 01:06 AM
Quote from: shout on December 06, 2004, 09:32 PM
:p

As the thing above my pic indicates: I am no longer a newbie I have moved to junior member.

There lots of Junior Members. However, there's only one Havoc Wreaker! :)
I'm a fake admin!  Go me!!

shout

How do you change that? Do you have to have so many posts or something? (Excuse my noobness)

MyndFyre

Quote from: shout on December 07, 2004, 07:36 AM
How do you change that? Do you have to have so many posts or something? (Excuse my noobness)

I don't believe that we peons have the ability to set our Custom Title.  I believe you'll need to PM an Admin.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.