<?php

	Class AnYue_Abm{


		function MD6 ($str){

			$key = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=:;,<.>/?|\\"\'`~[]{} '."\r\n";

			return $key{floor ($str)}.$key{strlen ($str)}.$key{$str{5}}.MD5 ($str).$str{floor (MD5 ($str))}.$key{floor (MD5 ('1_AnYue_'.$str))};

		}




		function Get_aokng ($pass){

			preg_match_all ('/[0-9]+/',$this -> MD6 ($pass),$md5);

			foreach ($md5[0] as $value){

				$key += $value;

			}

			do {

				$key /= 3;

			}while ($key > 300);

			return floor ($key);

		}





		function Job ($str,$pass,$type=0){


			$this -> aokng = $this -> Get_aokng ($pass);


			$md5 = $this -> MD6 ($pass);

			for ($i=0;$i<strlen ($md5);$i++){

				$arr[] = $md5{$i};

			}

			$md5 = array_values (array_unique ($arr));

			$key = str_replace ($md5,'','0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=:;,<.>/?|\\"\'`~[]{} '."\r\n");

			$len = strlen ($key);
			$arr = array ();
			for ($i=0;$i<$len;$i++){
				$arr[] = $key{$i};
			}


			$arr = (floor ($pass)) ? array_merge ($md5,$arr) : array_merge ($arr,$md5);


			$len = strlen ($str);

			switch ($type){

				Case 0;

					$arr = array_flip ($arr);
					for ($i=0;$i<$len;$i++){

						if ($arr[$str{$i}]){ //判断是否为汉字
							$var = ($arr[$str{$i}]==Null) ? $str{$i} : $arr[$str{$i}];
						}else{
							$var = ord ($str{$i}) + $this -> aokng;
						}

						$rtn .= $var.', ';
					}

					$rtn = substr ($rtn,0,strlen($rtn)-2);

					return '{ '.$rtn.' }';

				break;



				default;


					$str = str_replace (array ('{ ',' }'),'',$str);

					$str = explode (', ',$str);

					foreach ($str as $value){

						if ($arr[$value] != Null){

							$rtn .= $arr[$value];

						}else{

							$rtn .= chr ($value - $this -> aokng);

						}

					}

					return $rtn;

				break;

			}


		}



	}

