암호화 소스( 숫자 암호화,숫자 복호화)
/* ▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧
보안/암호
▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧ */
/* 숫자 암호화 */
function numEnc($str){
if($str=='null' || $str==null || $str=='') return "";
$temp= "";
$encStr= "";
$temp= strrev($str);
for($i=0; $i<strlen($temp); $i++){
$encStr .= intval($temp[$i] + $i *77) %10;
}
return $encStr;
}
암호화 스크립트 추가
$sn = $jumin1.$jumin2;
$userNum = numEnc($sn);
$sn(주민번호 암호화)
디비 쿼리 불러옴
$oDb->execute("select * from Member where userName='$name' and userNum='$userNum'");
/* 숫자 복호화 */
function numDec($encdata){
$temp = $encdata;
for($i = 0;$i < strlen($temp);$i++){
if($i==0){
$temp2=$temp[$i];
}else{
$aa = $i*77;
$temp2.=substr(intVal(10+$temp[$i]) - intVal(substr($aa,-1)),-1);
}
}
return strrev($temp2);
}
/* 로그인정보(쿠키) 암호화 */
function encrypt($txt) {
$key = "abcdefghijklmnopqrstuvwxyz";
$key_len = strlen($key);
$rot_ptr_set = 9;
$rot_ptr = $rot_ptr_set;
$tmp = "";
$txt = strrev($txt);
$txt_len = strlen($txt);
for ($i=0; $i<$txt_len; $i++) {
if($rot_ptr >= $key_len) $rot_ptr = 0;
$tmp .= $txt[$i] ^ $key[$rot_ptr];
$v = ord($tmp[$i]);
$tmp[$i] = chr(((($v << 3) & 0xf8) | (($v >> 5) & 0x07)));
$rot_ptr ++;
}
$tmp = base64_encode($tmp);
$tmp = strrev($tmp);
return $tmp;
}
/* 로그인정보(쿠키) 복호화 */
function decrypt($txt) {
$key = "abcdefghijklmnopqrstuvwxyz";
$key_len = strlen($key);
$rot_ptr_set = 9;
$rot_ptr = $rot_ptr_set;
$tmp = "";
$txt = strrev($txt);
$txt = base64_decode($txt);
$txt_len = strlen($txt);
for ($i=0; $i<$txt_len; $i++) {
if($rot_ptr >= $key_len) $rot_ptr = 0;
$v = ord($txt[$i]);
$txt[$i] = chr(((($v >> 3) & 0x1f) | (($v << 5) & 0xe0)));
$tmp .= $txt[$i] ^ $key[$rot_ptr];
$rot_ptr ++;
}
$tmp = strrev($tmp);
return $tmp;
}
/* 암호화 : mode 1 => 암호화 mode 0 => 해독 */
function usrCrypt($txt,$mode=1) {
$encrypt_key = "ruddktkfkd@~@$!@#$%^&*()raymond9493@hotmail.comabcdefghijklmnopqrstuvwxyz";
$tmp = "";
if (!$mode){
$txt = base64_decode($txt);
}
$ctr = 0;
$cnt = strlen($txt);
for ($i=0; $i<$cnt; $i++) {
if ($ctr==$cnt){
$ctr=0;
}
$tmp .= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return ($mode) ? base64_encode($tmp) : $tmp;
}