|
>> 매댐덜 님이 쓰신글
VC++ 밖엔 없는데...제 실력으론 포팅이 안되네요...
소스 올려 드리면 포팅을 좀 해주실수 있는지..흑흑 급한건데..여기서 막히네요...
void CEmailChecker::Base64Decoding(CString &strSource)
{
LPSTR szDecode;
char szTemp[10];
CString strDecode = "", strTemp;
int i, j, nSize, nPadding, nSum, test;
int *pData;
m_strDecoded = "";
strSource.Remove('=');
szDecode = (LPSTR)(LPCTSTR)strSource;
nSize = strSource.GetLength();
pData = new int[nSize];
// 문자열에서 6비트씩 추출
for(i = 0 ; i < nSize ; i++)
{
if(szDecode[i] >= 'A' && szDecode[i] <= 'Z')
pData[i] = szDecode[i] - 'A';
else if(szDecode[i] >= 'a' && szDecode[i] <= 'z')
pData[i] = szDecode[i] - 'a' + 26;
else if(szDecode[i] >= '0' && szDecode[i] <= '9')
pData[i] = szDecode[i] - '0' + 52;
else if(szDecode[i] == '+')
pData[i] = 62;
else if(szDecode[i] == '/')
pData[i] = 63;
// 이 부분이 6비트로 나와야 함...
itoa(pData[i], szTemp, 2);
nPadding = 6 - strlen(szTemp);
for(j = 0 ; j < nPadding ; j++)
strDecode += '0';
strDecode += szTemp;
}
// 6비트씩으로 맞추면서 들어간 '0'패딩부분을 없애줌
nSize = strDecode.GetLength();
nPadding = nSize % 8;
if(nPadding > 0)
{
strTemp = strDecode.Left(nSize-nPadding);
nSize = strTemp.GetLength();
}
else
strTemp = strDecode;
// 다시 8비트씩으로 묶음
nSize /= 8;
for(j = 0 ; j < nSize ; j++)
{
strDecode = strTemp.Left(8);
szDecode = (LPSTR)(LPCTSTR)strDecode;
for(nSum = 0, i = 0 ; i < 8 ; i++)
{
if(szDecode[i] == '0')
continue;
nSum += (int)pow(2, 7-i);
}
m_strDecoded += (char)nSum;
test = strTemp.GetLength();
strTemp = strTemp.Right(test-8);
}
delete [] pData;
}
/*******************************************************************************
KS C 5601 에서 Quoted-printable로 인코딩된 것을 디코딩하는 함수
*******************************************************************************/
void CEmailChecker::QPDecoding(CString &strSource)
{
LPSTR szDecode;
CString strDecode = "", strTemp;
int i, nSize, nSum, nCount = 0, nValue;
m_strDecoded = "";
strSource.Remove('=');
szDecode = (LPSTR)(LPCTSTR)strSource;
nSize = strSource.GetLength();
for(nSum = 0, i = 0 ; i < nSize ; i++)
{
if(szDecode[i] >= '0' && szDecode[i] <= '9')
nValue = (int)(szDecode[i] - '0');
else if(szDecode[i] >= 'A' && szDecode[i] <= 'F')
nValue = (int)(szDecode[i] - 'A') + 10;
else
{
m_strDecoded += szDecode[i];
continue;
}
if(nCount == 0)
{
nSum += nValue * 16;
nCount++;
continue;
}
else if(nCount == 1)
{
nSum += nValue;
nCount = 0;
m_strDecoded += (char)nSum;
nSum = 0;
}
}
}
|