?? dblock.cpp
字號:
// DBlock.cpp: implementation of the CDBlock class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DBlock.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDBlock::CDBlock(vlong n)
{
m_uBits = 0;
if(n != vlong(0))
{
m_n = n ;
m_uBits = m_n.m_pValue->GetBits()-1; //單個明文塊的最大位數
}
m_pMBuf = NULL;
}
CDBlock::~CDBlock()
{
if(m_pMBuf != NULL)
delete []m_pMBuf;
}
int CDBlock::MToDigist(unsigned char* pMBuf,unsigned uLen)
{
m_pMBuf = new unsigned char[2*uLen];
if(pMBuf == NULL || uLen == 0)
return 1;
unsigned off = 0 , i = 0,t1 ;
unsigned char *pMov = pMBuf;
vlong blk;
t1 = i;
while(i < uLen)
{
t1 = i;
t1 += (m_uBits + off)/8;
if(t1 >= uLen)
break;
pMov= pMBuf + i;
blk = DigitToVLInt(pMov,off,m_uBits);
unsigned d = blk;
i = t1;
off = (m_uBits + off)%8;
};
pMov= pMBuf + i;
unsigned x = ((uLen - i)*8-off) ;
blk = DigitToVLInt(pMov,off,x);
return 0;
}
//----------------------------------------------------------
vlong CDBlock::DigitToVLInt(unsigned char *pBuf, unsigned uOff, unsigned uBits)
{
vlong theResult;
unsigned char * pMove;
unsigned short Tmp;
unsigned char * pTmp;
unsigned uR;
uR = 0;
pMove = pBuf;
pTmp = (unsigned char*)&Tmp;
while( (uR + 16) < uBits)
{
*pTmp = (*pMove)<<uOff;
*pTmp |= (*(++pMove))>>(8-uOff);
*(pTmp+1) = (*pMove)<<uOff;
*(pTmp+1) |= (*(++pMove))>>(8-uOff);
theResult.m_pValue->Append(Tmp);
uR += 16;
}
Tmp = 0;
if((uR+8) < uBits)
{
*pTmp = (*pMove)<<uOff;
*pTmp |= (*(++pMove))>>(8-uOff);
uR+=8;
pTmp++;
}
unsigned char uch;
if((uOff+(uBits - uR))<8)
{
uch = *pMove;
ushort x= (8 - uBits + uR - uOff);
uch &= ((0xff>>x)<<(x+uOff));
*pTmp = uch<<uOff;
}else{
*pTmp = (*pMove<<uOff);
uch = *(pMove+1);
uch &= (0xff <<(16 - uBits + uR - uOff));
*pTmp = (uch >>(8- uOff));
}
uR += ((uBits+uOff)%8);
theResult.m_pValue->Append(Tmp);
theResult.m_pValue->ReArray(); //整理數據
return theResult;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號