I am trying to solve this code


#1

var string = "2b903102b29299c12d6c1e2ac80169";
var flag = "";
for (var i = 0; i < string.length; i++) {
// There is an easier way to find this than calculating by hand!
var ascii = string.charCodeAt(i);
ascii = ascii + i;
flag = flag + String.fromCharCode(ascii);
}
flag = "The flag is: " + flag;


#2

what are you trying to accomplish with this code?


#3

I am joined in a competition and this is the code that they gave me!!
Do u know the answer??


#4

What this code is doing is that it is trying to encode a string by converting each character in it to its corresponding unicode value (the charCodeAt(index) method returns the numeric Unicode value of the character at the given index .)

The code transforms that numeric value by adding the current value of i to it then the code transforms the new value to a string created by using the specified sequence of Unicode values.(which is what the fromCharCode(ascii) method does and add it to flag.

You can easily decode flag by reverse engineering the code. TO see this process take a look at the code you presented with some trace statement

var string = "2b903102b29299c12d6c1e2ac80169";
var flag = "";
for (var i = 0; i < string.length; i++) {
    // There is an easier way to find this than calculating by hand!
    var ascii = string.charCodeAt(i);
    console.log("ascii :: "+ascii)
    ascii = ascii + i;
    console.log("ascii :: "+ascii)
    flag = flag + String.fromCharCode(ascii);
    console.log("flag:: "+flag)
}
flag = "The flag is: " + flag;

console.log("finally flag is: "+flag);

This is what i see the code doing. other than that can you provide the question the contest provided along with the code?


#5

One of our agents recently caught a young hacker with the code name !$criptkiddie. He hid the below piece of javascript on a page which calculates a value but doesn't output the final result. It's also embedded on this page - can you find the result?

var string = "2b903102b29299c12d6c1e2ac80169";
var flag = "";
for (var i = 0; i < string.length; i++) {
// There is an easier way to find this than calculating by hand!
var ascii = string.charCodeAt(i);
ascii = ascii + i;
flag = flag + String.fromCharCode(ascii);
}
flag = "The flag is: " + flag;

This is it!!


#6

so. can U please tell me the answer


#7

tell the answer if you found it please


#8

I found the code and it's 2c;37669j;C=EFq@BuHvEzHx{QJLRV

No problem :wink: