Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Every living thing wants to survive. -- Spock, "The Ultimate Computer", stardate 4731.3


devel / comp.lang.javascript / Re: Help with reversing a function

SubjectAuthor
* Help with reversing a functionTenjin
`- Re: Help with reversing a functionJulio Di Egidio

1
Help with reversing a function

<ac3481db-6edc-40df-a6aa-e42be9e3a67fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17243&group=comp.lang.javascript#17243

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:a37:607:: with SMTP id 7mr22645051qkg.0.1630325631272;
Mon, 30 Aug 2021 05:13:51 -0700 (PDT)
X-Received: by 2002:a9d:67c1:: with SMTP id c1mr18886939otn.239.1630325630803;
Mon, 30 Aug 2021 05:13:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Mon, 30 Aug 2021 05:13:50 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=2a02:c7f:8b89:3d00:2c1a:a8f3:7a4a:d3ee;
posting-account=rQO11goAAAB7EmkYv78o2Y8czJwf8ODI
NNTP-Posting-Host: 2a02:c7f:8b89:3d00:2c1a:a8f3:7a4a:d3ee
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ac3481db-6edc-40df-a6aa-e42be9e3a67fn@googlegroups.com>
Subject: Help with reversing a function
From: jdiscordbusiness@gmail.com (Tenjin)
Injection-Date: Mon, 30 Aug 2021 12:13:51 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Tenjin - Mon, 30 Aug 2021 12:13 UTC

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Fun with && and ||</title>
<script type="text/javascript">
function g(s, C, m) {
console.log(String.fromCharCode(96 + C));
return (
(!C && !s[m]) ||
(C &&
s[m] &&
s[m++] == String.fromCharCode(96 + C) &&
f(s, (++C * C++ + C++ * ++C) >> ++m, --m))
);
}
</script>
</head>
<body style="text-align: center">
<form
onsubmit="alert((g(pass.value,1,0) ? 'Correct! The password is ' : 'Wrong! not ')+pass.value); return false;"
>
<div>
<input type="text" name="pass" />
<input type="submit" value="Login" />
</div>
</form>
</body>
</html>

I need some help in finding what the correct password is. So far I understand that te first character must contain an "a"

Re: Help with reversing a function

<12f0ca69-9363-4878-9548-29fa9fca14a7n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17244&group=comp.lang.javascript#17244

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:734c:: with SMTP id q12mr3206895qtp.192.1630422342074;
Tue, 31 Aug 2021 08:05:42 -0700 (PDT)
X-Received: by 2002:a05:6808:118:: with SMTP id b24mr3575777oie.0.1630422341781;
Tue, 31 Aug 2021 08:05:41 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Tue, 31 Aug 2021 08:05:41 -0700 (PDT)
In-Reply-To: <ac3481db-6edc-40df-a6aa-e42be9e3a67fn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=93.41.97.174; posting-account=F3H0JAgAAADcYVukktnHx7hFG5stjWse
NNTP-Posting-Host: 93.41.97.174
References: <ac3481db-6edc-40df-a6aa-e42be9e3a67fn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <12f0ca69-9363-4878-9548-29fa9fca14a7n@googlegroups.com>
Subject: Re: Help with reversing a function
From: julio@diegidio.name (Julio Di Egidio)
Injection-Date: Tue, 31 Aug 2021 15:05:42 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 157
 by: Julio Di Egidio - Tue, 31 Aug 2021 15:05 UTC

On Monday, 30 August 2021 at 14:14:45 UTC+2, Tenjin wrote:

> function g(s, C, m) {
> console.log(String.fromCharCode(96 + C));
> return (
> (!C && !s[m]) ||
> (C &&
> s[m] &&
> s[m++] == String.fromCharCode(96 + C) &&
> f(s, (++C * C++ + C++ * ++C) >> ++m, --m))

I take that should read 'g', not 'f'.

> );
> }

> onsubmit="alert((g(pass.value,1,0) ? 'Correct! The password is ' : 'Wrong! not ')+pass.value); return false;"

> I need some help in finding what the correct password is. So far I understand that te first character must contain an "a"

1) Firstly, few transformations [best viewed in monospace]:

1.1) Some clean-up and fixes:

(Fixed the exit conditions: note that 'false || undefined' is 'undefined', not 'false'.)

function g_1(s, c, m) {
var L = s.length;
return (
(!c && m === L)
|| (c && m < L
&& s[m++] === String.fromCharCode(96+c)
&& g_1(s, (++c*c++ + c++*++c) >> ++m, --m))
);
}

1.2) Resolve increments:

function g_2(s, c, m) {
var L = s.length;
return (
(!c && m === L)
|| (c && m < L
&& s[m] === String.fromCharCode(96+c)
&& g_2(s, ((c+1)*(c+1) + (c+2)*(c+4)) >> (m+2), (m+1)))
);
}

1.3) Unwind recursion and subsume 'm':

(We can subsume 'm' since it is the index into the string, bound to start from zero.)

function g(s, c) {
var L = s.length;
if (c === 0) { // short-cut
return L === 0;
}
for (var m = 0; m < L; ++m) {
if(!(s[m] === String.fromCharCode(96+c))) {
return false;
}
c = (c+1)*(c+1) + (c+2)*(c+4) >> m+2;
}
return c === 0;
}

2) Now from 1.3 we can extract the password generator:

(There is in 1.3 simply a comparison char by char with the expected password, so we can extrapolate the logic that just produces the password.)

function h(c) {
var s = "";
for (var m = 0; c !== 0; ++m) {
s += String.fromCharCode(96+c);
c = (c+1)*(c+1) + (c+2)*(c+4) >> m+2;
}
return s;
}

T) Some basic (and quick) testing in the console:

(Preliminarily, copy-paste the functions g_1, g, and h in the console.)

T.1) Check the code transformation:

-> h(1)
<- "adiorlc"

-> g_1("adiorlc", 1, 0)
<- true

-> g_1("adiorlC", 1, 0)
<- false

-> g_1("adiorl", 1, 0)
<- false

-> g("adiorlc", 1)
<- true

-> g("adiorlC", 1)
<- false

-> g("adiorl", 1)
<- false

T.2) Test the roundtrip:

-> g(h(100), 100)
<- true

-> g(h(100), 99)
<- false

-> var lo = -9, hi = 5; for (var c = lo; c <= hi; ++c) { var s = h(c), e_1 = g_1(s, c, 0), e = g(s, c); console.log(c, s, e_1, e); }
-9 "Wxĉວ셭ﵗ黡繗目护눕뙉ꯡ찁ᗋȫa" true true
-8 "XrÄմ鸾늲户抉韙哵많䮑䰶ⵐࡄ" true true
-7 "Yl‘ƥ᩻侚碸酟풂툲㒂ጕ鮐벋ቘā" true true
-6 "Zhy»ɼ␼ᨲ皏徕騐鼧弫Ⱪ빗ᩓ́c" true true
-5 "[diorlc" true true
-4 "\\bddb" true true
-3 "]" true true
-2 "^" true true
-1 "_" true true
0 "" true true
1 "adiorlc" true true
2 "bhy»ɼ␼ᨲ皏徕騐鼧弫Ⱪ빗ᩓ́c" true true
3 "cl‘ƥ᩻侚碸酟풂툲㒂ጕ鮐벋ቘā" true true
4 "drÄմ鸾늲户抉韙哵많䮑䰶ⵐࡄ" true true
5 "exĉວ셭ﵗ黡繗目护눕뙉ꯡ찁ᗋȫa" true true
<- undefined

Seems to work fine for all 'c' integer, but I have neither *proved* that, nor I have proved that 'h' always terminates.

N.B. It is definitely NOT a secure scheme...

Have fun,

Julio


devel / comp.lang.javascript / Re: Help with reversing a function

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor