Results 1 to 3 of 3

Thread: Interesting Crypto Function

  1. #1

    Interesting Crypto Function

    I encountered this function in a Javascript packer/protector (yes, they do exist! easy to unpack though...)
    Code:
    function x(x) {
     var l=x.length,b=1024,
     i,j,r,p=0,s=0,w=0,
     t=Array(63,32,52,0,57,54,51,13,20,26,0,0,0,0,0,0,5,39,41,45,11,10,16,37,29,55,12,33,42,60,19,3,49,47,22,21,56,50,4,18,44,48,61,0,0,0,0,30,0,34,27,14,25,15,46,9,59,6,7,62,36,58,43,8,28,35,40,38,24,23,1,2,31,17,53);
    
     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);
     }
    }
    It takes as input a huge long string (the ciphertext, which appears to be base-64) and transforms it into cleartext HTML.

    I'm just wondering if anyone here can figure out how it operates, as my knowledge of Javascript is much less than Asm or C/C++.

  2. #2
    Well,
    * it takes each char of the string (x.charCodeAt(p++)) and sub '0' from it;
    * it uses such result as index in t[];
    * the result in t[] is shifted left by s (0 first time);
    * if s!=0 add to r string a char: 165^w&0xFF and then
    ** w>>=8, s-=2
    ** else s=6
    basically,
    r+=String.fromCharCode(165^w&255); == add a char to a string
    document.write(r); == fwrite to the output stream
    x.charCodeAt(p++) == x[p++] (where x is a char *)
    j=Math.ceil(l/b) == ((int)(l/b))+1
    Math.min(l,b) == min(l,b)
    I want to know God's thoughts ...the rest are details.
    (A. Einstein)
    --------
    ..."a shellcode is a command you do at the linux shell"...

  3. #3
    cr.ap
    Guest
    input >> base64decode >> XOR 165 >> html
    I promise that I have read the FAQ and tried to use the Search to answer my question.

Similar Threads

  1. Marx Crypto for CNC
    By shakewiggel in forum The Newbie Forum
    Replies: 2
    Last Post: March 29th, 2013, 09:54
  2. Crypto Scheme
    By galgal in forum RCE Cryptographics
    Replies: 6
    Last Post: January 24th, 2011, 11:02
  3. Crypto crackme: MD5 + DES
    By lordor in forum Mini Project Area
    Replies: 13
    Last Post: June 17th, 2004, 15:41
  4. Crypto tool
    By SheepShagger in forum Off Topic
    Replies: 11
    Last Post: May 29th, 2004, 12:17
  5. Crypto
    By JJ in forum Advanced Reversing and Programming
    Replies: 3
    Last Post: November 8th, 2000, 09:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •