Eduard Lebedyuk · 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?

3 0 7 586
Log in or sign up to continue


Not the most creative output:

USER>write ##class(ITPlanet.BlackBox).Main(<left as a mystery>,<also left as a mystery>)
Hello World!

@Eduard, I'm assuming you don't want spoilers here beyond that?

One non-spoiler: there are actually two valid options for the first argument that will produce this output.

That was fast.

I'm assuming you don't want spoilers here beyond that?

Yes, for now.

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

How do you propose to store static strings?

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..!

maybe something like this

USER>set list="ªÅÊÈÉx­Ãļ²m"

USER>for i=1:1:$l(list) s c=$a(list,i)-100+(i*2) write $c(c)
Hello World!

or another way a bit easier to decode, I think

USER>set list="Iemlp Xosle!"

USER>for i=1:1:$l(list) s c=$a(list,i)+(i#-2) write $c(c)
Hello World!

The solution:

Hello World!
Hello World!