Can anyone help to identify what this encryption used in this script?
<html>
<body>
<script type="text/javascript" language="JavaScript">
function decrypt_p(x){
var l=x.length,
b=1024,
i,j,r,
p=0,
s=0,
w=0,
t=Array&
#40;63,47,29,11,10,49,16,9,42,48,0,0,0,0,0,0,41,57,58,45,44,31,15,28,7,2,62,36,3
5,14,34,51,18,17,39,13,33,59,23,0,27,26,46,0,0,0,0,61,0,24,5,38,3,50,37,22,1,20,
55,6,25,32,43,21,4,8,40,54,53,12,30,56,60,52,19);
for (j=Math.ceil(l/b);j>0;j--) {
r='';
for (i=Math.min(l,b);i>0;i--,l--) {
w|=(t[x.charCodeAt(p++)-48])<<s;
if(s) {
r+=String.fromCharCode(165^w&255);
w>>=8;
s-=2
} else {
s=6
}
}
document.write(r)
}
}
decrypt_p(& ..=encrypted code here=..")
</script>
</body>
</html>
It looks like a lookup (converting the original encrypted
text to a string of numbers from 0 through 63),
base64 decoding of that "base 64" number
and then a simple XOR.
The "for (j=Math.ceil(l/b);j>0;j--)" loop just works in blocks
of 1024 characters, so let's ignore that and get into the
"for (i=Math.min(l,b);i>0;i--,l--)" loop.
s will start at 0 and then to 6 4 2 0 6 4 2 0 ...
The first step is always to convert the character in the string
to a number based at "0" (the string "0" has ascii value 48)
and look that up in a table (the "t array" - a simple substitution
lookup). While there are duplicates, the numbers in the "t array"
(in your prior post) ranged from 0 through 63 (it covers all those
numbers) so we have several values which might result in the same
falue but the characters we get (t[x.charCodeAt(p++)-48]) will all
be integers from 0 through 63 suggesting base64 encoding.
Base64 decoding will drop some characters (4 base 64 encoded characters
become 3 ascii characters) and the s values show that. There are four
values through which s loops (starting with 0)
0 6 4 2 0 6 4 2 0 ...
(if (s) {... s-=2} else {s=6})
and only for s not zero do we get an extra character in the decoded
string
if(s) {r+=...}
So ... 64 possibled encoded characters, for every four encoded characters
we get three decoded characters - again, strongly suggestive of base64
decoding.
Let's look at the code ...
for the first character (s=0) we just with that in "w"
(w|=(t[x.charCodeAt(p++)-48])<<s where s=0 and w=0 initially)
The next time through, (s=6) the next character is shifted six
bits to the left and added (ORed) to this initial character
(w|=(t[x.charCodeAt(p++)-48])<<s

with the result that w's
last eight bits consist of the last two bits of the second
character (after the lookup) followed by the six bits (the
lookup value always only has six bits being from 0 through 63)
of the first character. After the simple XOR, we take the last
eight bits (r+=String.fromCharCode(165^w&255)). So a lookup,
construct 8 bits from six bits of the first and the low two
bits of the second character and and XOR.
Then we drop the character we just got (w>>=8) keeping (in w
now) only the bits left after this shift (we dropped the
first encoded character's six bits and two more from what
we got by shifing the second character six bits to the
left and now shifting 8 bits to the right). The result,
since the second encoded character (after the lookup)
had only six bits (0-63) is the top four bits of this.
We lookup the next encoded character (to get another number
from 0-63) and shift that (s is now 4) four bits to the
left and add (OR) it to the four high bits of the second
encoded character (after lookup).
The XOR (and truncated to the last 8 bits,
String.fromCharCode(165^w&255), creates the next decoded
character from the high four (of the six) bits of the
second encoded character and the low four (of the six bits)
of the third encoded character (after lookup) and then that
(after the decoded character is appended to the string)
loses its last 8 bits (the decoded character) leaving the
high two bits of the third encoded (after lookup) character
in w and now s=2.
The four encoded character is shifted (s=2) two to the left
and added (ORed) with this to get the third decoded character
(its value is obtained from the high two of six bits of the
third character along with the six bits of the fourth encoded
character after lookup).
Yep ... that's just a base64 decoder (after the lookup in the
t Array to get six bit values and before the final simple
XOR and extraction of the character (last eight bits) 165^w&255).