C
C#3y ago
maria 🌟

❔ How i can convert a js function to c#

I have a VERY complex function on js and i want it to parse it to c#
20 Replies
Pobiega
Pobiega3y ago
There are no readymade tools for this. You could try throwing it at chatgpt and see if it works, but its very likely to make mistakes. best bet is to do it by hand
maria 🌟
maria 🌟OP3y ago
amm the function is this one
g = Math.round(1E11 * Math.random()) + "";
f = function() {
for (var v = [], w = 0; 64 > w;)
v[w] = 0 | 4294967296 * Math.sin(++w % Math.PI);
return function(y) {
var z, D, E, H = [z = 1732584193, D = 4023233417, ~z, ~D]
, F = []
, x = unescape(encodeURI(y)) + "\u0080"
, u = x.length;
y = --u / 4 + 2 | 15;
for (F[--y] = 8 * u; ~u;)
F[u >> 2] |= x.charCodeAt(u) << 8 * u--;
for (w = x = 0; w < y; w += 16) {
for (u = H; 64 > x; u = [E = u[3], z + ((E = u[0] + [z & D | ~z & E, E & z | ~E & D, z ^ D ^ E, D ^ (z | ~E)][u = x >> 4] + v[x] + ~~F[w | [x, 5 * x + 1, 3 * x + 5, 7 * x][u] & 15]) << (u = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21][4 * u + x++ % 4]) | E >>> -u), z, D])
z = u[1] | 0
, D = u[2];
for (x = 4; x;)
H[--x] += u[x]
}
for (y = ""; 32 > x;)
y += (H[x >> 3] >> 4 * (1 ^ x++) & 15).toString(16);
return y.split("").reverse().join("")
}
}();
k = "tryit-" + g + "-" + f(navigator.userAgent + f(navigator.userAgent + f(navigator.userAgent + g)));
g = Math.round(1E11 * Math.random()) + "";
f = function() {
for (var v = [], w = 0; 64 > w;)
v[w] = 0 | 4294967296 * Math.sin(++w % Math.PI);
return function(y) {
var z, D, E, H = [z = 1732584193, D = 4023233417, ~z, ~D]
, F = []
, x = unescape(encodeURI(y)) + "\u0080"
, u = x.length;
y = --u / 4 + 2 | 15;
for (F[--y] = 8 * u; ~u;)
F[u >> 2] |= x.charCodeAt(u) << 8 * u--;
for (w = x = 0; w < y; w += 16) {
for (u = H; 64 > x; u = [E = u[3], z + ((E = u[0] + [z & D | ~z & E, E & z | ~E & D, z ^ D ^ E, D ^ (z | ~E)][u = x >> 4] + v[x] + ~~F[w | [x, 5 * x + 1, 3 * x + 5, 7 * x][u] & 15]) << (u = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21][4 * u + x++ % 4]) | E >>> -u), z, D])
z = u[1] | 0
, D = u[2];
for (x = 4; x;)
H[--x] += u[x]
}
for (y = ""; 32 > x;)
y += (H[x >> 3] >> 4 * (1 ^ x++) & 15).toString(16);
return y.split("").reverse().join("")
}
}();
k = "tryit-" + g + "-" + f(navigator.userAgent + f(navigator.userAgent + f(navigator.userAgent + g)));
Pobiega
Pobiega3y ago
ah. obfuscated?
maria 🌟
maria 🌟OP3y ago
probably
Pobiega
Pobiega3y ago
¯\_(ツ)_/¯
maria 🌟
maria 🌟OP3y ago
Chat gpt just made it :0
static void Main(string[] args)
{
var g = (long)(1E11 * new Random().NextDouble());
var f = new Func<string, string>(y =>
{
var v = new uint[64];
for (var w = 0; w < 64; w++)
v[w] = 0 | (uint)(4294967296 * Math.Sin(++w % Math.PI));
var z = 1732584193U;
var D = 4023233417U;
var E = ~z;
var H = ~D;
var F = new uint[80];
var x = Encoding.UTF8.GetBytes(y);
var u = x.Length;
y = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(y)) + "\u0080";
u = --u / 4 + 2 | 15;
for (F[--u] = (uint)(8 * x.Length); ~u >= 0;)
F[u >> 2] |= (uint)x[u] << (8 * (~u & 3));
for (var w = x = 0; w < u; w += 16)
{
for (var u_ = z; u_ < z + 16; u_++)
F[u_] = F[w + ((u_ - z) % 16)];
for (var u_ = 16; u_ < 80; u_++)
F[u_] = ((F[u_ - 3] ^ F[u_ - 8] ^ F[u_ - 14] ^ F[u_ - 16]) << 1) | ((F[u_ - 3] ^ F[u_ - 8] ^ F[u_ - 14] ^ F[u_ - 16]) >> 31);
for (var u_ = z; u_ < z + 20; u_++)
{
var K = ((z << 5) | (z >> 27)) + ((D & E) | (~D & H)) + H + F[u_] + (uint)((w / 16) << 5) + z;
H = E;
E = D;
D = ((z << 30) | (z >> 2));
z = K;
}
z += u_;
D += E;
E += H;
H += z;
}
return string.Join("", BitConverter.GetBytes(z).Concat(BitConverter.GetBytes(D)).Concat(BitConverter.GetBytes(E)).Concat(BitConverter.GetBytes(H)).Select(b => b.ToString("x2"))).Reverse().Aggregate("", (a, b) => a + b);
});
var k = $"tryit-{g}-{f($"{Environment.OSVersion.VersionString}{f($"{Environment.OSVersion.VersionString}{f($"{Environment.OSVersion.VersionString}{g}")}")}")}";
}
static void Main(string[] args)
{
var g = (long)(1E11 * new Random().NextDouble());
var f = new Func<string, string>(y =>
{
var v = new uint[64];
for (var w = 0; w < 64; w++)
v[w] = 0 | (uint)(4294967296 * Math.Sin(++w % Math.PI));
var z = 1732584193U;
var D = 4023233417U;
var E = ~z;
var H = ~D;
var F = new uint[80];
var x = Encoding.UTF8.GetBytes(y);
var u = x.Length;
y = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(y)) + "\u0080";
u = --u / 4 + 2 | 15;
for (F[--u] = (uint)(8 * x.Length); ~u >= 0;)
F[u >> 2] |= (uint)x[u] << (8 * (~u & 3));
for (var w = x = 0; w < u; w += 16)
{
for (var u_ = z; u_ < z + 16; u_++)
F[u_] = F[w + ((u_ - z) % 16)];
for (var u_ = 16; u_ < 80; u_++)
F[u_] = ((F[u_ - 3] ^ F[u_ - 8] ^ F[u_ - 14] ^ F[u_ - 16]) << 1) | ((F[u_ - 3] ^ F[u_ - 8] ^ F[u_ - 14] ^ F[u_ - 16]) >> 31);
for (var u_ = z; u_ < z + 20; u_++)
{
var K = ((z << 5) | (z >> 27)) + ((D & E) | (~D & H)) + H + F[u_] + (uint)((w / 16) << 5) + z;
H = E;
E = D;
D = ((z << 30) | (z >> 2));
z = K;
}
z += u_;
D += E;
E += H;
H += z;
}
return string.Join("", BitConverter.GetBytes(z).Concat(BitConverter.GetBytes(D)).Concat(BitConverter.GetBytes(E)).Concat(BitConverter.GetBytes(H)).Select(b => b.ToString("x2"))).Reverse().Aggregate("", (a, b) => a + b);
});
var k = $"tryit-{g}-{f($"{Environment.OSVersion.VersionString}{f($"{Environment.OSVersion.VersionString}{f($"{Environment.OSVersion.VersionString}{g}")}")}")}";
}
Pobiega
Pobiega3y ago
Does it work thou, are all inputs and respective outputs the same?
maria 🌟
maria 🌟OP3y ago
maria 🌟
maria 🌟OP3y ago
nope
Pobiega
Pobiega3y ago
also I can already tell its not the same unescape(encodeURI(y)) + "\u0080" does not "translate" into Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(y)) + "\u0080";
maria 🌟
maria 🌟OP3y ago
i think f its just md5 hash Oh its like a modified md5 hash function :C OMG I DID IT
maria 🌟
maria 🌟OP3y ago
i feel proud of myself and of gpt 🥲
ero
ero3y ago
what the fuck is 1E11 oh it's the exponent... very confusing syntax that the using in the GenerateApiKey method is pointless
Jimmacle
Jimmacle3y ago
you shouldn't be creating a new instance of Random inside the method it's seeded with system time by default, so if you call it fast enough it will generate duplicates ah, news to me
MODiX
MODiX3y ago
Retax#0813
REPL Result: Success
for (int i = 0; i < 10; i++) Console.WriteLine(new Random().Next(10));
for (int i = 0; i < 10; i++) Console.WriteLine(new Random().Next(10));
Console Output
0
4
4
3
0
4
2
3
0
2
0
4
4
3
0
4
2
3
0
2
Compile: 511.179ms | Execution: 43.324ms | React with ❌ to remove this embed.
maria 🌟
maria 🌟OP3y ago
then what you recomend
Jimmacle
Jimmacle3y ago
read the conversation that followed and you'll have answers
maria 🌟
maria 🌟OP3y ago
i see thath is fixed but what was you gonna say
Jimmacle
Jimmacle3y ago
that was it just reuse one instance
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?