encrypt with JavaScript at PHP

Поиск
Список
Период
Сортировка
От ivana novianti
Тема encrypt with JavaScript at PHP
Дата
Msg-id 20010602031130.54262.qmail@web11307.mail.yahoo.com
обсуждение исходный текст
Список pgsql-php
I have made a script about encryption as follow, when
user_id and password are sent to the server, I can run
this script at IE, but I can not run this one at
Netscape. This script is run at the client side and
this should be decrypted at server side (PHP). Can
this script be used in PHP, or it must be convert to
PHP language/script ?

Would you mind helping  me , please ...




<html>
<head>
<!script language="javascript"
scr="C:\coba\crypt.js"><!/script>
<script language="javascript">

var allowedChars = "

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

function CharToDec(Character) {
var pos = allowedChars.indexOf(Character.charAt(0));
if(pos == -1) {
window.status += Character;
pos = 0;
}
return pos;
}

function DecToBin(Decimal) {
var i = 0;
var Bin = "";
while(Decimal > Math.pow(2, i)) {
i++;
}
for (var i = i; i >= 0; i--) {
if (Decimal >= Math.pow(2, i)) {
Decimal -= Math.pow(2, i);
Bin += "1";
} else Bin += "0";
}
return Bin;
}

function ExclusiveOr(input1, input2) {
var output = "";
while(input1.length < input2.length) {
input1 = "0" + input1;
}
while(input1.length > input2.length) {
input2 = "0" + input2;
}
if (input1.length == input2.length) {
for (var i=0; i<input1.length; i++) {
output += (input1.charAt(i) != input2.charAt(i)) ? "1"
: "0";
}
} else alert("XOR Operation Error.");
return output;
}
function BinToDec(Binary) {
var Dec = 0;
for(var i=0; i<=Binary.length; i++) {
Dec += Math.pow(2,i) * Binary.charAt((Binary.length -
1) - i);
}
return Dec;
}
function DecToChar(Decimal) {
if (Decimal > allowedChars.length) {
Decimal = 0;
}
var pos = allowedChars.charAt(Decimal);
return pos;
}
function BlockEncrypt(input1, input2) {
var output = "";
if (input1.length == input2.length) {
for (var i = 0; i < input1.length; i++) {
output +=
DecToChar(BinToDec(ExclusiveOr(DecToBin(CharToDec(input1.charAt(i))),
DecToBin(CharToDec(input2.charAt(i))))));
   }
} else alert("Block Encryption Error.");
return output;
}


function hashKey(key) {
var hash = "";
for (var i = 0; i < key.length; i++) {
hash += DecToChar((CharToDec(key.charAt(i)) + i) %
allowedChars.length);
}
return hash;
}


/*   Function:  Encrypts data.
   Parameters:  2 parameters:  (text string, key)
      Returns:  Encrypted string

Decrypt the string by running function twice.
*/

function EncryptString(plainText, key) {
var cipherText = "";
var textBlock, keyBlock = "";
var keyRotationPos = 0;
var beforePos, afterPos = 0;
var blockSize = 48;
var key = hashKey(key);
while(afterPos < plainText.length) {
beforePos = 0;
afterPos = blockSize;
if(afterPos < plainText.length) {
afterPos = plainText.length;
}
textBlock = plainText.substring(beforePos, afterPos);
keyBlock = key.substring(keyRotationPos, key.length);
while(keyBlock.length < textBlock.length) {
keyBlock += key;
}
keyBlock = keyBlock.substring(0, textBlock.length);
keyRotationPos = keyBlock.length % key.length;
cipherText += BlockEncrypt(textBlock, keyBlock);
beforePos = afterPos;
afterPos += blockSize;
}
return cipherText;
}


function kirim(){
var nama=login.user_id.value;
var pwd=login.pwd.value;

if (nama=="") {
 alert(" Anda belum mengisi nama login ");
 login.user_id.focus();
 return false;
}
if (pwd=="") {
alert(" Anda belum mengisi password ");
login.pwd.focus();
return false;
}
else {
nama1=EncryptString(nama,pwd);
pwd1=EncryptString(nama,pwd);
login.user_id.value=nama1 ;
login .pwd.value =pwd1;
login.submit()
//login.user_id.value=nama ;
login .pwd.value =pwd;
  }
}
</script>
</head>
<body bgcolor=lavender>
<table>
<tr> <td><font color=blue face=verdana size=5><B>
Login di SSdisc</B></font></td></tr></table>
<form name="login" action="login.html"  method=post  >
<!onsubmit="return kirim()">
 <FONT face="Verdana" size=3>Masukkan <B>user name</B>
dan <B>password</B> anda, apabila anda sudah menjadi
anggota <B>SSdisc             </B>.</FONT><P>
  <center>  User_id     : <input type=text
name=user_id><br>
                Password     :<input type=password
name=pwd></P>
  <input type=button value=OK name=reg
onclick="kirim()"><br><br>   </center>
 <FONT face="Verdana" size=3>Apabila anda belum
menjadi anggota SSdisc, <A
hef=anggota_baru1.html><B>Daftarkan</B></A>  diri anda
sekarang juga dengan GRATIS ! </font>
</form><center><font face= arial><a
href=kanan.html>Halaman Utama</a></font></center></body></html>

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year!  http://personal.mail.yahoo.com/

В списке pgsql-php по дате отправления:

Предыдущее
От: "Mitch Vincent"
Дата:
Сообщение: Re: Re: Printing Notices to the web?
Следующее
От: Dorin Grunberg
Дата:
Сообщение: PHP-PostgreSQL - install