URL Encryption II

[Total: 0    Average: 0/5]

This script will take a valid URL address and convert it into a non-user readble format that still works.

Head Code:

<SCRIPT LANGUAGE="JavaScript">
<!-- 
function custLog(x,base) {
	// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
	return (Math.log(x))/(Math.log(base));
}

function mod(divisee,base) {
	// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
	return Math.round(divisee - (Math.floor(divisee/base)*base));
}

function custRound(x,places) {
	// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
	return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

function fractApprox(x,maxDenominator) {
	// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
	maxDenominator = parseInt(maxDenominator);
	var approx = 0;
	var error = 0;
	var best = 0;
	var besterror = 0;
	for (var i=1; i <= maxDenominator; i++) {
		approx =Math.round(x/(1/i)); error =(x - (approx/i))
		if (i==1) {best =i; besterror =error;} if (Math.abs(error) != Math.abs(besterror)) {best = i; besterror = error;}
	}
	return (Math.round(x/(1/best)) + "/" + best);
}


function baseConverter (number,ob,nb) {
	// Created 1997 by Brian Risk.  http://members.aol.com/brianrisk
	number = number.toString().toUpperCase();
	var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var dec = 0;
	for (var i = 0; i <=  number.length; i++) {
		dec +=(list.indexOf(number.charAt(i))) * (Math.pow(ob , (number.length - i - 1)));
	}
	number =""; var magnitude =Math.floor((Math.log(dec))/(Math.log(nb))); for (var i =magnitude; i >= 0; i--) {
		var amount = Math.floor(dec/Math.pow(nb,i));
		number = number + list.charAt(amount); 
		dec -= amount*(Math.pow(nb,i));
	}
	return number;
}

function encryptIt(_in,_out) {
  // the following letters are going to be encrypted.
  var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var letterCode=new Array();

  for(var i=0;i<letters.length;i++)
  {
    var _temp=baseConverter(letters.charCodeAt(i),10,16);
    letterCode[i]="%"+_temp;
  }
  alert(letterCode[letters.indexOf("j")]);
  var _search = _in.value.indexOf("?")==-1?"":"?"+_in.value.split("?")[1];
  var _formIn = _in.value.indexOf("?")==-1?_in.value.split("."):_in.value.split("?")[0].split(".");
  
  var output = _formIn[0]+".";
  for(var i = 0; i < _formIn[1].length; i++) {
    if(letters.indexOf(_formIn[1].charAt(i))!=-1) {
	  if (letters.indexOf(_formIn[1].charAt(i))!=-1) {
	    // its a letter
		var x = (Math.random()*1000);
		var j = letters.indexOf(_formIn[1].charAt(i));
		if (x > 500) {
		  // j should be 0 through 25 for lowercase and 26 through 51 for uppercase
		  // switch them
		  if (j < 26) j += 26;
		  else        j -= 26;
		}
		if (x < 300) { output += _formIn[1].charAt(i);
		} else { output += letterCode[j]; }
	  } else { output += escape(_formIn[1].charAt(i)); }
	} else { output += _formIn[1].charAt(i); }
  }
  for(var i=2;i<_formIn.length;i++)
    output += "."+_formIn[i];
  _out.value = output+_search;
}
function testIt() {
var _l = document.exf1.output.value;
if (_l.indexOf("http://")==-1) _l = "http://"+_l;
alert(_l);
//var myWin = window.open(_l,"TestWin","width=500,height=50,location=yes");
}
//  End -->
</script>

Body Code:

<form name=exf1>
Enter into this box the URL that you want to encrypt:
<BR>
<input type=text name=input size=50 value="www.js-examples.com">
<input type=button value="Encrypt URL" onclick="encryptIt(this.form.input,this.form.output)">
<BR>
This is where the encrypted URL will appear:
<BR>
<input type=text name=output size=50 value="">
<input type=button value="Test Encrypted URL" onclick="testIt()">
</form>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *