Ajax Google Search
4/15/2006 12:27:00 PM | Permanent Link | Comments (9)
I've fixed the search function for the blog. It uses Google Search to query the keyword, with a site wide limitation.The coolest part is the XmlHttpRequest (Ajax). The search is performed using the asynchronous function and the response is written to a hidden div, just above the first post, and a message, saying Searching ... is also notified for informing the user of the pending action!
Feel free to look at the source :
ajax.js
google.js
search.php
Look at the source of my blog, to see further details about the elements and html involved.
Labels: Technology




Comments (
)
Nice :) It seems those js files, can be deemed libraries, you might want to develop them further.
Hi
I've looked at your RC4 Source Code and made a Javascript implementation of it , so that I can interoperate between the C# and Javascript.
I'm listing here the javascript implementation first (can be used as stand-alone) , and then the C# code to use to decrypt , because it is passed in as a hex-string , in C# it must first be converted to a normal string.
Javascript Listing :
//Helper Functions
function byteArrayToHex(byteArray) {
var result = "";
if (!byteArray)
return;
for (var i=0; i%lt;byteArray.length; i++)
result += ((byteArray[i]%lt;16) ? "0" : "") + byteArray[i].toString(16);
return result;
}
function hexToByteArray(hexString) {
var byteArray = [];
if (hexString.length % 2) // must have even length
return;
if (hexString.indexOf("0x") == 0 || hexString.indexOf("0X") == 0)
hexString = hexString.substring(2);
for (var i = 0; i%lt;hexString.length; i += 2)
byteArray[Math.floor(i/2)] = parseInt(hexString.slice(i, i+2), 16);
return byteArray;
}
function byteArrayToString(buf)
{
var S = "";
for(i =0;i%lt;buf.length;i++)
{
S += String.fromCharCode(buf[i]);
}
return S;
}
//Implementation usage : rc4.encrypt() and rc4.decrypt()
var rc4 = {
encrypt:function(pwd,data)
{
var a, i, j, k, tmp, pwd_length, data_length;
var key = new Array();
var box = new Array();
cipher = new Array();
pwd_length = pwd.length;
data_length = data.length;
for (i = 0; i %lt; 256; i++)
{
key[i] = pwd.charCodeAt(i % pwd_length);
box[i] = i;
}
for (j = i = 0; i %lt; 256; i++)
{
j = (j + box[i] + key[i]) % 256;
tmp = box[i];
box[i] = box[j];
box[j] = tmp;
}
for (a = j = i = 0; i %lt; data_length; i++)
{
a = (a + 1) % 256;
j = (j + box[a]) % 256;
tmp = box[a];
box[a] = box[j];
box[j] = tmp;
k = box[((box[a] + box[j]) % 256)];
cipher[i] = (data.charCodeAt(i) ^ k);
}
return byteArrayToHex(cipher);
},
decrypt:function(pwd,data)
{
data = hexToByteArray(data);
data = byteArrayToString(data);
var a, i, j, k, tmp, pwd_length, data_length;
var key = new Array();
var box = new Array();
cipher = new Array();
pwd_length = pwd.length;
data_length = data.length;
for (i = 0; i %lt; 256; i++)
{
key[i] = pwd.charCodeAt(i % pwd_length);
box[i] = i;
}
for (j = i = 0; i %lt; 256; i++)
{
j = (j + box[i] + key[i]) % 256;
tmp = box[i];
box[i] = box[j];
box[j] = tmp;
}
for (a = j = i = 0; i %lt; data_length; i++)
{
a = (a + 1) % 256;
j = (j + box[a]) % 256;
tmp = box[a];
box[a] = box[j];
box[j] = tmp;
k = box[((box[a] + box[j]) % 256)];
cipher[i] = (data.charCodeAt(i) ^ k);
}
return byteArrayToString(cipher);
}
};
C# Listing :
private String ConvertFromHex(String dataSet)
{
ArrayList dataBytes = new ArrayList();
for (int i = 0; i %lt; dataSet.Length; i = i+2)
{
String strHex;
strHex = dataSet.Substring(i, 2);
dataBytes.Add(Convert.ToByte(strHex, 16));
}
return System.Text.Encoding.GetEncoding(1252).GetString((byte[])dataBytes.ToArray(typeof(byte)));
}
//Usage : RC4.Decrypt(k,ConvertFromHex(data),false);
Thanks for the good work
Le Roi
Hi
I've looked at your RC4 Source Code and made a Javascript implementation of it , so that I can interoperate between the C# and Javascript.
I'm listing here the javascript implementation first (can be used as stand-alone) , and then the C# code to use to decrypt , because it is passed in as a hex-string , in C# it must first be converted to a normal string.
Javascript Listing :
//Helper Functions
function byteArrayToHex(byteArray) {
var result = "";
if (!byteArray)
return;
for (var i=0; i%lt;byteArray.length; i++)
result += ((byteArray[i]%lt;16) ? "0" : "") + byteArray[i].toString(16);
return result;
}
function hexToByteArray(hexString) {
var byteArray = [];
if (hexString.length % 2) // must have even length
return;
if (hexString.indexOf("0x") == 0 || hexString.indexOf("0X") == 0)
hexString = hexString.substring(2);
for (var i = 0; i%lt;hexString.length; i += 2)
byteArray[Math.floor(i/2)] = parseInt(hexString.slice(i, i+2), 16);
return byteArray;
}
function byteArrayToString(buf)
{
var S = "";
for(i =0;i%lt;buf.length;i++)
{
S += String.fromCharCode(buf[i]);
}
return S;
}
//Implementation usage : rc4.encrypt() and rc4.decrypt()
var rc4 = {
encrypt:function(pwd,data)
{
var a, i, j, k, tmp, pwd_length, data_length;
var key = new Array();
var box = new Array();
cipher = new Array();
pwd_length = pwd.length;
data_length = data.length;
for (i = 0; i %lt; 256; i++)
{
key[i] = pwd.charCodeAt(i % pwd_length);
box[i] = i;
}
for (j = i = 0; i %lt; 256; i++)
{
j = (j + box[i] + key[i]) % 256;
tmp = box[i];
box[i] = box[j];
box[j] = tmp;
}
for (a = j = i = 0; i %lt; data_length; i++)
{
a = (a + 1) % 256;
j = (j + box[a]) % 256;
tmp = box[a];
box[a] = box[j];
box[j] = tmp;
k = box[((box[a] + box[j]) % 256)];
cipher[i] = (data.charCodeAt(i) ^ k);
}
return byteArrayToHex(cipher);
},
decrypt:function(pwd,data)
{
data = hexToByteArray(data);
data = byteArrayToString(data);
var a, i, j, k, tmp, pwd_length, data_length;
var key = new Array();
var box = new Array();
cipher = new Array();
pwd_length = pwd.length;
data_length = data.length;
for (i = 0; i %lt; 256; i++)
{
key[i] = pwd.charCodeAt(i % pwd_length);
box[i] = i;
}
for (j = i = 0; i %lt; 256; i++)
{
j = (j + box[i] + key[i]) % 256;
tmp = box[i];
box[i] = box[j];
box[j] = tmp;
}
for (a = j = i = 0; i %lt; data_length; i++)
{
a = (a + 1) % 256;
j = (j + box[a]) % 256;
tmp = box[a];
box[a] = box[j];
box[j] = tmp;
k = box[((box[a] + box[j]) % 256)];
cipher[i] = (data.charCodeAt(i) ^ k);
}
return byteArrayToString(cipher);
}
};
C# Listing :
private String ConvertFromHex(String dataSet)
{
ArrayList dataBytes = new ArrayList();
for (int i = 0; i %lt; dataSet.Length; i = i+2)
{
String strHex;
strHex = dataSet.Substring(i, 2);
dataBytes.Add(Convert.ToByte(strHex, 16));
}
return System.Text.Encoding.GetEncoding(1252).GetString((byte[])dataBytes.ToArray(typeof(byte)));
}
//Usage : RC4.Decrypt(k,ConvertFromHex(data),false);
Thanks for the good work
Le Roi
http://rc4dotnet.devhome.org
How do you know Dan?? Plz write back
I just saw him in Perkins in Minnesota
As far as the design is concerned, all credit to you. But to make my template I had to start with the travel template(as I had said earlier) since a copy paste of your code would have resulted in something like chaitanyam.blogspot.com.
http://abhishekn.blogspot.com/2006/06/internet-connections-in-india.html
http://markonzo.edu It is a very good thing, actual ashley furniture [url=http://jguru.com/guru/viewbio.jsp?EID=1536072]actual ashley furniture[/url], jypxx, watch allegiant air [url=http://jguru.com/guru/viewbio.jsp?EID=1536075]watch allegiant air[/url], 46070, best pressure washers [url=http://jguru.com/guru/viewbio.jsp?EID=1536078]best pressure washers[/url], njxyigg, follow dishnetwork [url=http://jguru.com/guru/viewbio.jsp?EID=1536080]follow dishnetwork[/url], hrioaa, fresh adt security [url=http://jguru.com/guru/viewbio.jsp?EID=1536076]fresh adt security[/url], tnrurbo,