Skip to content

Instantly share code, notes, and snippets.

@hshrzd
Last active May 29, 2021 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hshrzd/578770a5261d422e1e112cdd3d8ed75e to your computer and use it in GitHub Desktop.
Save hshrzd/578770a5261d422e1e112cdd3d8ed75e to your computer and use it in GitHub Desktop.
int __stdcall calc_hash(char *name)
{
int next_chunk;
int hash;
for ( hash = HASH_INIT; ; hash = next_chunk + 33 * hash )
{
next_chunk = *name++;
if ( !next_chunk )
break;
}
return hash;
}
void __stdcall decrypt_buf(BYTE *data, BYTE *key, unsigned int size)
{
BYTE key_stream[512];
int j;
char next;
int i;
int v6 = 0;
int v4 = 0;
for ( i = 0; i < 256; ++i )
{
key_stream[i + 256] = i;
key_stream[i] = key[i % size];
}
for ( i = 0; i < 256; ++i )
{
v6 = (key_stream[i] + v6 + key_stream[i + 256]) % 256;
next = key_stream[v6 + 256];
key_stream[v6 + 256] = key_stream[i + 256];
key_stream[i + 256] = next;
}
v6 = 0;
for ( j = 0; j < DATA_SIZE; ++j )
{
i = (i + 1) % 256;
v6 = (v6 + key_stream[i + 256]) % 256;
next = key_stream[v6 + 256];
key_stream[v6 + 256] = key_stream[i + 256];
key_stream[i + 256] = next;
v4 = (key_stream[v6 + 256] + key_stream[i + 256]) % 256;
data[j] ^= key[j % size];
data[j] ^= key_stream[v4 + 256];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment