Link to home
Start Free TrialLog in
Avatar of zattz
zattz

asked on

javascript encryption

Hi,

I found the following function that decrypts something. I'm not sure how this works. Can somebody write a function that does the reverse. IE: one that encrypts

The decryption function is:

function hdecrypt(s){var o="",ar=new
Array(),os="",ic=0,p=0;
for(i=0;i<s.length;i++){c=s.charcodeat(i);
if (c<128)c=c^((p++%8)+1);os+=String.fromCharCode(c);
if(os.length>80){ar[ic++]=os;os=""}}o=ar.join("")+os;return o}
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

I guess this is not going to be possible.  you can create a routine that encrypts and decrypts using Javascript, that bit is no problem.  Where are you going to store your encryption key though?  Javascript is not compiled and therefore anyone can see your code.  You could then view the code find the key and crack the password very very easily.

But try these below options...
http://javascript.internet.com/passwords/ascii-encryption.html#source

XOR Encryption: Sample Code

<script>
str=''
str=str+String.fromCharCode('Q'.charCodeAt(0)^((0x05).toString(10)))
str=str+String.fromCharCode('P'.charCodeAt(0)^((0x38).toString(10)))
str=str+String.fromCharCode('j'.charCodeAt(0)^((0x03).toString(10)))
str=str+String.fromCharCode('h'.charCodeAt(0)^((0x1B).toString(10)))
str=str+String.fromCharCode('4'.charCodeAt(0)^((0x14).toString(10)))
str=str+String.fromCharCode('3'.charCodeAt(0)^((0x5A).toString(10)))
alert(str)
</script>

http://guymal.com/mycode/xor_js_encryption/

More info. Use microsoft script encoder, it is free :
http://www.microsoft.com/downloads/details.aspx?FamilyId=E7877F67-C447-4873-B1B0-21F0626A6329&displaylang=en

FOR Netscape/Mozilla there is no encryption only scrambeling :
http://www.shopable.co.uk/scrambler.html
http://www.brainjar.com/js/crunch/

R.K
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Did you try my solution..

_PA
Avatar of zattz
zattz

ASKER

Sorry forgot about this
Thanks for the 'A', good luck, and Happy New Year.
Avatar of zattz

ASKER

And to you :>
Avatar of zattz

ASKER

I was surprised you thanked me for the 'A'. Usually I only get people complaining when I give a C! The other day somebody gave me a one line answer for a 500 point question and expected an A!
Well, I try to be polite, and find that it is a good habit to get into.