View Single Post
  #3 (permalink)  
Old June 5th, 2002
Eoin Eoin is offline
Apprentice
 
Join Date: May 2nd, 2002
Location: Five paces forward, two left.
Posts: 5
Eoin is flying high
Default

No its not a stupid answer, WinCVS wouldn't run and I couldn't find the source. That was then, this is now and I've since found it.
Code:
// Convert 5 Bytes to 8 Bytes Base32
void _Sha1toBase32(BYTE *out, const BYTE *in)
{
	const char *Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

	out[0] = Table[((in[0] >> 3)               ) & 0x1F];
	out[1] = Table[((in[0] << 2) | (in[1] >> 6)) & 0x1F];
	out[2] = Table[((in[1] >> 1)               ) & 0x1F];
	out[3] = Table[((in[1] << 4) | (in[2] >> 4)) & 0x1F];
	out[4] = Table[((in[2] << 1) | (in[3] >> 7)) & 0x1F];
	out[5] = Table[((in[3] >> 2)               ) & 0x1F];
	out[6] = Table[((in[3] << 3) | (in[4] >> 5)) & 0x1F];
	out[7] = Table[((in[4]     )               ) & 0x1F];
}

// Return a base32 representation of a sha1 hash
CString Sha1toBase32(const BYTE *Sha1)
{
	char Base32[32];
	CString ret;

	_Sha1toBase32((BYTE *)Base32, Sha1);
	_Sha1toBase32((BYTE *)Base32 + 8, Sha1 + 5);
	_Sha1toBase32((BYTE *)Base32 + 16, Sha1 + 10);
	_Sha1toBase32((BYTE *)Base32 + 24, Sha1 + 15);

	ret = CString(Base32, 32);
	return ret;
}
I still can't get this bloody thing to work though, I'll figre it out.
Reply With Quote