+- +-

+-User

Welcome, Guest.
Please login or register.
 
 
 

Login with your social network

Forgot your password?

+-Stats

Members
Total Members: 134
Latest: jemes petrick
New This Month: 0
New This Week: 0
New Today: 0
Stats
Total Posts: 170
Total Topics: 99
Most Online Today: 3
Most Online Ever: 677
(September 13, 2022, 10:57:19 am)
Users Online
Members: 0
Guests: 3
Total: 3

Author Topic: My simple hash function  (Read 667 times)

zwclose7

  • Administrator
  • Full Member
  • *****
  • Posts: 155
  • I love anime and science!
    • View Profile
    • My blog
My simple hash function
« on: April 17, 2016, 07:11:39 pm »
This is my new hash function. It can be used to hash binary data and text. The output size of the hash function is 128 bits (16 bytes). The name of this hash function is Neon.

The hash function

Code: [Select]
void WINAPI NeonHash(PVOID Data,ULONG Length,PVOID Result)
{
ULONG i;
PUCHAR ptr=(PUCHAR)Data;

PULONG Hash=(PULONG)Result;

Hash[0]=0x12345678;
Hash[1]=0x98765432;

Hash[2]=0xAABBCCDD;
Hash[3]=0xFFFFFFFF;

for(i=0;i<Length;i++)
{
Hash[0]+=(Hash[(Hash[1]^ptr[i]) & 3]+(ptr[i]<<1))^((Hash[0]>>1)+(Hash[1]<<3));
Hash[1]+=(Hash[(Hash[0]^ptr[i]) & 3]+(ptr[i]<<3))^((Hash[2]>>3)+(Hash[3]<<5));

Hash[2]+=(Hash[(Hash[3]^ptr[i]) & 3]+(Hash[2]>>10))^((Hash[0]<<10)+(Hash[1]>>11));
Hash[3]+=(Hash[(Hash[2]^ptr[i]) & 3]+(Hash[3]>>12))^((Hash[2]<<11)+(Hash[3]>>13));
}

Hash[0]^=(Hash[0]>>3)+(Hash[2]<<5);
Hash[1]^=(Hash[1]>>5)+(Hash[3]<<7);

Hash[2]^=(Hash[2]>>5)+(Hash[0]<<11);
Hash[3]^=(Hash[3]>>7)+(Hash[1]<<13);
}

Sample output

Code: [Select]
Input data: 48 65 6C 6C 6F
Output: f4068206243bc861bb972d4a2f0ce1b0

Here is an example program that allows you to hash files.

Code: [Select]
#include <stdio.h>
#include <Windows.h>

void WINAPI NeonHash(PVOID Data,ULONG Length,PVOID Result)
{
ULONG i;
PUCHAR ptr=(PUCHAR)Data;

PULONG Hash=(PULONG)Result;

Hash[0]=0x12345678;
Hash[1]=0x98765432;

Hash[2]=0xAABBCCDD;
Hash[3]=0xFFFFFFFF;

for(i=0;i<Length;i++)
{
Hash[0]+=(Hash[(Hash[1]^ptr[i]) & 3]+(ptr[i]<<1))^((Hash[0]>>1)+(Hash[1]<<3));
Hash[1]+=(Hash[(Hash[0]^ptr[i]) & 3]+(ptr[i]<<3))^((Hash[2]>>3)+(Hash[3]<<5));

Hash[2]+=(Hash[(Hash[3]^ptr[i]) & 3]+(Hash[2]>>10))^((Hash[0]<<10)+(Hash[1]>>11));
Hash[3]+=(Hash[(Hash[2]^ptr[i]) & 3]+(Hash[3]>>12))^((Hash[2]<<11)+(Hash[3]>>13));
}

Hash[0]^=(Hash[0]>>3)+(Hash[2]<<5);
Hash[1]^=(Hash[1]>>5)+(Hash[3]<<7);

Hash[2]^=(Hash[2]>>5)+(Hash[0]<<11);
Hash[3]^=(Hash[3]>>7)+(Hash[1]<<13);
}

void __fastcall DisplayError(ULONG ErrorCode)
{
printf("Error: Unable to access the target file (%u)",ErrorCode);
}

int main(int argc,char** argv)
{
HANDLE hFile;
ULONG i,FileSize,BytesRead;

PVOID Buffer;
UCHAR Hash[16];

if(argc<2)
{
printf("Usage: NeonHash [Filename]");
return 0;
}

hFile=CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);

if(hFile==INVALID_HANDLE_VALUE)
{
DisplayError(GetLastError());
return 0;
}

FileSize=GetFileSize(hFile,NULL);
Buffer=LocalAlloc(LMEM_ZEROINIT,FileSize);

if(!Buffer)
{
printf("Error: Unable to allocate memory (%u)",GetLastError());
}

if(!ReadFile(hFile,Buffer,FileSize,&BytesRead,NULL))
{
DisplayError(GetLastError());
}

CloseHandle(hFile);

NeonHash(Buffer,FileSize,Hash);
LocalFree(Buffer);

for(i=0;i<16;i++)
{
printf("%02x",Hash[i]);
}

return 0;
}
« Last Edit: April 17, 2016, 09:52:09 pm by zwclose7 »

Share on Facebook Share on Twitter


 

+-Recent Topics

Why Should We Use An Opensea Clone To Begin Your Crypto Business by jemes petrick
September 27, 2022, 07:43:26 pm

Latest NFT Marketplace Trends by jemes petrick
September 23, 2022, 06:24:09 pm

OpenSea Clone Script on Various Blockchains by jemes petrick
September 12, 2022, 07:40:43 pm

Hi zwclose7. How to create process by using NT apis? by zwclose7
June 01, 2021, 03:09:52 pm

Poison of the Day by zwclose7
March 16, 2020, 06:45:08 pm

Native API tutorial by hMihaiDavid
January 08, 2019, 02:11:02 am

The properties of GP nerve agent by xchg
October 19, 2018, 07:40:57 pm

A new route of synthesis for G-series agents by Basquyatti
October 15, 2018, 06:12:57 am

Synthesis of Methylisobutylcarbinylsarin (GH) by APC process by Basquyatti
October 14, 2018, 07:55:33 am

Synthesis conventional of Sarin by Basquyatti
October 02, 2018, 07:57:32 am