
encryptor.php 的程式原始碼如下
<?php
class Encrypt {
public $cArray = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
public $oArray = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
public function __construct() {
shuffle($this->cArray);
}
public function setcArray($s) {
for ($i = 0; $i < 26; $i++) {
$this->cArray[$i] = $s[$i];
}
}
public function toEncode($s) {
$r = Array();
$pattern = "/[a-z]/";
for ($i = 0; $i < strlen($s); $i++) {
if (preg_match($pattern, $s[$i])) {
for ($j = 0; $j < 26; $j++) {
if ($s[$i] == $this->oArray[$j]) {
array_push($r, $this->cArray[$j]);
break;
}
}
}
else {
array_push($r, $s[$i]);
}
}
return join($r);
}
public function toDecode($s) {
$r = Array();
$pattern = "/[a-z]/";
for ($i = 0; $i < strlen($s); $i++) {
if (preg_match($pattern, $s[$i])) {
for ($j = 0; $j < 26; $j++) {
if ($s[$i] == $this->cArray[$j]) {
array_push($r, $this->oArray[$j]);
break;
}
}
}
else {
array_push($r, $s[$i]);
}
}
return join($r);
}
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:encryptor.php
功能:示範 PHP 程式
作者:張凱慶
時間:西元 2012 年 11 月 */
?>您可以繼續參考
範例程式碼
相關目錄
回 PHP 入門指南
回 PHP 教材
回首頁
參考資料
http://www.php.net/
http://www.php.net/manual/en/getting-started.php
http://www.w3schools.com/php/default.asp
http://www.apache.org/
http://www.mysql.com/
http://dev.mysql.com/doc/index.html
http://www.appservnetwork.com/
沒有留言:
張貼留言