11-1 ���}�O�@

ºô¸ô¬OµL»·¥±©¡ªº¡A¦ý¬O¦b¯S®í±¡ªp¤U¡A¦³®É­ÔÁÙ¬O§Æ±æ¹ï¨Ï¥ÎªÌ¶i¦æ¹LÂo¡A¥i¥H¨Ï¥Îªº¤èªk¦³«Ü¦hºØ¡A¨Ò¦p¡G ¨ä¤¤¨Ï¥Î±K½X¨Ó«OÅ@§Aªººô­¶¬O³Ì±`¨£ªº¤è¦¡¡C

­Y­n¹ïºô­¶¶i¦æÄY±KªººÞ¨î¡A¤@©w¥²¶·±q¦øªA¾¹ºÝªºµ{¦¡½XµÛ¤â¡C¦ý¦pªGºô­¶ªº¾÷±K©Ê¤£¬O¤Ó°ª¡]¨Ò¦p­Ó¤Hªº¥Í¬¡·Ó¡B³q°T¿ýµ¥¡^¡A¥u¬O§Æ±æ¥~¦æ¤H¤£±o¨äªù¦Ó¤J¡A©Î¬O¤£Åý·j´M¤ÞÀº§ä¨ì§Aªººô­¶¡A ¨º»ò´N¥i¥H±q«È¤áºÝªº JavaScript ¨Ó¹F¨ì¥H±K½X«OÅ@ºô­¶ªº¥Øªº¡C¤@¯ë¦Ó¨¥¡A¨Ï¥Î JavaScript ¨Ó«OÅ@ºô­¶¡A¥i¥HÁ×±¼ªº¨Ï¥ÎªÌ¦p¤U¡G

¦ý¥²¶·ª`·Nªº¬O¡A¥H«È¤áºÝªº JavaScript ¨Ó¶i¦æªº±K½X«OÅ@¡A¬O¥u¯à¨¾§b¥Ê¡A¤£¯à¨¾°ª¤â¡A¦]¦¹¹ï©óÁô±K©Ê·¥°ªªº¸ê®Æ¡A¤´À³¥H¦øªA¾¹ºÝªºµ{¦¡½X¨Ó«OÅ@¡C¤@¯ë¦Ó¨¥¡A­Y¨Ï¥Î JavaScript¡A¨Ã¦õ¥H¦øªA¾¹ºÝªº±K½X«OÅ@¡A´N¥i¥H¹F¨ì¬Û­¼¬Û¥[ªº®ÄªG¡C¦³Ãö©ó¦¹ºØ¨Ï¥Î«È¤áºÝ¤Î¦øªA¾¹ºÝªºµ{¦¡¨Ó¶i¦æÁp¤â¨¾¿mªº²Ó¸`¡A·|¦b«áÄò³¹¸`¤¤»¡©ú¡C

­º¥ý§Ú­Ì¨Ó¬Ý¤@­Ó³Ì²³æªº½d¨Ò¡G

Example¡]password01.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A§A¥²¶·¿é¤J¥¿½Tªº±K½X¡A¤~¯à³s¨ì¡u¯µ±KÀɮסvºô­¶¡A½Ð¸Õ¸Õ¬Ý¡C·íµM¡A¥u­n§A¦³­@¤ßÀˬd JavaScript ªº­ì©l½X¡A´N¥i¥Hª¾¹D¦¹ºô­¶ªº±K½X¡C¦U¦ìŪªÌ½Ð¦Û¦æÀ˾\¤W­zºô­¶ªº­ì©l½X¡A¨Ã§ä¥X±K½X¡C

§Ú­Ì¦A¬Ý¤@­Óµy·L½ÆÂø¤@¨Çªº½d¨Ò¡A¥Î¨ì¤F¡u±b¸¹¡v¥[¡u±K½X¡vªº¨â¬q¦¡»{ÃÒ¡G

Example¡]password02.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A·í§A«ö¤U¡u¯µ±KÀɮסv«á¡A§A¥²¶·¿é¤J¥¿½Tªº±b¸¹©M±K½X¡A¤~¯à³s¨ì¬ÛÃöªººô­¶¡A½Ð¸Õ¸Õ¬Ý¡C¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]password02.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>¥H±K½X«OÅ@ªººô­¶¡G²³æªº¨â¬q¦¡±K½X«OÅ@</h2>
<hr>

<script>
function password() {
	username="";
	passwd="";
	while (username=="")		// Get the user's name
		username=prompt('½Ð¿é¤J¤j¦W¡G', "");
	if ((username!="Roger") && (username != "Jang")) {
		alert("§A¤£¬O§Úªº¥D¤H¡A¤£­ã¶i¤J¡I")
		return;
	}
	while (passwd=="")		// Get the password
		passwd=prompt(username+"¡A±z¦n¡I\n"+"½Ð¿é¤J±K½X¡G", username+"ªº±K½X");
	if (passwd!="cs3431")
		alert("±K½X¿ù»~¡A¤£­ã¶i¤J¡I")
	else
		myWin=open("found01.htm", "displayWindow", "width=600,height=200,status=yes,toolbar=yes,location=yes,resizable=yes,menubar=yes,scrollbars=yes");
}
</script>
<a href="javascript:password()">¯µ±KÀÉ®×</a>

<hr>
</body>
</html>

¤W­z¨â­Ó½d¨Ò¡A«Ü®e©ö±q JavaScript ªº­ì©l½X´N¬Ý¥X¯µ±Kºô­¶ªººô§}¡A¥t¤@ºØ¤èªk¡A«h¬O±N¿é¤J±K½X¶i¦æ½s½X¡A¥H±o¨ì¯µ±Kºô­¶ªººô§}¡A¨Ò¦p¡G

Example¡]password03.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A§A¥²¶·¿é¤J¥¿½Tªº±K½X¡A¤~¯à³s¨ì¬ÛÃöªººô­¶¡A½Ð¸Õ¸Õ¬Ý¬O§_¯à¥Ñ¤W­z½d¨Òªº­ì©lÀÉ¡]¦p¤U¡^¨Ó°»´ú¥X¯µ±Kºô­¶ªººô§}¡G

­ì©lÀÉ¡]password03.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>¥H±K½X«OÅ@ªººô­¶¡G½s½X¦¡ªº±K½X«OÅ@</h2>
<hr>

<script>
function testEncode(form) {
	seed = 1;
	newStr = encode(form.passwordField.value, seed)
	document.location = newStr+".htm"
}
function encode(inStr, seed){
	seed = parseInt(seed);
	var char, index, newIndex, outStr="";
	var refStr="0123456789abcdefghijklmnopqrstuvwxyz._~ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (var i=0; i<inStr.length; i++) {
		char = inStr.substring(i, i+1)
		index = refStr.indexOf(char)
		newIndex = index^seed;		// ^: bitwise xor operator
		outStr += refStr.substring(newIndex, newIndex+1);
	}
	return (outStr)
}
</script>
<form NAME="testform" onSubmit=false;>
½Ð¿é¤J¶Q»«±K½X¡G<input type="password" NAME="passwordField">
<input type="button" NAME="button" Value="¬d®Ö" onClick="testEncode(this.form)">
<font color=white>cs3431</font>
</form>


<hr>
</body>
</html>

¥Ñ¤W­z­ì©l½X¡A´Nºâ§Ú­Ì¬Ý±oÀ´ JavaScript µ{¦¡½X¡A¤]µLªk¬Ý¥X±K½X©Î¬O¯µ±Kºô­¶ªººô§}¡C§Ú­Ì¥i¥H±N½s½Xªº¹Lµ{¼g¦¨¤@­Óºô­¶¡G

Example¡]passwordEncoding01.htm¡^¡G

¦b¤W­z½d¨Ò¤¤¡A§A¥u­n¶ñ¤J¿é¤J¦r¦ê¡A¦A³]©w½s½X°Ñ¼Æ¡A´N¥i¥H¬Ý¨ì½s½Xªºµ²ªG¡C¤W­z½d¨Òªº­ì©lÀɦp¤U¡G

­ì©lÀÉ¡]passwordEncoding01.htm¡^¡G¡]¦Ç¦â°Ï°ì«ö¨â¤U§Y¥i«þ¨©¡^
<html>
<head>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
</head>

<body>
<h2 align=center>¥H±K½X«OÅ@ªººô­¶¡G¦p¦ó´úÅç½s½X¦¡ªº±K½X«OÅ@</h2>
<hr>

<script>
function testEncode(form) {
	form.outStr.value = encode(form.inStr.value, form.seed.value);
}
function encode(inStr, seed){
	seed = parseInt(seed);
	var char, index, newIndex, outStr="";
	var refStr="0123456789abcdefghijklmnopqrstuvwxyz._~ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (var i=0; i<inStr.length; i++) {
		char = inStr.substring(i, i+1)
		index = refStr.indexOf(char)
		newIndex = index^seed;
		outStr += refStr.substring(newIndex, newIndex+1);
	}
	return (outStr)
}
</script>
<form>
¿é¤J¦r¦ê¡G<input NAME="inStr" value=cs3431>
<input TYPE="button" Value="===> ½s½X ===>" onClick="testEncode(this.form)">
¿é¥X¦r¦ê¡G<input TYPE="text" NAME="outStr"><br>
½s½X°Ñ¼Æ¡G<input NAME="seed" value=1>
</form>

<hr>
</body>
</html>

³oºØ½s½X¤è¦¡¬O¤@ºØ²³æªº¡u¦ì¸mÂà´«½s½X¡v¡A¦ÓÂà´«¶q«h¬O®Ú¾Ú index^seed¡]index ©M seed ªº Bitwise XOR¡^¨Ó¨M©w¡C

¦ý¬O¤W­z³o¨Ç½d¨Ò¡A³£¬O¦b«È¤áºÝªº JavaScript¡A©Ò¥H«ÜÃø°µ¨ì§¹¾ãªº±K½X©Îºô­¶«OÅ@¡C¦pªG»Ý­n§¹¾ã«OÅ@¡]¨Ò¦pºô¸ô»È¦æªºÂà±b¨t²Î¡^¡A´N»Ý­n¦øªA¾¹©M«È¤áºÝªº¾ã¦X¹B¥Î¡A¦³Ãö©ó³o¤è­±ªº»¡©ú¡A§Ú­Ì·|¦b«áÄò ASP ¬ÛÃö³¹¸`¨Ó¶i¦æ¸Ô²Ó»¡©ú¡C


JavaScript µ{¦¡³]­p»PÀ³¥Î¡G¥Î©óºô­¶¥Î¤áºÝ