암호화라고 거창하게 써놨지만, 사실 별거 없죠
걍 특정/불특정 문자열을 꼬아놓은다 랄까...
여튼, 전 제가 원하는 임의의 문자(숫자)를 곱하는 형식을 취했습니다.
CFile f;
CFileException e;
CString fileName, strHost;
UpdateData(TRUE);
char *p_host = (LPSTR)(LPCSTR)m_strHost; // 에디트 박스에 쳐박은 호스트주소입니다.
char key = 243;
int i = 0;
for( i = 0; i < strlen(p_host); i++){ // 한글자 마다 key 값을 곱합니다 (-_-) 제곱이랄까....
p_host[i] = p_host[i] ^ key;
}
strHost.Format("%s\r\n", p_host);
char szCurDir[256] = {NULL, };
GetCurrentDirectory(256, szCurDir);
strcat(szCurDir, "\\config.ini");
fileName=szCurDir;
if( !f.Open( fileName, CFile::modeCreate | CFile::modeWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
else
{
f.SeekToEnd();
f.Write(strHost , strlen(strHost)); // 저장합니다.
f.Close();
}
끝.
읽어올때도 마찬가지로 하나씩 읽어오는 형태를 취합니다.
char szCurDir[256] = {NULL, };
CString fileName, strHost;
GetCurrentDirectory(256, szCurDir);
strcat(szCurDir, "\\config.ini");
fileName=szCurDir;
char load_data[256] = { 0 ,};
char key = 243;
int i = 0;
FILE *p_file = fopen(fileName, "rb");
if(p_file != NULL){
fread(load_data, 256, 1, p_file);
fclose(p_file);
}
int length = strlen(load_data);
int j = 0, k=0;
for(i = 0; i < length; i++){
load_data[i] = load_data[i] ^ key;
}
m_strHost = load_data;
if(bUpdate) UpdateData(FALSE);
끝...
| 태그 : | 개발관련 |
