Question
· Jun 19, 2017

Can you crack the Black Box?

Hi, Community!

And so I continue with publishing of the tasks for the Final round of InterSystems Contest on InterSystems Caché and DeepSee as a part of IT Planet Student Championship in Sochi. This year we had about 2 000 participants in InterSystems Contest.

One of the tasks for the finals was to crack the black box!

Problem description

First of all, download and import the black box:

write ##class(%Studio.Project).InstallFromFile("BlackBox.xml")

Black Box has only one class - ITPlanet.BlackBox and one method - Main. If you call it from a terminal:

write #class(ITPlanet.BlackBox).Main()

it would throw an exception. However, if you call it just right, it would return something slightly more meaningful.

But what? And how do you need to call it?

Discussion (7)2
Log in or sign up to continue

I don't know how close my version of this method to the original, but it should be something like this. But I think, your version a bit bigger.

ClassMethod Main(cfg As %SystemBase, mode As %String) As %String
{
    set trantabla=cfg.trantable
    set str=""
    set list=$listbuild(72,101,108,108,111,32,87,111,114,108,100,33)
    for i=1:1:$listlength(list) {
        set n=$listget(list, i)
        set hex = $zhex(n)
        set str = str _ "\u" _ $extract("000" _ hex, *-3, *)
    }
    set str=$zconvert(str, mode, trantable)
    set:$length(str)'=12 str="????? ??????"
    quit str
}

Btw, it was a good idea, to deploy code. But I think bad idea to hide original string in $ListBuild 

set list=$lb(72,101,108,108,111,32,87,111,114,108,100,33)

Because, such static variables, stored as is in OBJ code, and could be easily recognized.

USER>zzdump list

0000: 03 04 48 03 04 65 03 04 6C 03 04 6C 03 04 6F 03         ..H..e..l..l..o.
0010: 04 20 03 04 57 03 04 6F 03 04 72 03 04 6C 03 04         . ..W..o..r..l..
0020: 64 03 04 21                                             d..!