G
G
GrayL2017-03-11 18:12:35
JavaScript
GrayL, 2017-03-11 18:12:35

Convert JavaScript to Delphi?

Hello, please help me to find the error in the code

var a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN0PQRSTUVWXYZO123456789+/="
function o(t) {
    if (!t || t.length % 4 == 1)
        return !1;
    for (var i, e, o = 0, s = 0, r = ""; e = t.charAt(s++); ){
        e = a.indexOf(e), ~e && (i = o % 4 ? 64 * i + e : e, o++ % 4) && (r += String.fromCharCode(255 & i >> (-2 * o & 6)));
    }
    return r

function sar32(value, shift: longint): longint;
asm
  mov ecx, edx
  sar eax, cl
  end;

function FromCharCode(ch:array of byte):AnsiString;
var L:Integer;
begin
    L := Length(ch);
    SetLength(result, L);
    if L > 0 then Move(ch[0], result[1], L);
end;

function o(t:string): string;
var
o, s, i, eint :integer;
r :string;
ch : array[0..500] of byte;
ec : char;
const
a : string = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN0PQRSTUVWXYZO123456789+/=';
begin
o := 0;
i := 0;
if (t = '') or (Length(t) mod 4 = 1) then
  r := 'False';
for s := 1 to Length(t) do
  begin
    eint := AnsiPos(t[s], a) - 1;
    if eint <> -1 then
      begin
        i := ifThen((o mod 4) <> 0, 64 * i + eint, eint);
        o := o + 1;
        ch[s] := (255 and sar32(i, (-2 * o and 6)));
        if inttostr(ch[s]) <> '0' then
          begin
            r := r + FromCharCode(ch[s]);
          end;
      end;
  end;
  result := r;
end;

An example of calling JS
92c6aca4695c4e4889e49e58cd8bcba7.PNG
a in Delphi does not quite correctly work out
5f2934c3f94046e9be2fedeb05a2a29d.PNG
the link to the js source code

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rou1997, 2017-03-11
@Rou1997

This doesn’t even look like laboratory work, rather like a project of some kind of bot, so the logical question is: I’ll leave everything here and I’ll help you, but will you get money?
You do not need help, the problem is solvable, there are at least two ways, the first is to learn to analyze and debug, the second is an alternative, connect a ready-made JS "engine", if you wanted, you would solve it faster than me, since you are in the know I don't even know what it is or where.
And the #bytecode tag has nothing to do with it.

G
GrayL, 2017-03-11
@GrayL

figured out, the problem was also due to differences in functions
and in delphi

chr(0) // ничего не возвращает
//заменил на 
chr(32) // ->> ' '

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question