Advertisement
flarn2006

Untitled

Feb 27th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <libsha1.h>
  4.  
  5. void printByte(unsigned char);
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     unsigned char hash[20];
  10.     int i;
  11.    
  12.     #ifndef LIBSHA1_NO_CTX
  13.         sha1_ctx ctx;
  14.     #endif
  15.  
  16.     if (argc != 2)
  17.     {
  18.         fprintf(stderr, "Usage: %s string\n", argv[0]);
  19.         return 1;
  20.     }
  21.    
  22.     #ifdef LIBSHA1_NO_CTX
  23.         sha1(hash, argv[1], strlen(argv[1]));
  24.     #else
  25.         sha1_begin(&ctx);
  26.         sha1_hash(argv[1], strlen(argv[1]), &ctx);
  27.         sha1_end(hash, &ctx);
  28.     #endif
  29.    
  30.     for (i=0; i<5; i++) printByte(byte); printf("\n");
  31.    
  32.     return 0;
  33. }
  34.  
  35. void printByte(unsigned char byte)
  36. {
  37.     const char *digits = "0123456789abcdef";
  38.     printf("%c%c", digits[byte / 16], digits[byte % 16]);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement