这个混淆的代码中是否存在浮点错误?

时间:2016-08-26 13:02:20

标签: javascript arithmetic-expressions deobfuscation

作为一个谜题我昨天给了以下代码片段

  

为什么这会给773.06 ..?

var _ = 10, __ = 21, ___ = 38;
var _______ = { _: { "yo":_/___*_+___ }};
var ___________ = [[[{"heh":{"hehe":[[[[12,71,82,91]]]][0][0][0][1]}}]]];
var ____________ = ___________[0][0][0].heh.hehe*_+__+_______._.yo/_+___;
console.log(____________);

我记不起预期的答案了,但它至少是800.一位同事简短地看了一眼并说它是由于浮点不精确但我认为应该返回773.06 ..

答案是什么?

整理代码

var a = 10, b = 21, c = 38;
var d = a/c*a+c;
var e = (71*a)+b+(d/a)+c;
console.log(e);

3 个答案:

答案 0 :(得分:3)

让我们删除膨胀,并给这个东西一些可读的变量名称:

//translated line by line
var a = 10, b = 21, c = 38;
var d = a/c*a + c;
//d = 100/38 + 38
//d = 40.63157894736842
var e = [12,71,82,91][1];
//e = 71;
var f = e*a + b + d/a + c;
//f = 710 + 21 + 4.xxx + 38
//f = 773.0631578947368
console.log(f);

答案 1 :(得分:2)

最后一行相当于: 71*10+21+(10/38*10+38)/10+38 773.06 ...

如果您忘记将809.63157894除以d

,则可以获得a

答案 2 :(得分:2)

实际上没有错误。这是故意混淆的,但如果你简化,你会得到如下:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Workbook_BeforeSave False, True
    ThisWorkbook.Save

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

    If Cancel Then Sheet1.Visible = xlSheetHidden

End Sub

然后变为:

var A = 10;
var B = 21;
var C = 38;
var D = { A: { "yo": A / C * A + C }};
var E = [[[{"heh":{"hehe":[[[[12, 71, 82, 91]]]][0][0][0][1]}}]]];
var F = E[0][0][0].heh.hehe * A + B + D.A.yo / A + C;
console.log(F);

然后变为:

var D = 10 / 38 * 10 + 38;
var E = [[[[12, 71, 82, 91]]]][0][0][0][1];
var F = E * 10 + 21 + D / 10 + 38;
console.log(F);

然后变为:

var D = 10 / 38 * 10 + 38;
var F = 71 * 10 + 21 + D / 10 + 38;
console.log(F);

然后变为:

var F = 769 + (100 / 38 + 38) / 10;
console.log(F);