⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 base64.cpp

📁 一个用ATL开发的Base64编码控件
💻 CPP
字号:
/**********************************************************************
	Quiet Night工作室全力奉献 作者:周磊  若有问题请联系QQ:75297662
						请保留此段,尊重作者
***********************************************************************/
// Base64.cpp : CBase64 的实现
#include "stdafx.h"
#include "Base64.h"
#include ".\base64.h"


// CBase64

STDMETHODIMP CBase64::get_EnCode(BSTR* pVal)
{
	CString str;
	str = m_EnCode.data();
	*pVal = str.AllocSysString();
	return S_OK;
}

STDMETHODIMP CBase64::put_EnCode(BSTR newVal)
{
	return S_OK;
}

STDMETHODIMP CBase64::get_DeCode(BSTR* pVal)
{
	CString str;
	str = m_DeCode.data();
	*pVal = str.AllocSysString();
	return S_OK;
}

STDMETHODIMP CBase64::put_DeCode(BSTR newVal)
{
	return S_OK;
}

void CBase64::EnBase64()
{
    string::size_type  i;
    char c;
    string::size_type  len = m_EnCode.length();
    string ret;
	m_DeCode.clear();

	m_DeCode.reserve(len * 2);

    for (i = 0; i < len; ++i)
    {
        c = (m_EnCode[i] >> 2) & 0x3f;
        m_DeCode.append(1, Base64Table[c]);
        c = (m_EnCode[i] << 4) & 0x3f;
        if (++i < len)
            c |= (m_EnCode[i] >> 4) & 0x0f;

        m_DeCode.append(1, Base64Table[c]);
        if (i < len)
        {
            c = (m_EnCode[i] << 2) & 0x3f;
            if (++i < len)
                c |= (m_EnCode[i] >> 6) & 0x03;

            m_DeCode.append(1, Base64Table[c]);
        }
        else
        {
            ++i;
            m_DeCode.append(1, fillchar);
        }

        if (i < len)
        {
            c = m_EnCode[i] & 0x3f;
            m_DeCode.append(1, Base64Table[c]);
        }
        else
        {
            m_DeCode.append(1, fillchar);
        }
    }
}

void CBase64::DeBase64()
{
	string::size_type  i;
    char c;
    char c1;
    string::size_type  len = m_DeCode.length();

	m_EnCode.clear();
	m_EnCode.reserve(len);

    for (i = 0; i < len; ++i)
    {
        c = (char) DecodeTable[(unsigned char)m_DeCode[i]];
        ++i;
        c1 = (char) DecodeTable[(unsigned char)m_DeCode[i]];
        c = (c << 2) | ((c1 >> 4) & 0x3);
        m_EnCode.append(1, c);
        if (++i < len)
        {
            c = m_DeCode[i];
            if (fillchar == c)
                break;

            c = (char) DecodeTable[(unsigned char)m_DeCode[i]];
            c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
            m_EnCode.append(1, c1);
        }

        if (++i < len)
        {
            c1 = m_DeCode[i];
            if (fillchar == c1)
                break;

            c1 = (char) DecodeTable[(unsigned char)m_DeCode[i]];
            c = ((c << 6) & 0xc0) | c1;
            m_EnCode.append(1, c);
        }
    }
}
STDMETHODIMP CBase64::DeCode64(BSTR str)
{
	CString newVal;
	newVal = str;
	m_DeCode = newVal;
	DeBase64();
	put_DeCode(((CString)(m_EnCode.data())).AllocSysString());
	put_EnCode(((CString)(m_DeCode.data())).AllocSysString());
	FireViewChange();
	return S_OK;
}

STDMETHODIMP CBase64::EnCode64(BSTR str)
{
	CString newVal;
	newVal = str;
	m_EnCode = newVal;
	EnBase64();
	put_DeCode(((CString)(m_DeCode.data())).AllocSysString());
	put_EnCode(((CString)(m_EnCode.data())).AllocSysString());
	FireViewChange();
	
	return S_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -