
encrypt.js 的程式原始碼如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | function Encrypt() { this .code = "abcdefghijklmnopqrstuvwxyz" .split( "" , 26); var i = this .code.length; while (i) { var j = parseInt(Math.random() * i); var x = this .code[--i]; this .code[i] = this .code[j]; this .code[j] = x; } this .alph = "abcdefghijklmnopqrstuvwxyz" .split( "" , 26); } Encrypt.prototype.showCode = function () { return this .code.join( "" ); } Encrypt.prototype.setCode = function (c) { this .code = c.split( "" , 26); } Encrypt.prototype.toEncode = function (str) { var result = "" ; var i = 0; var len = str.length; while (i < len) { var regExp = /^[a-z]+$/; if (regExp.test(str[i])) { var j = this .alph.indexOf(str[i]) result += this .code[j]; } else { result += str[i]; } i++; } return result; } Encrypt.prototype.toDecode = function (str) { var result = "" ; var i = 0; var len = str.length; while (i < len) { var regExp = /^[a-z]+$/; if (regExp.test(str[i])) { var j = this .code.indexOf(str[i]); result += this .alph[j]; } else { result += str[i]; } i++; } return result; } /* 《程式語言教學誌》的範例程式 檔名:encrypt.js 功能:示範 JavaScript 程式 作者:張凱慶 時間:西元 2012 年 12 月 */ |
您可以繼續參考
範例程式碼
相關目錄
回 JavaScript 入門指南
回 JavaScript 教材
回首頁
參考資料
http://www.ecma-international.org/publications/standards/Ecma-262.htm
http://www.w3schools.com/JS/default.asp
http://www.tutorialspoint.com/javascript/index.htm
http://www.w3.org/standards/techs/dom#w3c_all
https://developer.mozilla.org/en-US/docs/JavaScript
https://developer.mozilla.org/en/DOM
http://msdn.microsoft.com/en-us/ie/default
http://developer.apple.com/devcenter/safari/index.action
http://dev.chromium.org/
http://dev.opera.com/
沒有留言:
張貼留言