Converting old Delphi key generator

Hi All,
Here is a bit of code I found ages ago.
Could anyone tell me what to do with the ORD function bit.

function GetRegString(Company, ABN,rType: string): string;
  S,F,P : string;
  bdate, Key, xKey :string;
  I, N, PN: LongInt;



  S:=Company + ABN + F
  S:= uppercase(S);
  for i:=1 to length(S) do
      if i <> 1 then Pn:=ord(S[i-1]) else Pn:=ord(S[1]);
  S:=IntToHex(N, 8);
  while S[1] = '0' do Delete(S, 1, 1);
  Result:=F + '-' + S;

I assume the ord is a bitwise type rotation, but to hard for little old me. lol


Given the code, I think the closest equivalent is the Asc function. Something like:

if i <> 1 then
  Pn = S.Mid( i -1, 1 ).Asc
  Pn = S.Left( 1 ).Asc
end if
N = Pn * ( N + S.Mid( i, 1 ).Asc )

Thanks for that will test it.

Once you’ve got it working, post the code here. If you translate the Delphi code to Xojo as written, it will be slower than it needs to be.

Thanks for that.
Got it working.

Method  GenKey (abn as string , name as string) as string

  dim i,n,PN as integer
  dim F,S as string
  F ="NAME"
  S = name + abn + F
  S = uppercase(S)
  for i = 1 to len(S)
    if i <> 1 then
      Pn = S.Mid( i -1, 1 ).Asc
      Pn = S.Left( 1 ).Asc
    end if
    N = Pn * ( N + S.Mid( i, 1 ).Asc )
  S = hex(N) 
  Return  S

Works well enough for me, thanks

That’s good. My only suggestion is to cache the value for Len(S). Each iteration of the loop will calculate that again and, if your strings are long, you’ll wonder why it’s taking so much time.

dim lastCharIndex as integer = S.Len
for i = 1 to lastCharIndex

Put the string in a memoryblock and use the Byte() accessor to manipulate the characters. Or at least use MidB/LeftB/LenB to get at single byte values, not characters which could be multi-byte.