CSS

Tuesday, February 28, 2012

Javascript Hex Decode and Encode

String.prototype.hexEncode=function(){
  var r='';
  var i=0;
  var h;
  while(i<this.length){
    h=this.charCodeAt(i++).toString(16);
    while(h.length<2){
      h=h;
    }
    r+=h;
  }
  return r;
};
String.prototype.hexDecode=function(){
  var r='';
  for(var i=0; i<this.length; i+=2){
    r+=unescape('%'+this.substr(i,2));
  }
  return r;
};
Example:
'Tya Ganteng :P'.hexEncode()
will return:
5479612047616e74656e67203a50
and
'5479612047616e74656e67203a50'.hexDecode()
will return:
Tya Ganteng :P
One day this script would be handy, very handy indeed :)

Haha.. :D

4 comments:

cemong sagai said...

bang mau tanya ni, lo soal navbar yang ga mau ngeload nama pesbuk gmn ya? TKP di http://punakawan-berbagi.blogspot.com

oya, bagi ilmu dkit soal chiper ni, hehe...
http://punakawan-berbagi.blogspot.com/2012/03/convert-chiper-rot13.html

Ksatria Purnama said...

oh, jangan asal copy paste script, tar kalo blog nya meleduk gimana? :D
ngerti dulu bar copas :P

dede arts said...

hehe... :P iya bang maaf, tp jujur, aing-creations ni sangt bagus dan sangt menginspirasi kami.. trimaskh ats komntrnya dan trimask ats kemurahan atas kami diberi kesempatan menginspirasi blog ini.
salam..

Dwi Siswanto (CaFc Versace) said...

Cakakakak,,, komper mLeduxx (buduG) :D