2002-10-04 17:31:41 +00:00
|
|
|
// hex.cpp - written and placed in the public domain by Wei Dai
|
|
|
|
|
|
|
|
#include "pch.h"
|
2003-07-04 00:17:37 +00:00
|
|
|
|
|
|
|
#ifndef CRYPTOPP_IMPORTS
|
|
|
|
|
2002-10-04 17:31:41 +00:00
|
|
|
#include "hex.h"
|
|
|
|
|
|
|
|
NAMESPACE_BEGIN(CryptoPP)
|
|
|
|
|
|
|
|
static const byte s_vecUpper[] = "0123456789ABCDEF";
|
|
|
|
static const byte s_vecLower[] = "0123456789abcdef";
|
|
|
|
|
|
|
|
void HexEncoder::IsolatedInitialize(const NameValuePairs ¶meters)
|
|
|
|
{
|
2003-07-18 04:35:30 +00:00
|
|
|
bool uppercase = parameters.GetValueWithDefault(Name::Uppercase(), true);
|
2002-10-04 17:31:41 +00:00
|
|
|
m_filter->Initialize(CombinedNameValuePairs(
|
|
|
|
parameters,
|
2003-07-18 04:35:30 +00:00
|
|
|
MakeParameters(Name::EncodingLookupArray(), uppercase ? &s_vecUpper[0] : &s_vecLower[0], false)(Name::Log2Base(), 4, true)));
|
2002-10-04 17:31:41 +00:00
|
|
|
}
|
|
|
|
|
2003-07-18 04:35:30 +00:00
|
|
|
void HexDecoder::IsolatedInitialize(const NameValuePairs ¶meters)
|
|
|
|
{
|
2006-07-23 10:38:00 +00:00
|
|
|
BaseN_Decoder::IsolatedInitialize(CombinedNameValuePairs(
|
2003-07-18 04:35:30 +00:00
|
|
|
parameters,
|
|
|
|
MakeParameters(Name::DecodingLookupArray(), GetDefaultDecodingLookupArray(), false)(Name::Log2Base(), 4, true)));
|
|
|
|
}
|
|
|
|
|
|
|
|
const int *HexDecoder::GetDefaultDecodingLookupArray()
|
2002-10-04 17:31:41 +00:00
|
|
|
{
|
2010-06-18 00:51:12 +00:00
|
|
|
static volatile bool s_initialized = false;
|
2002-10-04 17:31:41 +00:00
|
|
|
static int s_array[256];
|
|
|
|
|
|
|
|
if (!s_initialized)
|
|
|
|
{
|
|
|
|
InitializeDecodingLookupArray(s_array, s_vecUpper, 16, true);
|
|
|
|
s_initialized = true;
|
|
|
|
}
|
|
|
|
return s_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
NAMESPACE_END
|
2003-07-04 00:17:37 +00:00
|
|
|
|
|
|
|
#endif
|