#include "StdAfx.h" #include "yDES.h" #include ".\snregister.h" char KeyCode[7][8] = { // 密钥1; 'A','T','O','M','8','2','8','K', // 密钥2; 'A','K','C','L','8','9','8','T', // 密钥3; 'A','B','J','I','8','7','8','P', // 密钥4; 'K','U','C','G','8','6','8','E', // 密钥5; 'A','A','S','D','7','0','8','S', // 密钥6; 'W','B','V','B','9','0','8','X', // 密钥7; 'E','B','T','N','1','0','7','Z', }; CSNRegister::CSNRegister() { m_strStart.Format("%d",127); m_strCode = ""; m_strSn = ""; m_strUseTime = ""; m_strPName = ""; m_strStartTime = ""; m_strEndTime = ""; m_strLeftTime = ""; m_strCheck = ""; m_strEndof.Format("%d",13); } CSNRegister::~CSNRegister() { } BOOL CSNRegister::Load(const char *&pStrDirectroy) { CFile file; if (file.Open(pStrDirectroy, CFile::modeRead)) { CArchive ar(&file,CArchive::load); Serialize(ar); ar.Close(); file.Close(); } if ( m_strStart != "127" || m_strEndof != "13") { return FALSE; } return TRUE; } void CSNRegister::Store(const char *&pStrDirectroy) { CFile file; CFileException e; if(file.Open(pStrDirectroy, CFile::modeWrite|CFile::modeCreate, &e)) { CArchive ar(&file,CArchive::store); Serialize(ar); ar.Close(); file.Close(); } else { #ifdef _DEBUG afxDump << "File could not be opened " << e.m_cause << "\n"; #endif } } void CSNRegister::Serialize(CArchive& ar) { CObject::Serialize(ar); if(ar.IsStoring()) { ar << m_strStart; ar << m_strCode; ar << m_strSn; ar << m_strUseTime; ar << m_strPName; ar << m_strStartTime; ar << m_strEndTime; ar << m_strLeftTime; ar << m_strCheck; ar << m_strEndof; } else { ar >> m_strStart; ar >> m_strCode; ar >> m_strSn; ar >> m_strUseTime; ar >> m_strPName; ar >> m_strStartTime; ar >> m_strEndTime; ar >> m_strLeftTime; ar >> m_strCheck; ar >> m_strEndof; } } void CSNRegister::ShowCihper(char *rtext,long len) { len=(len+7)&0xfffffff8 ; int i; int p; char rtext2[1024] = {0}; unsigned char c1,c2,c3; //处理 p = 0; for (i = 0; i < len; i++) { c3 = rtext[i]; c1 = c3 >> 4; c2 = c3 & 15; if (c1 <=9 && c1 >= 0) c1=c1+'0'; if (c1 <=15 && c1 >= 10) c1=c1-10+'A'; if (c2 <=9 && c2 >= 0) c2=c2+'0'; if (c2 <=15 && c2 >= 10) c2=c2-10+'A'; rtext2[p]=c1; rtext2[p+1]=c2; p+=2; } rtext2[p] = 0; memcpy(rtext,rtext2,p+1); } void CSNRegister::HalfByteToByte(char *rin,CString &strout, long len) { int i =0; char rout[1024] = {0}; for (i=0; i='0' && rin[i] <= '9') rin[i] = rin[i]-'0'; if (rin[i]>='A' && rin[i] <= 'F') rin[i] = rin[i]-'A'+10; } for (i=0;i= 'a' && szCheck[i] <= 'z' ) { szCheck[i] = szCheck[i] - 'a' + 'A'; } } if (btype == CREATE) { m_strCheck = szCheck; } else { if (m_strCheck.Compare(szCheck) == -1) return -1; } return 0; } void CSNRegister::GetByteSum(DWORD &dwSum, CString &strSrc) { //int len = strSrc.GetLength(); for (int i = 0; i < strSrc.GetLength(); i++) { dwSum += strSrc.GetAt(i); } } BOOL CSNRegister::create_snfile(const char *szfile, char *byCode, char *bySn, char *byUseTime, char *byPName, char *byStartTime, char *byEndTime, char *byLeftTime) { encrypt(byCode,bySn,byUseTime,byPName,byStartTime,byEndTime,byLeftTime); GetCheck(CREATE); Store(szfile); return 0; } BOOL CSNRegister::modify_snfile(const char *szfile, char *byCode, char *bySn, char *byUseTime, char *byPName, char *byStartTime, char *byEndTime, char *byLeftTime) { return 0; }