📄 myencrptpublic.cpp
字号:
#include "stdafx.h"
#include "MyEncrptPublic.h"
#include "Winsock2.h"
#include "math.h"
#pragma comment(lib, "Ws2_32")
void EncryptBuffer(char *pbuffer,char *pout,int nStartPos,int nEnlen,int nBufferDataSize,
unsigned char *pKey,int nKeyLen)
{
register int i,j=0;
register int nDataSize=min(nEnlen,nBufferDataSize-nStartPos);
char *p=pbuffer+nStartPos;
if(nDataSize<=0) return;
for(i=0;i<nDataSize;i++){
*pout=*p^pKey[j];
j++;
p++;
pout++;
if(j>=nKeyLen)
j=0;
} // end i
}
void MMCopy(char *pdst,char *psrc,int k)
{
__asm{
//save the registers
push eax
push ebx
push ecx
push edx
mov ecx ,k
mov ebx,pdst
mov edx,psrc
mov eax ,0
copyloop:
mov al,[edx]
mov [ebx],al
add ebx,1
add edx,1
//add eax,1
dec ecx
jne copyloop
//restore the registers
ExitLine:
pop edx
pop ecx
pop ebx
pop eax
// ret
}
// TRACE("");
}
void EncryptBuffer_Asm_(char *pbuffer,int nStartPos,int nEnlen,int nBufferDataSize,
unsigned char *pKey,int nKeyLen)
{
int nDataSize=min(nEnlen,nBufferDataSize-nStartPos);
__asm{
//save the registers
push eax
push ebx //data buffer
push ecx // datasize
push edx //keylen
push esi // pkey
//push epi
mov ecx,nDataSize //缓存计数器
mov edx,nKeyLen // 密钥计数器
mov ebx,pbuffer
add ebx,nStartPos // databuffer
mov esi ,pKey // key
Encrptyloop:
mov al,[ebx]
// mov ah,[esi]
xor al,[esi]
mov [ebx],al // 完成数据单元加密
//inc ebx
//inc esi
add ebx,1
add esi,1
//dec edx
sub edx,1
jne continueNext
mov edx ,nKeyLen
mov esi,pKey
continueNext:// dec ecx
sub ecx,1
jne Encrptyloop
//restore the registers
ExitLine:
pop esi
pop edx
pop ecx
pop ebx
pop eax
// ret
}
// TRACE("sd");
}
void EncryptBuffer_Asm(char *pbuffer,char *poutbuffer,
int nStartPos,int nEnlen,int nBufferDataSize,
unsigned char *pKey,int nKeyLen)
{
int nDataSize=min(nEnlen,nBufferDataSize-nStartPos);
if(!poutbuffer)
poutbuffer=pbuffer;
__asm{
//save the registers
push eax
push ebx //data buffer
push ecx // datasize
push edx //keylen
push esi // pkey
push edi // Poutbuffer
//push epi
mov ecx,nDataSize //缓存计数器
mov edx,nKeyLen // 密钥计数器
mov ebx,pbuffer
add ebx,nStartPos // databuffer
mov esi ,pKey // key
mov edi ,poutbuffer // outbuffer
Encrptyloop:
mov al,[ebx]
// mov ah,[esi]
xor al,[esi]
mov [edi],al // 完成数据单元加密
//inc ebx
//inc esi
add ebx,1
add esi,1
add edi,1
//dec edx
sub edx,1
jne continueNext
mov edx ,nKeyLen
mov esi,pKey
continueNext:// dec ecx
sub ecx,1
jne Encrptyloop
//restore the registers
ExitLine:
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
// ret
}
// TRACE("sd");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -