
11.06.2007, 01:20
|
|
Участник форума
Регистрация: 17.12.2006
Сообщений: 191
С нами:
10210610
Репутация:
75
|
|
скрипт показывающий кодировку
PHP код:
<HTML>
<HEAD>
<TITLE>Ваша кодировка :</TITLE> </HEAD>
<BODY BGCOLOR="#FFFFFF"> <script> var u=navigator.userAgent; if (u.indexOf("Win") != -1)
// Текст в 1251 document.writeln ("Windows 1251") ;
else if (u.indexOf("DOS") != -1 || u.indexOf("OS/2") != -1)
// Текст в 866 document.writeln("MS-DOS CP866"); else
// Текст в K018 document.writein ( "лПДЙТПЧЛБ KOI8-R") ;
</script>
</BODY>
</HTML>
скрипт 2-Base перекодировщик
PHP код:
<HTML>
<HEAD>
<TITLE>Base converter</TITLE>
<SCRIPT LANGUAGE="JavaScript"> <!-- hiding content from old browsers
// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http:
//www.geocities.com/~yehuda/
// Simulate the "power of" (^) operator
/////////////////////////////////////////
function power(op1, op2) { var result = 1 for (var i = 1; i <= op2; i++) { result *= op1 } return result }
// Simulate the div (integral division)
// operator
/////////////////////////////////////////
function div(op1, op2) {
return Math.round(op1 / op2 - op1 % op2 / op2) }
// Returns a digit (maximum hexadecimal)
// based on its decimal value
/////////////////////////////////////////
function getDigit(val) { if (val == 10) return "A" if (val == 11) return "B" if (val == 12) return "C" if (val == 13) return "D" if (val == 14) return "E" if (val == 15) return "F" return val
// the return statement terminates the function,
// so there is no need for else statements }
// Returns the decimal value of a digit
// (maximum hexadecimal)
/////////////////////////////////////////
function getValue(dig) { if (dig == "A") return 10 if (dig == "B") return 11 if (dig == "C") return 12 if (dig == "D") return 13 if (dig == "E") return 14 if (dig == "F") return 15 return dig
// the return statement terminates the function,
// so there is no need for else statements }
// Convert from decimal to specified base
/////////////////////////////////////////
function toBase(num, base) { var newNum = (num == 0) ? "0" : "" while (num >= 1) { newNum = getDigit(num % base) + newNum num = div(num, base) } return newNum }
// Convert from specified base to decimal
/////////////////////////////////////////
function toDec(num, base) { if (base == 8) return parseInt("0" + num) if (base == 16) return parseInt("0x" + num) num = "" + num
// convert to string by casting
var numLength = num.length
// the length property returns the length of a string var newNum = 0
// initialization
// (must be 0 so the sum is not affected) var curDigit = "" var contributedValueValue = 0 for (var i = numLength - 1; i >= 0; --i) { curDigit = num.charAt(i) contributedValue = getValue(curDigit) contributedValue *= power(base, numLength - (i + 1)) newNum += parseInt(contributedValue) } return newNum }
// Main function that accepts input and
// calls appropriate functions
/////////////////////////////////////////
function convert(num, base1, base2) {
if (typeof num == "string")
num = num.toUpperCase() if (base1 == base2) return num if (base1 == 10)
return toBase(num, base2) if (base2 == 10) return toDec(num, base1) return toBase(toDec(num, base1), base2) }
// Create a conversion table
/////////////////////////////////////////
function drawTable(lastNum) { with (document) { lastNum = parseInt(lastNum) write("<TABLE BORDER=3>") write("<TR><TD COLSPAN=8><CENTER><FONT COLOR=purple SIZE=+4>") write("Base Converter</FONT></CENTER></TD></TR>")
write("<TR>")
for (var k = 2; k <= 16; k = k + 2) { write("<TD><CENTER> Base " + k + "
</CENTER></TD>") }
write("</TR>")
for (var i = 0; i <= lastNum; ++i) { write("<TR>")
for (var j = 2; j <= 16; j = j + 2) { write("<TD>" + toBase(i, j) + "</TD>") } write("</TR>") } write("</TABLE>") } }
// Gets table's input
/////////////////////////////////////////
function getTableAttributes() {
var message = "Enter last number to be converted in the table" var lastNum = parseInt(prompt(message, 15))
if (lastNum != 0)
drawTable(lastNum) }
// Convert individual numbers, until the
// user selects cancel on the first
// prompt of the loop
/////////////////////////////////////////
function calcNum() { while(1) {
var number = prompt("Enter a number in any base:", 0)
if (number == null) break var base1 = prompt("Enter its base:", 10) if (base1 == null) continue base1 = parseInt(base1) var base2 = prompt("Enter the desired base:", 16) if (base2 == null) continue base2 = parseInt(base2) var outputString = number + " (base " + base1 + ") = " outputString += convert(number, base1, base2) outputString += " (base " + base2 + ")" alert(outputString) } }
// Ask user for conversion device
// (T-table, I-individual values)
/////////////////////////////////////////
function mainInput() { var message = "Enter (T) to create a table or (V) to " message += "calculate a value"
var chosenDevice = prompt(message, "T") if (chosenDevice == "T" || chosenDevice == "t") getTableAttributes() else if (chosenDevice == "V" || chosenDevice == "v") calcNum() else alert("Goodbye!") } mainInput()
// end hiding content -->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
Кодировщик-перекодировщик
PHP код:
<HTML>
<HEAD>
<TITLE>Enciphering</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved. // Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http:
//www.geocities.com/~yehuda/
// create list of valid characters var list = "0123456789abcdefghijklmnopqrstuvwxyz._~ABCDEFGHIJKLMNOPQRSTUVWXYZ" function encipher() {
// prompt user for string
var str = prompt("Enter string:", "")
// terminate function if user selects CANCEL if (!str) return
// check that each character of input string is valid
for (var i = 0; i < str.length; ++i) {
if (list.indexOf(str.charAt(i)) == -1) { alert("script terminated -- invalid character found") return } }
// prompt user for key
var key = prompt("Enter key (1-63):", "")
// terminate function if user selects CANCEL if (!key) return
// convert key to integer (number)
key = parseInt(key)
// alert enciphered string
alert(encode(str, key)) }
function encode(str, key) {
// initialize accumulative string variable
var code = ""
// encipher all characters
for (var i = 0; i < str.length; ++i) {
var ind = list.indexOf(str.charAt(i))
var converted = list.charAt(ind ^ key) code += converted }
// return enciphered value return code } encipher()
// -->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
|
|
|