📜 ⬆️ ⬇️

sha256 tooth test for neural network

Dear Colleagues.
I found my old samples of reverse, unfortunately not the latest version.

I don’t remember very precisely all the details, the experiment was conducted in 2012, but as they dig in the code, they emerge more and more clearly.

Warning: Further code is taken out of context, description of its work is made from memory and may contain errors, is given only for educational purposes.

')
This is how data was prepared for training and testing the neural network. At first lines of this type were generated, they represent the desired result:

spins : 0; server code word : 74b0dc5166334873643c9869327b23c6 spins : 1; server code word : 46e87ccd238e1f29625558ec2ae8944a spins : 2; server code word : 79e2a9e341b71efb2eb141f2507ed7ab spins : 3; server code word : 4db127f8122008545bd062c2515f007c spins : 4; server code word : 140e0f7666ef438d1190cde71f16e9e8 


Then approximately from them hashes for training of a neural network turned out.

 FILE *fp; sha256_context stx; int ss,zz,yy,ii,jj,zzi; unsigned long int pdata; fp = fopen("data_src", "rb"); if(!fp) return 1; // bail out if file not found while(fgets(str,sizeof(str),fp) != NULL) { zz=0; // strip trailing '\n' if it exists int len = strlen(str)-1; if(str[len] == '\n') str[len] = 0; sha256_starts( &stx ); sha256_update( &stx, (uint8 *) str, strlen( str ) ); sha256_finish( &stx, sha256sum ); zz=stx.zzz; 

What gave about the following output:

 d34453f3c04552ee19cb6734ab71ad124710cfc98401570f73f65cb8cfa2a64d 6cc8ca5b918d1a22d5141494ad08b76a6c67cd5f649744f80d2fad4916b2b6d9 f89e9fd9609099b22924a77a5c8122c06118608c4287fca1cdafe5827249bce7 35280fd1e2289488828004682679452a070ccd90c12072fcb904529ab18e3f9d 1112c4cffb617c835874446f13c4d7d29fa091ba7ac996b776998f89dedffcc1 02e0521aae2d4ecdeb4482bda545bb222e1280ec1f580d5d23e29fb719252f70 

Then it all turned bit by bit:

 // printf("\n\n\nSUM="); //    sha256   printf ("%d 512 512",zz); zf(str1); for( j = 0; j < 32; j++ ) { sprintf(str1,"%s%s",str1, ui2bin(sha256sum[j])); } //   512  while(strlen(str1)<512) { sprintf(str1,"%s%s",str1,"0"); } //printf("%s\n",str1); jj=0; ii=0; //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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [...] 

files were fed to the neural network as a training and test sample.
FANN library was used, tried different neurons.
The result was certainly, but was ambiguous. Fully restore the original text failed.
However, sometimes fragments of parts of the lines skipped quite accurately restored.
I think this problem has a solution, but to find it you still need to make an effort.
For example, it makes sense to feed all internal variables of the hashing algorithm to the input of the network. It also makes sense to run competitive networks and teach another network to recognize the result of the consultation.
These interesting experiments can be carried out now much easier than in 2012.
With the advent of tools like Python with Tensorflow, sklearn numpy, scipy and the treasury of the repository, it has become much easier to check.

Source: https://habr.com/ru/post/423839/


All Articles