1. 2010. 2. 8. 10:38 프로그래밍 언어/C++
아이디 / 패스워드를 노출 시키지 않기 위한 C++ 코드.

void *Encrypt[16]={new char, new char, new char, new char, new char, new char, new char, new char, new char, new char, new char, new char, new char, new char, new char, new char,};
char *PassEncrypt;
/*
PassEncrypt : " 'char *'에서 'char'(으)로 변환할 수 없습니다."
의 문제때문에 사용함. 빠른 처리를 하려면 인라인 어샘블리어 코딩을 사용.
32비트의 포인터는 4바이트, 64비트 8바이트 신경 써줘야한다.
C++ 코드 아래에 예문 포함.
아래의 ^ 0 은 다른 값으로 바꿔주고, 되도록 상수대신 변수를 사용하는 것이 강력합니다.
char = byte 와 같고, 값을 넘겨받을 곳 에서는 다시 같은방법으로 xor 연산을 하면 원래 값이 나옵니다.
*/

char input='a';
//xor 값은 0~255.  xor 비트연산 : 같으면0 다르면1
/*input*/
PassEncrypt=(char*)Encrypt[0];//a[0] 포인터 옮김.
PassEncrypt[0]=input ^ 0;
input='b';
PassEncrypt=(char*)Encrypt[1];//a[1] 포인터 옮김.
PassEncrypt[0]=input ^ 0;
/*output*/
char *output=new char[2];//잠시 사용
PassEncrypt=(char*)Encrypt[0];
output[0]=PassEncrypt[0];
PassEncrypt=(char*)Encrypt[1];
output[1]=PassEncrypt[0];
//output 데이터를 사용하고 지운다 (delete).
delete output;//해제

_asm{
 MOV EAX,[Encrypt]
 MOV BL,byte Ptr ds:[EAX]//첫문자 꺼냄
 MOV byte Ptr ds:[EAX],BL//첫문자 기록
 MOV EAX,[Encrypt+4]
 MOV BH,byte Ptr ds:[EAX]//두번쨰 문자 꺼냄
 MOV byte Ptr ds:[EAX],BH//두번쨰 문자 기록
}

이것이 끝인데, C++ 코드는 너무 복잡한 형태를 가지는것이 흠입니다.
처음부터 어샘블리어를 이용할수도 있고,
식이 복잡하다면 같이 혼용 하여 사용도 가능함으로, 상황에 맞춰서 사용하는 것이  좋습니다.

Document by tanny tales
Posted by Nightly Luna
,
® © Tanny Tales
/ rss