<?
/*
	[SueamCMS] (C)2009-2010 ZMRNet Studio
	function.php by 2009-10-15 zmrnet
*/
function caesar_encrypt($data, $key){
	$cipher = '';
	$dlen = strlen($data);
	$klen = strlen($key);
	if(!$dlen||!$klen)return $cipher;
	for($i=0,$j=0;$i<$dlen;$i++,$j++){
		if($j>=$klen)$j -= $klen;
		$d = ord($data[$i])-32;
		$k = ord($key[$j])-32;
		$c = $d + $k;
		if($c>=95)$c-=95;
		$cipher .= chr($c+32);
	}
	return $cipher;
}
function caesar_decrypt($cipher, $key){
	$data = '';
	$clen = strlen($cipher);
	$klen = strlen($key);
	if(!$clen||!$klen)return $data;
	for($i=0,$j=0;$i<$clen;$i++,$j++){
		if($j>=$klen)$j -= $klen;
		$c = ord($cipher[$i])-32;
		$k = ord($key[$j])-32;
		$d = $c - $k;
		if($d<0)$d+=95;
		$data .= chr($d+32);
	}
	return $data;
}

function array_find($arr, $key, $val){
	foreach($arr as $k => $v){
		if($v[$key]==$val){
			return $k;
		}
	}
	return -1;
}

function refresh($url = ''){
	$res = '<meta http-equiv="refresh" content="0;url='.$url.'">';
	return $res;
}

function checkuser($u){
	$u = strtolower($u);
	$t = ' 0123456789abcdefghigklmnopqrstuvwxyz._-';
	$i = strlen($u);
	while($i--)
		if(!strpos($t,$u[$i]))
			return false;
	return true;
}

function showpage($page, $page_cnt){
	$page_ended = $page + 5;
	$page_start = $page - 5;
	if($page_ended>$page_cnt){
		$page_ended=$page_cnt;
		$page_start = $page_ended - 10;
	}
	if($page_start<0) $page_start=0;

	$page_str = '';
	if($page==1){
		$page_str .= '首页 上一页 ';
	}else{
		$page_str .= '<a href="1.html">首页</a> ';
		$page_str .= '<a href="'.($page-1).'.html">上一页</a> ';
	}
	for($i=$page_start;$i<$page_ended;$i++){
		$page_str .= '<a href="'.($i+1).'.html">'.($i+1).'</a> ';
	}
	if($page_cnt&&($page!=$page_cnt)){
		$page_str .= '<a href="'.($page+1).'.html">下一页</a> ';
		$page_str .= '<a href="'.$page_cnt.'.html">尾页</a>';
	}else{
		$page_str .= '下一页 尾页';
	}
	return $page_str;
}
?>