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

📄 serialnum.cpp

📁 本程序是VC为平台开发的股票资讯系统
💻 CPP
字号:
// SerialNum.cpp : implementation file
//

#include "stdafx.h"
#include "SerialNum.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//static char LET[17] = _T("HWIMVNPLQOJRKSTU");
static char LET[17] =   _T("HIJKLMNOPQRSTUVW");

static char DecodeKey[7][12] = {
	_T("http://www"),_T("http://"),
	_T("href=&</a>@"),_T("href"),
	_T(".com.cn"),_T(".com"),_T(".cn")
    };

static char SecretKey[7][4] = {
	_T("!#1"),_T("!#2"),_T("!#3"),_T("!#4"),
	_T("!#5"),_T("!#6"),_T("!#7")
	};

/////////////////////////////////////////////////////////////////////////////
// CSerialNum

CSerialNum::CSerialNum()
{
}

CSerialNum::~CSerialNum()
{
}

/////////////////////////////////////////////////////////////////////////////
// CSerialNum message handlers

CString CSerialNum::Encrypt(long sSN)
{
	CString pass;
	char *ch,*nch;
	int i,len;
	pass.Format(_T("%x"),sSN);
	pass.MakeUpper();
	len = pass.GetLength();
	ch = new char[len];
	nch = new char[len];
	for(i=0;i<len;i++){
		ch[i] = pass.GetAt(i);
		if(ch[i]<'A')
			nch[i] = LET['9' - ch[i]];
		else
			nch[i] = LET[10 + 'F' - ch[i]];
	}
	pass = _T("");
	for(i=0;i<len;i++){
		pass += ch[i]; 
		pass += nch[len-i-1];
	}

	delete ch;
	delete nch;
	return pass;
}

CString CSerialNum::GetDate()
{
	CString reg,strdate;
	int len,i;
	char ch[8],nch[8],tmpch;
	reg = GetReg();
	long da = 0,bas = 1;
	if(reg.IsEmpty())
		return reg;

	len = reg.GetLength();
	if(len != 14)
		return _T("");
	
	len = len/2;
	for(i=0;i<len;i++){
		ch[i] = reg.GetAt(2*i);
		nch[i] = reg.GetAt(2*(len-i-1)+1);
		if(ch[i]<'A')
			tmpch = LET['9' - ch[i]];
		else
			tmpch = LET[10 + 'F' - ch[i]];
		if(tmpch != nch[i])
			break;
	}
	if(i<len)
		return _T("");

	for(i=0;i<len;i++){
		tmpch = ch[len-i-1];
		if(tmpch<'A')
			da += (tmpch - '0')*bas;
		else
			da += (tmpch - 'A' + 10)*bas;
		bas *= 16;
	}

	strdate.Format(_T("%ld"),da);
	return strdate;
}

int CSerialNum::SetReg(LPCTSTR RegKey,int flag)
{
	char keyName[256];
	HKEY hkRoot,hKey;
	char Value[80];
	long cb;
	cb=sizeof(Value);
    int i;
	for(i=0;i<256;i++)
		keyName[i]=0;
	sprintf(Value,_T("%s"),RegKey);
	if(flag)
		strcpy(keyName,_T("NSCSNum"));
	else
		strcpy(keyName,_T("Fctsoly"));
	if (RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkRoot)==ERROR_SUCCESS){
		if (RegOpenKey(hkRoot,(LPSTR)keyName,&hKey)==ERROR_SUCCESS){
				RegSetValue(hKey,NULL,REG_SZ,Value,cb);
				RegCloseKey(hKey);
				RegCloseKey(hkRoot);
				return 1;
		}else{
			if (RegCreateKey(hkRoot,keyName,&hKey)==ERROR_SUCCESS){
				RegSetValue(hKey,NULL,REG_SZ,Value,cb);
				RegCloseKey(hKey);
				RegCloseKey(hkRoot);
				return 1;
			}
		}
	} 
    RegCloseKey(hkRoot);
	
	return 0;
}

CString CSerialNum::GetReg(int flag)
{
	CString strResult;
	// TODO: Add your dispatch handler code here
	char keyName[256];
	HKEY hkRoot;
	char szValue[80];
	long cb;
    int i;
	for (i=0;i<256;i++) 
		keyName[i]=0;
	strResult=_T("");
	if(flag)
		strcpy(keyName,_T("NSCSNum"));
	else
		strcpy(keyName,_T("Fctsoly"));
	if (RegOpenKey(HKEY_CLASSES_ROOT,NULL,&hkRoot)==ERROR_SUCCESS){
		cb=sizeof(szValue);
		if (RegQueryValue(hkRoot,(LPSTR)keyName,szValue,&cb)==ERROR_SUCCESS){
			strResult=szValue;
			return strResult;
		}
	}
    RegCloseKey(hkRoot);

	return _T("");
}

CString CSerialNum::Eencrypt(LPCTSTR lpSource)
{
	CString temp,str;
	str = lpSource;
    unsigned code;
    int i,n,l,pos;
	for(i = 0;i<7;i++){
		pos = str.Find(DecodeKey[i]);
        if (pos != -1) 
			str.Replace(DecodeKey[i],SecretKey[i]);
    }
    char cc;
	i = 0;
	n = 1;
    l=str.GetLength();
    while(i < l) {
		code=(unsigned)str[i];
        if (n == 5) n = 1;
		code=code-n;
		cc=(char)code;
		temp=temp+cc;
        i++;
        n++;
    }

	temp.Replace(_T("\\"),_T("\\\\"));
	temp.Replace(_T("|"),_T("\\7c"));
	return temp;
}

CString CSerialNum::Decode(LPCTSTR lpSource)
{
	CString temp,str;
    unsigned code;
    int i,n,l,pos;
    char cc;
	str = lpSource;
//	str.Replace(_T("\\7c"),_T("|"));
	pos = str.Find(_T("\\7c"));
	while(pos != -1)
	{
		if(pos != 0){
			cc = str[pos - 1];
			if(cc != '\\'){
				str.Delete(pos,3);
				str.Insert(pos,'|');
			}
		}
		else{
			str.Delete(pos,3);
			str.Insert(pos,'|');
		}
		pos = str.Find(_T("\\7c"),pos + 1);
	}

	str.Replace(_T("\\\\"),_T("\\"));
	l = str.GetLength();
	i = 0;
	n = 1;
    while(i < l) {
		code=(unsigned)str[i];
        if (n == 5) n = 1;
		code=code+n;
        cc=(char)code;
        temp=temp+cc;
        i++;
        n++;
    }
    str = temp;
    for(i = 0;i<7;i++){
		pos = str.Find(SecretKey[i]);
        if (pos != -1) 
			str.Replace(SecretKey[i],DecodeKey[i]);
    }

    return str;
}

⌨️ 快捷键说明

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