📄 global.cpp
字号:
// Global.cpp: implementation of the CGlobal class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ShoolCard.h"
#include "Global.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGlobal::CGlobal()
{
}
CGlobal::~CGlobal()
{
}
BYTE CGlobal::CalMoneyCheck(CByteArray *pBA, short ALow, short AHigh)
{
short int i;
int mTotal;
//============================
mTotal = 0x13;
for(i=ALow;i<=AHigh;i++)
{
mTotal = mTotal + pBA->GetAt(i);
}
return mTotal % 0xff;
}
BYTE CGlobal::CalCheck(CByteArray *pBA, short ALow, short AHigh)
{
BYTE mByte;
short int i;
mByte = 0xd2;
for(i=ALow;i<=AHigh;i++)
{
mByte = mByte ^ pBA->GetAt(i);
}
return mByte;
}
BYTE CGlobal::Encrypt(BYTE b)
{
BYTE mByte3,mByte6;
//取第三位
mByte3 = b & 0x08;
//第三位移动第六位
mByte3 = mByte3 << 3;
//取第六位
mByte6 = mByte6 & 0x40;
//第6位移动第3位
mByte6 = mByte6 >> 3;
//第6位\第3位交换位置
b = b | mByte3;
b = b | mByte6;
//和$5d异或
return (b ^ 0x5d);
}
BYTE CGlobal::AntiEncrypt(BYTE b)
{
BYTE mByte3,mByte6;
//和$5d异或
b = b ^ 0x5d;
//取第三位
mByte3 = b & 0x08;
//第三位移动第六位
mByte3 = mByte3 << 3;
//取第六位
mByte6 = b & 0x40;
//第6位移动第3位
mByte6 = mByte6 >> 3;
//第6位\第3位交换位置
b = b | mByte3;
b = b | mByte6;
return b;
}
bool CGlobal::IsArrayValid(CByteArray *pBA)
{
int i,mHigh;
BYTE mByte ;
//检查报文头部
if(pBA->GetAt(0) != 0x0f ||
pBA->GetAt(1) != 0xf0)
return false;
//mLen为AByteAry最后
mHigh = pBA->GetSize() -1;
//将$d2和所有报文作异或
mByte = 0xd2;
for (i=0;i<= mHigh-1;i++)
{
mByte = mByte ^ pBA->GetAt(i);
}
//检查校验位
if (mByte != pBA->GetAt(mHigh)) return false;
else return true;
}
short int CGlobal::ComStrToInt(CString AComStr)
{
CString mstr;
mstr = AComStr.Mid(3,AComStr.GetLength());
return atoi(mstr);
}
CString CGlobal::EncryptStr(CString AStr)
{
return AStr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -