warcsum/warcsum.c
/*
 * Converts base32 numbers following RFC 4648 to hexadecimal numbers
 */
Converts base32 numbers following RFC 4648 to hexadecimal numbers
Converts base32 numbers following RFC 4648 to hexadecimal numbers
int
base32_to_hex (char* in, char* out)
{
  char binary[BINARY_SHA1_LENGTH];
  if (strlen (in) != 32)
    {
      return -1;
    }
  int i;
  for (i = 0; i < strlen (in); i++)
    {
      if ((in[i] >= 'A' && in[i] <= 'Z'))
        {
          char c[6];
          c[5] = '\0';
          int_to_bin (in[i] - 'A', c);
          strcpy (&binary[i * 5], c);
        }
      else if (in[i] >= '2' && in[i] <= '7')
        {
          char c[6];
          c[5] = '\0';
          int_to_bin (in[i] - ('2' - 26), c);
          strcpy (&binary[i * 5], c);
        }
      else
        {
          assert (0);
        }
    }
  assert (strlen (binary) == 160);
  int s = 0;
  for (i = 0; i < strlen (binary); i += 4, s++)
    {
      char temp[4];
      memcpy (temp, &binary[i], 4);
      int j;
      int t = 0;
      for (j = 3; j >= 0; j--)
        {
          if (temp[j] == '1')
            {
              t |= (1 << (3 - j));
            }
        }
      out[s] = t < 10 ? t + '0' : t - 10 + 'a';
    }
  out[40] = '\0';
  return 0;
}
int base32_to_hex ( char * in , char * out ) { char binary [ BINARY_SHA1_LENGTH ] ; if ( strlen ( in ) != 32 ) { return -1 ; } int i ; for ( i = 0 ; i < strlen ( in ) ; i ++ ) { if ( ( in [ i ] >= ' ' && in [ i ] <= ' ' ) ) { char c [ 6 ] ; c [ 5 ] = ' \0 ' ; int_to_bin ( in [ i ] - ' ' , c ) ; strcpy ( & binary [ i * 5 ] , c ) ; } else if ( in [ i ] >= ' ' && in [ i ] <= ' ' ) { char c [ 6 ] ; c [ 5 ] = ' \0 ' ; int_to_bin ( in [ i ] - ( ' ' - 26 ) , c ) ; strcpy ( & binary [ i * 5 ] , c ) ; } else { assert ( 0 ) ; } } assert ( strlen ( binary ) == 160 ) ; int s = 0 ; for ( i = 0 ; i < strlen ( binary ) ; i += 4 , s ++ ) { char temp [ 4 ] ; memcpy ( temp , & binary [ i ] , 4 ) ; int j ; int t = 0 ; for ( j = 3 ; j >= 0 ; j -- ) { if ( temp [ j ] == ' ' ) { t |= ( 1 << ( 3 - j ) ) ; } } out [ s ] = t < 10 ? t + ' ' : t - 10 + ' ' ; } out [ 40 ] = ' \0 ' ; return 0 ; }
Converts base32 numbers following RFC 4648 to hexadecimal numbers
Converts base32 numbers following RFC 4648 to hexadecimal numbers
/* If strlen(in) != 32 then digest was divided between 2 chunks */ /* base32 to binary */ /* binary to hex */