WJLHA (full name: Wang Jie lin Hash Algorithm) is a free and open source hash algorithm. The algorithm is based on the weighted probability model theory (basic theory of Jielin code). It is the basic algorithm for China's independent theoretical innovation and application implementation, and has been authorized by China's invention patent. Jelin code is not only a hash algorithm, but also includes a series of new algorithms such as symmetric encryption (authorized), channel error detection and correction (authorized and PCT), lossless compression (authorized), filtering algorithm (Applied), pseudo-random (authorized), etc, The source code of all basic algorithms based on weighted probability model is also open source in the book "principle and application of Jielin code" (author Wang Jielin, ISBN No. 978-7-5221-1311-1), which is only for your study and reference.
WJLHA is completely different from MD5, SHA, MAC, CRC and SM3. It supports custom and adaptive hash value length and private secret key. At present, the relatively stable version is version 2.0.1 (WJLHA2 for short). It is worth noting that the language versions of the algorithm have realized interoperability, and provide a complete development library, support linux, unix, window, Android, IOS and other operating systems, and support Web applications (JavaScript). Among them, C, python, java and JavaScript versions are published in GitHub and CSDN:
GitHub download address: https://github.com/Jielin-Code/WjlHashAlgorithm
CSDN download address: https://download.csdn.net/download/wjlxueshu/12754346
JavaScript version download address: http://jielincode.ystx365.com/ Or https://download.csdn.net/download/wjlxueshu/16543250
(1) Existing international algorithms:
(1) MD5 (Message Digest Algorithm 5): it is a one-way hash algorithm developed by RSA data security company. MD5 is widely used and can be used to perform secret code operation on data blocks of different lengths into a 128 bit value.
(2) SHA (Secure Hash Algorithm) this is a relatively new hash algorithm, which can generate a 160 bit value for data operation of any length. The five algorithms of Sha family are SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512, which are designed by the National Security Agency (NSA) and published by the National Institute of standards and Technology (NIST); It is the American government standard. The latter four are sometimes referred to as SHA-2. SHA-1 is widely used in many security protocols, including TLS and SSL, PGP, SSH, S/MIME and IPsec. It was once regarded as the successor of MD5 (hash function widely used earlier). However, the security of SHA-1 is now seriously questioned by cryptologists; Although there is no effective attack on SHA-2, its algorithm is basically similar to SHA-1; So some people began to develop other alternative hash algorithms.
WJLHA1 (Wang JieLin Hash Algorithm V1) algorithm has user-defined bit length, flexible algorithm application, more secure and reliable, and supports key and self iterative coding. Since WJLHA2 has been released, the source code of WJLHA1 is now open. Once the SHA algorithm was said to be unbreakable in the United States for ten years. Now I release the source code of my first generation WJLHA-1 algorithm. Professionals are welcome to crack it when the theory and source code are published.
(2) C source code of WJLHA1 algorithm:
The source code includes wjlha h,WJLHA.c,main.c. Welcome to the test.
Header file: wjlha h
#pragma once /****************************************************************************** Jering code hash algorithm Theory source: jering code weighted probability model one-way hash function Code implementation: Wang Jielin Time: April 15, 2020 Version No.: WJLHA-1 ******************************************************************************/ #ifndef _WJLHA_H #define _WJLHA_H /***************************************************************************** Hash function Usages, independent encoding: it is suitable for small files, and when it is called, it reads the files directly into InBuFF, and then calls the encoding below. Usage 2: streaming mode: it is applicable to large files. The InBuFFLength - ByteLength bytes of the file are read each time, and the ByteLength bytes in the OutBuFF after the previous encoding are saved from a certain position of the InBuFF (if it is the first frame), so the data with ByteLength bytes obtained last time and the newly read data are encoded into new ByteLength bytes Usage 3: adaptive flow mode: Based on usage 2, each operation uses different ByteLength. When the ByteLength used each time is known, it increases the difficulty of cracking. keyt Is the key. This hash algorithm supports the digital key set by the user when encoding. The key is encoded to each bit through the weight coefficient of the weighted probability model. When keyt = 0, there is no key. ******************************************************************************/ unsigned char *WJLHA( unsigned char *InBuFF, // Enter the first address of the byte cache waiting for encoding (for file calls, please load the whole file into the cache first), which may contain the data in the UpBuFF after the last encoding unsigned int InBuFFLength, // Enter the length of the InBuFF unsigned int keyt, // Enter the key when encoding. The key is encoded to each bit through the weight coefficient of the weighted probability model. When keyt = 0, there is no key unsigned char *OutBuFF, // Enter the result in the OutBuFF after the last encoding, with a length of ByteLength bytes unsigned int ByteLength // Input, the byte length of the user-defined output result is limited by this function. It is recommended that it should not be less than 128 bits (16 bytes), which is not capped in theory. ); #endif
C source: wjlha c
#include "WJLHA.h" #include "math.h" /*********************************************************************Global variable**********************************************************************/ // Number of bits 1 in each byte static unsigned char CntOfOneSymbol[256]= { 0x00,0x01,0x01,0x02,0x01,0x02,0x02,0x03,0x01,0x02,0x02,0x03,0x02,0x03,0x03,0x04, 0x01,0x02,0x02,0x03,0x02,0x03,0x03,0x04,0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05, 0x01,0x02,0x02,0x03,0x02,0x03,0x03,0x04,0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05, 0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05,0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06, 0x01,0x02,0x02,0x03,0x02,0x03,0x03,0x04,0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05, 0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05,0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06, 0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05,0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06, 0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06,0x04,0x05,0x05,0x06,0x05,0x06,0x06,0x07, 0x01,0x02,0x02,0x03,0x02,0x03,0x03,0x04,0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05, 0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05,0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06, 0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05,0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06, 0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06,0x04,0x05,0x05,0x06,0x05,0x06,0x06,0x07, 0x02,0x03,0x03,0x04,0x03,0x04,0x04,0x05,0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06, 0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06,0x04,0x05,0x05,0x06,0x05,0x06,0x06,0x07, 0x03,0x04,0x04,0x05,0x04,0x05,0x05,0x06,0x04,0x05,0x05,0x06,0x05,0x06,0x06,0x07, 0x04,0x05,0x05,0x06,0x05,0x06,0x06,0x07,0x05,0x06,0x06,0x07,0x06,0x07,0x07,0x08 }; // Bit value of each position in each byte static unsigned char bitOfByteTable[256][8]= { {0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,1},{0,0,0,0,0,0,1,0},{0,0,0,0,0,0,1,1},{0,0,0,0,0,1,0,0},{0,0,0,0,0,1,0,1},{0,0,0,0,0,1,1,0},{0,0,0,0,0,1,1,1}, //0~7 {0,0,0,0,1,0,0,0},{0,0,0,0,1,0,0,1},{0,0,0,0,1,0,1,0},{0,0,0,0,1,0,1,1},{0,0,0,0,1,1,0,0},{0,0,0,0,1,1,0,1},{0,0,0,0,1,1,1,0},{0,0,0,0,1,1,1,1}, //8~15 {0,0,0,1,0,0,0,0},{0,0,0,1,0,0,0,1},{0,0,0,1,0,0,1,0},{0,0,0,1,0,0,1,1},{0,0,0,1,0,1,0,0},{0,0,0,1,0,1,0,1},{0,0,0,1,0,1,1,0},{0,0,0,1,0,1,1,1}, //16~23 {0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,1},{0,0,0,1,1,0,1,0},{0,0,0,1,1,0,1,1},{0,0,0,1,1,1,0,0},{0,0,0,1,1,1,0,1},{0,0,0,1,1,1,1,0},{0,0,0,1,1,1,1,1}, //24~31 {0,0,1,0,0,0,0,0},{0,0,1,0,0,0,0,1},{0,0,1,0,0,0,1,0},{0,0,1,0,0,0,1,1},{0,0,1,0,0,1,0,0},{0,0,1,0,0,1,0,1},{0,0,1,0,0,1,1,0},{0,0,1,0,0,1,1,1}, //32~39 {0,0,1,0,1,0,0,0},{0,0,1,0,1,0,0,1},{0,0,1,0,1,0,1,0},{0,0,1,0,1,0,1,1},{0,0,1,0,1,1,0,0},{0,0,1,0,1,1,0,1},{0,0,1,0,1,1,1,0},{0,0,1,0,1,1,1,1}, //40~47 {0,0,1,1,0,0,0,0},{0,0,1,1,0,0,0,1},{0,0,1,1,0,0,1,0},{0,0,1,1,0,0,1,1},{0,0,1,1,0,1,0,0},{0,0,1,1,0,1,0,1},{0,0,1,1,0,1,1,0},{0,0,1,1,0,1,1,1}, //48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,1,1,0,0,1,0,1},{1,1,1,0,0,1,1,0},{1,1,1,0,0,1,1,1}, //224~231 {1,1,1,0,1,0,0,0},{1,1,1,0,1,0,0,1},{1,1,1,0,1,0,1,0},{1,1,1,0,1,0,1,1},{1,1,1,0,1,1,0,0},{1,1,1,0,1,1,0,1},{1,1,1,0,1,1,1,0},{1,1,1,0,1,1,1,1}, //232~239 {1,1,1,1,0,0,0,0},{1,1,1,1,0,0,0,1},{1,1,1,1,0,0,1,0},{1,1,1,1,0,0,1,1},{1,1,1,1,0,1,0,0},{1,1,1,1,0,1,0,1},{1,1,1,1,0,1,1,0},{1,1,1,1,0,1,1,1}, //240~247 {1,1,1,1,1,0,0,0},{1,1,1,1,1,0,0,1},{1,1,1,1,1,0,1,0},{1,1,1,1,1,0,1,1},{1,1,1,1,1,1,0,0},{1,1,1,1,1,1,0,1},{1,1,1,1,1,1,1,0},{1,1,1,1,1,1,1,1} //248~255 }; /*********************************************************************Private function**********************************************************************/ // In order to improve the effectiveness of the key, the key is processed and the transformed coefficient is returned double ChangeKeyt(double JIELINCOEC, unsigned int keyt) { if(keyt < 100000.0 && keyt > 0){ JIELINCOEC = JIELINCOEC - (1.0 / ((double)keyt + 100000.0)); }else if(keyt >= 100000.0){ JIELINCOEC = JIELINCOEC - (1.0 / (double)keyt); } // If it is 0, the currently calculated weight coefficient will be returned directly return JIELINCOEC; } // This function is the core of the whole algorithm. The probability of symbol 0 in InBuFF is counted, and the coefficient of jering code is obtained according to the probability of symbol 0 and ByteLength. This function is obtained according to my own theory double GetJieLinCoeV(unsigned char *InBuFF, double *p0, double *p1, unsigned int InBuFFLength, unsigned int ByteLength) { int i; double JIELINCOEC = 0.0; unsigned int realLength = 0; double Count1 = 0, CountAll = 0, H; // First, judge whether InBuFFLength is greater than or equal to 3 * ByteLength CountAll = (double)InBuFFLength * 8; // Number of statistical symbols 1 for(i = 0; i < InBuFFLength; ++i){ Count1 += (double)CntOfOneSymbol[InBuFF[i]]; } // Calculate the probability p0 of symbol 0 and the probability p1 of symbol 1 *p1 = Count1 / CountAll; *p0 = 1.0 - *p1; // Find the standard entropy H = -*p0 * (log(*p0)/log(2.0))- *p1 * (log(*p1)/log(2.0)); // Find out the coefficient of jering code that can encode the bit length of ByteLength * 8. Please refer to the formula (2-14) in my theoretical jering code - weighted probability model one-way hash function JIELINCOEC = pow(2.0, H - ((ByteLength- 4) * 8) / CountAll); //Add a little more weight to ensure complete coding // return return JIELINCOEC; } // Encoded output byte information void WEOutPutEncode(unsigned char *EOut_buff,unsigned int *EOut_buff_loop, unsigned char ucByte) { EOut_buff[ *EOut_buff_loop] = ucByte; *EOut_buff_loop = *EOut_buff_loop + 1; } // Core coding void WEncode(unsigned char symbol, double p0, double p1, double JIELINCOE, unsigned int *EFLow, unsigned int *EFRange, unsigned int *EFDigits, unsigned int *EFFollow, unsigned char *EOut_buff,unsigned int *EOut_buff_loop) { unsigned int High = 0,i = 0; // According to the theory of weighted probability model, the coefficient of jering code acts on the probability of symbol 0 and symbol 1 if (1 == symbol){// Symbol 1 *EFLow += (unsigned int)((*EFRange) * p0); *EFRange = (unsigned int)( (*EFRange) * p1 ); }else{ *EFRange = (unsigned int)( (*EFRange) * p0 ); } *EFRange = (unsigned int)((double)(*EFRange) * JIELINCOE); // Output one encoded byte at a time according to the interval coding method while(*EFRange <= 8388608){ High = *EFLow + *EFRange - 1; if(*EFFollow != 0) { if (High <= 2147483648) { WEOutPutEncode(EOut_buff, EOut_buff_loop, *EFDigits); for (i = 1; i <= *EFFollow - 1; ++i){ WEOutPutEncode(EOut_buff, EOut_buff_loop, 0xFF); } *EFFollow = 0; *EFLow = *EFLow + 2147483648; } else if (*EFLow >= 2147483648) { WEOutPutEncode(EOut_buff, EOut_buff_loop, *EFDigits + 1); for (i = 1; i <= *EFFollow - 1; ++i){ WEOutPutEncode(EOut_buff, EOut_buff_loop, 0x00); } *EFFollow = 0; } else { *EFFollow = *EFFollow + 1; *EFLow = (*EFLow << 8) & 2147483647; *EFRange = *EFRange << 8; continue; } } if (((*EFLow ^ High) & (0xFF << 23)) == 0) { WEOutPutEncode(EOut_buff, EOut_buff_loop, *EFLow >> 23); }else{ *EFLow = *EFLow - 2147483648; *EFDigits = *EFLow >> 23; *EFFollow = 1; } *EFLow = ( ( (*EFLow << 8) & 2147483647) | (*EFLow & 2147483648) ); *EFRange = *EFRange << 8; } } // End coding void WFinishEncode(unsigned int *EFLow, unsigned int *EFRange, double *JIELINCOE, unsigned int *EFDigits, unsigned int *EFFollow, unsigned char *EOut_buff,unsigned int *EOut_buff_loop) { int n = 0; if (*EFFollow != 0) { if (*EFLow < 2147483648) { WEOutPutEncode(EOut_buff, EOut_buff_loop, *EFDigits); for (n = 1; n <= *EFFollow - 1; ++n) WEOutPutEncode(EOut_buff, EOut_buff_loop, 0xFF); } else { WEOutPutEncode(EOut_buff, EOut_buff_loop, *EFDigits + 1); for (n = 1; n <= *EFFollow - 1; ++n) WEOutPutEncode(EOut_buff, EOut_buff_loop, 0x00); } } *EFLow = *EFLow << 1; n = 32; do { n -= 8; WEOutPutEncode(EOut_buff, EOut_buff_loop, *EFLow >> n); } while ( n > 0 ); } // Final function unsigned char *WJLHA( unsigned char *InBuFF, // Enter the first address of byte cache waiting for encoding (for file call, please load the whole file into the cache first) unsigned int InBuFFLength, // Enter the length of the InBuFF unsigned int keyt, // Input, the key at the time of encoding. The key is encoded to each bit through the weight coefficient of the weighted probability model. When keyt = 0, there is no key unsigned char *OutBuFF, // Input. After this encoding, ByteLength bytes will be stored in outboff unsigned int ByteLength // Input, the byte length of the user-defined output result is limited by this function, and the maximum is not less than 128 bits (16 bytes), which is not capped theoretically. ) { int i = 0, j = 0; // Initialize encoder value unsigned int EFLow = 2147483648; unsigned int EFRange = 2147483648; unsigned int EFDigits = 0; unsigned int EFFollow = 0; unsigned int EFTotal = 0; unsigned int EOut_buff_loop = 0; double p0 = 0.0, p1 = 0.0, JIELINCOE = 0.0; // Calculates the probability of symbol 0 and symbol 1 in the current InBuFF JIELINCOE = GetJieLinCoeV(InBuFF, &p0, &p1, InBuFFLength, ByteLength); // Set the key if(keyt > 0){ JIELINCOE = ChangeKeyt(JIELINCOE, keyt); } // Direct coding for(i = 0; i < InBuFFLength ; ++ i){ // Each byte has 8 bits for(j = 0; j < 8; ++ j){ // Encode the current symbol WEncode(bitOfByteTable[InBuFF[i]][j], p0, p1, JIELINCOE, &EFLow, &EFRange, &EFDigits, &EFFollow, OutBuFF,&EOut_buff_loop); } } // End coding WFinishEncode(&EFLow, &EFRange, &JIELINCOE, &EFDigits, &EFFollow, OutBuFF, &EOut_buff_loop); return OutBuFF; }
Test main C source code:
#include "WJLHA.h" #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <time.h> #ifdef WIN32 #define inline __inline #endif // WIN32 int main(){ long t1,t2; int i,j,tj; unsigned char *In_BUFF; unsigned char *Out_BUFF; int In_BUFF_Len = 10000; int ByteLength = 32; unsigned int keyt = 0; In_BUFF = (unsigned char *)malloc(sizeof(unsigned char) * In_BUFF_Len); Out_BUFF = (unsigned char *)malloc(sizeof(unsigned char) * ByteLength); // Generate random number srand(time(0)); // Generate a set of random numbers for(i = 0; i < In_BUFF_Len; ++i){ In_BUFF[i] = rand() % 256;//rand() //printf("%d ", In_BUFF[i]); } //printf("\n"); // Call WJLHA-1 algorithm WJLHA(In_BUFF, In_BUFF_Len, keyt, Out_BUFF, ByteLength); printf("WJLHA-1 Encoded value:\n"); // Output Out_BUFF for(i = 0; i < ByteLength; ++i){ printf("%d ", Out_BUFF[i]); } printf("\n"); system("pause"); return 0; }