C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[11864] Base64 및 QP 디코딩 하는 알고리즘이나 소스 있으신분 점 알려주세요... (FAQ에서 옮겼습니다)
김성진.kark [kark] 763 읽음    2001-10-17 23:52
>> 매댐덜 님이 쓰신글

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;
        }
    }
}


+ -

관련 글 리스트
11864 Base64 및 QP 디코딩 하는 알고리즘이나 소스 있으신분 점 알려주세요... (FAQ에서 옮겼습니다) 김성진.kark 763 2001/10/17
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.