Unable to debug an encodded javascript?

I’m having some problems debugging an encoded javacscript. This script I’m referring to given in this link over here.

The encoding here is simple and it works by shifting the unicodes values to whatever Codekey was use during encoding. The code that does the decoding is given here in plain English below:-

<script language="javascript">
function dF(s){
var s1=unescape(s.substr(0,s.length-1)); var t='';
for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
document.write(unescape(t));
}
</script>

I’m interested in knowing or understanding the values (e.g s1,t). Like for example when the value of i=0 what values would the following attributes / method would hold

    s1.charCodeAt(i) and s.substr(s.length-1,1)

The reason I’m doing this is to understand as to how a CodeKey function really works. I don’t see anything in the code above which tells it to decode on the basis of codekey value. The only thing I can point in the encoding text is the last character which is set to 1 , 2 ,3 or 4 depending upon the codekey selected during encoding process. One can verify using the link I have given above.

However, to debug, I’m using firebug addon with the script running as localhost on my wamp server. I’m able to put a breakpoint on the js using firebug but I’m unable to retrieve any of the user defined parameters or functions I mentioned above.

I want to know under this context what would be best way to debug this encoded js.

EDIT

@blueberryfields Thanks for the neat code review.

However, to clarify this is no homework its something i picked from a website about encoding and javascript.The material just looked interesting and decided to give it a go. I don’t see the point of using the intermediate variables as I was hoping to make use of those already define (s1,t,i). Usually these variable types are seen in firebug way too often like the enumerable types. Beside, using a good breakpoint and the right place i can always step over these values in the loop.

I changed my focus as someone on stackexchange told me to use dragonfly (opera) as i did I was able to retrieve the variable and their values with the breakpoint statement. For other values i just did document.write to get desired results. Here is the link of the screenshot.

link.

I was more interested in understanding the part of coding that actually tell the program to shift-back the unicode character based upon code key value. That part of code was s.substr(s.length-1,1). He just extracted the last character which is the codekey number and then use it in calculating the matching charcode value.

If you unescape this shift-1 code %264DTDSJQU%2631MBOHVBHF%264E%2633kbwbtdsjqu%2633%264F%261Bbmfsu%2639%2638Ifmmp%2631Xpsme%2638%263%3A%264C%261B%264D0TDSJQU%264F%261B%261%3A%261%3A%261%3A1 you would get &4DTDSJQU&31MBOHVBHF&4E&33kbwbtdsjqu&33&4F&1Bbmfsu&39&38Ifmmp&31Xpsme&38&3:&4C&1B&4D0TDSJQU&4F&1B&1:&1:&1:1 Although those last chars not required but were intentionally added so it helps in decoding.

To figure out how this code works, I would recommend expanding it, and assigning intermediate local variables to store various results, so you can watch how they change as you step through.

Before assuming that you’re looking at you’re looking at user defined parameters or functions, you might want to look the functions up in a standard library. If you do look them up, you’ll notice all the functions used are standard library functions for Javascript.

For example, with the code you’ve got, I’d do something like this:

function dF(s) {
    var s1 = unescape(s.substr(0, s.length - 1));
    var t = '';
    for (i = 0; i < s1.length; i++) {
        var cCode = s1.charCodeAt(i);
        var key = s.substr(s.length - 1, 1);
        var temp= String.fromCharCode( cCode - key );
        t += temp;
    }
    var unescaped = unescape(t);
    document.write(unescaped);
}

NOTE:

This question smells a lot like a homework question. It’s generally frowned upon to ask us to do your homework for you, and it’s usually good form to at least warn that it’s homework you’re doing.

Lets make this simpler:

(function (s){
    var s1=unescape(s.substr(0,s.length-1));
    var t='';
    for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));
    return unescape(t);
})( [
        'var q = 1;0' // here is a little hack, the generator never outputs this code
        'wbs%2631r%2631%264E%26312%264C1',
        'xct%2742s%2742%275F%27423%275D2',
        'ydu%2853t%2853%286G%28534%286E3',
        'zev%2964u%2964%297H%29645%297F4',
        '%7Bfw*75v*75*8I*756*8G5'
    ][1] // here you can change the index (which is also the shift amount)
)

Outputs:

“var q = 1;”

As you can see its a Caesar cipher, probably the first cipher that kids learn in school.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật