Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.61 KB | None | 0 0
  1. #include <openssl/sha.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. void calc_sha256(char *src,char *buffer) {
  7.     SHA256_CTX c;
  8.     SHA256_Init(&c);
  9.     SHA256_Update(&c,src,11);
  10.     SHA256_Final(buffer,&c);
  11. }
  12.  
  13. int cmp(char *a,char *b);
  14.  
  15. int main(void) {
  16.     unsigned char phone_num[11];
  17.     int top,bottom,i,j,tmp_bottom;
  18.     unsigned char ***phone_sha;
  19.     unsigned char input[70],input_hex[32];
  20.     unsigned char tmp_sha;
  21.     phone_sha = (unsigned char ***)malloc(3 * sizeof(unsigned char**));
  22.     for(i = 0;i < 3;i++) {
  23.         phone_sha[i] = (unsigned char **)malloc(100000000 * sizeof(unsigned char *));
  24.         for(j = 0;j < 100000000;j++) {
  25.             phone_sha[i][j] = (unsigned char *)malloc(32 * sizeof(unsigned char));
  26.         }
  27.     }
  28.     puts("memory allocate done.");
  29.     phone_num[0] = '0';
  30.     phone_num[2] = '0';
  31.     for(top = 7;top <= 9;top++) {
  32.         phone_num[1] = '0' + top;
  33.         for(bottom = 0; bottom < 100000000; bottom++) {
  34.             tmp_bottom = bottom;
  35.             for(i = 10;i >= 3;i--) {
  36.                 phone_num[i] = tmp_bottom % 10 + '0';
  37.                 tmp_bottom /= 10;
  38.             }
  39.             calc_sha256(phone_num,phone_sha[top - 7][bottom]);
  40.         }          
  41.     }
  42.     puts("hash calculate done.");
  43.    
  44.     while(1) {
  45.         scanf("%s",input);
  46.         for(i = 0;i < 32;i++) {
  47.             input_hex[i] = (input[i * 2] < 'A' ? input[i * 2] - '0' : input[i * 2] - 'A' + 10) * 16 + (input[i * 2 + 1] < 'A' ? input[i * 2 + 1] - '0' : input[i * 2 + 1] - 'A' + 10);
  48.         }
  49.         printf("input: %s\n",input);
  50.         for(i = 0;i < 3;i++) {
  51.             for(j = 0;j < 100000000;j++) {
  52.                 if(!memcmp(phone_sha[i][j],input_hex,32 * sizeof(unsigned char))) {
  53.                     printf("result: 0%d0%8d\n",i + 7,j);
  54.                 }
  55.             }
  56.         }
  57.         puts("search done.");
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement