Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Delphi to VB6 code conversion

Featured Replies

Posted

Hi

Can anyone convert this delphi code to BV6?

procedure TKeyGen.Button1Click(Sender: TObject);
const Const_Array : array[0..7] of Char = ('e','n','c','r','y','w','e','b');
Var
StrName, Part2, Code : string;
i, AL, Last_Char  : Integer;

begin

  Code  := '' ;
  StrName := Edit1.Text;
  If StrName = '' then
  Edit2.Text := 'Enter your Name !!!'
  else
  Begin
  For i := 0 to length(StrName) - 1 do
  begin
    AL := ((Ord(StrName[i + 1]) + (i) + Length(StrName) + Ord(Const_Array[(I and 80000007)])) mod 10) + 48;
    Code := Char (AL) + Code  ;
  end;

    Last_Char := ((Length(StrName) + 112) mod 10) + 48;
 Edit2.Text := Code + Char(Last_Char);
  end;
end;

 

 

THANKS

Delphi registration code.txt

Edited by tarequl.hassan

  • 3 weeks later...
  • Author

Have anyone tried?

@tarequl.hassan

I understand this is not what you want to hear but IMHO you should try converting it on your own, instead of asking others to do so for you. It will be more rewarding. :)
I mean: the code is not that difficult to understand and with a couple of online searches you would find the way to convert it, if you already know VB6.

Personally I think you would just need the following links to understand that code.

http://www.delphibasics.co.uk/Article.asp?Name=Arrays
http://www.delphibasics.co.uk/RTL.asp?Name=ord
http://www.delphibasics.co.uk/rtl.asp?name=char

Good luck!

Regards,
Tony

 

Edited by tonyweb

Try this. I'm not sure if this is correct (haven't tried).

Procedure keygen_click()

Dim enc = "encryweb"

If (Len(Text1.Text) = 0) Then
    Text2.Text = "Enter some name!"
    Exit Sub
End If

For i = 1 to Len(Text1.Text):
     code = code & Chr(Asc(Mid(Text1.Text, i + 1, 1)) + i + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)
Next i

code = code & Chr(((Len(Text1.Text) + 112) mod 10) + 48)

Text2.Text = code

Also I'm not sure why there is 'mod 10' in this line:
Ord(Const_Array[(I and 80000007)])) mod 10)
String is 8 chars so 'and ' will work like 'mod' in this case and give us current 'string[i]'.

VB6 is not 0 based ( per the' i' starting with 1, not 0 in the for loop), therefore this will not work

code = code & Chr(Asc(Mid(Text1.Text, i + 1, 1)) + i + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)

it will have to be something more like this like this providing the rest works

code = code & Chr(Asc(Mid(Text1.Text, i, 1)) + (i - 1) + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)

also the Delphi code reads

Code := Char (AL) + Code  ;

so shouldn't the vb6  code read

code = Chr(Asc(Mid(Text1.Text, i, 1)) + (i - 1) + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48) & code

 just my thoughts...

T-rad

  • 3 weeks later...
On 4/30/2021 at 8:25 PM, ToMKoL said:

Try this. I'm not sure if this is correct (haven't tried).

Procedure keygen_click()

Dim enc = "encryweb"

If (Len(Text1.Text) = 0) Then
    Text2.Text = "Enter some name!"
    Exit Sub
End If

For i = 1 to Len(Text1.Text):
     code = code & Chr(Asc(Mid(Text1.Text, i + 1, 1)) + i + Len(Text1.Text) + Asc(Mid(enc, (i mod 7), 1)) + 48)
Next i

code = code & Chr(((Len(Text1.Text) + 112) mod 10) + 48)

Text2.Text = code

Also I'm not sure why there is 'mod 10' in this line:
Ord(Const_Array[(I and 80000007)])) mod 10)
String is 8 chars so 'and ' will work like 'mod' in this case and give us current 'string[i]'.

This code is not working for me. Anyone tested?

Try this one. Tested and it should work as delphi version.

delphivb.zip

  • Author
20 hours ago, ToMKoL said:

Try this one. Tested and it should work as delphi version.

delphivb.zip 5.06 kB · 3 downloads

Thanks. But it doesn't generate the actual results. I am sending the Delphi and assembly one for checking.

@ToMKoL: I'm able to spot one mistake in your code:

Asc(Mid(enc, (i Mod 7), i))

should most likely read

Asc(Mid(enc, (i Mod 8), 1))

Maybe there are more issues, but I'm not really a VB wizard... ;) 

@tarequl.hassan: I've replied to You in PM. Any compiled version will be fine to check.

@kao: Thanks for spotting error. I'm also no VB coder (this is my second program in basic). Also my Delphi coding ended over 20+ years ago with D4 so I might forgot few things and maybe read source code wrong.

Will correct mistake pointed out and upload corrected version.

  • Author
1 hour ago, ToMKoL said:

@tarequl.hassan: I've replied to You in PM. Any compiled version will be fine to check.

@kao: Thanks for spotting error. I'm also no VB coder (this is my second program in basic). Also my Delphi coding ended over 20+ years ago with D4 so I might forgot few things and maybe read source code wrong.

Will correct mistake pointed out and upload corrected version.

Please find the proggie in delphi and masm. Woul you please check?

In ASM.rar Project1.rar

There were few more small mistakes, including one in my earlier fix. :) 

This one is tested and output matches your ASM/Delphi versions.

Option Explicit
Procedure keygen_click()
    Dim enc As String
    Dim username As String
    Dim serial As String
    Dim idx1 As Integer
    Dim i As Integer
    
    enc = "encryweb"
    
    username = Text1.Text
    If (Len(username) = 0) Then
        Text2.Text = "Enter some name!"
        Exit Sub
    End If

    serial = ""
    For i = 0 To Len(username) - 1
        ' calculate magic number
        idx1 = Asc(Mid(username, i + 1, 1)) + _
            i + _
            Len(username) + _
            Asc(Mid(enc, (i Mod 8) + 1, 1))
        ' prepend the symbol to generated serial
        serial = Chr(idx1 Mod 10 + 48) & serial
    Next i
    
    ' finally, append one more symbol that depends on username length
    serial = serial & Chr(((Len(username) + 112) Mod 10) + 48)
    Text2.Text = serial
End Sub

 

@tarequl.hassanPlease check snippet provided by kao. Hope that this time it will work for You.

  • Author
2 minutes ago, ToMKoL said:

@tarequl.hassanPlease check snippet provided by kao. Hope that this time it will work for You.

I sent a mail to you with link. Have you checked?

Thanks

  • Author
18 hours ago, kao said:

There were few more small mistakes, including one in my earlier fix. :) 

This one is tested and output matches your ASM/Delphi versions.


Option Explicit
Procedure keygen_click()
    Dim enc As String
    Dim username As String
    Dim serial As String
    Dim idx1 As Integer
    Dim i As Integer
    
    enc = "encryweb"
    
    username = Text1.Text
    If (Len(username) = 0) Then
        Text2.Text = "Enter some name!"
        Exit Sub
    End If

    serial = ""
    For i = 0 To Len(username) - 1
        ' calculate magic number
        idx1 = Asc(Mid(username, i + 1, 1)) + _
            i + _
            Len(username) + _
            Asc(Mid(enc, (i Mod 8) + 1, 1))
        ' prepend the symbol to generated serial
        serial = Chr(idx1 Mod 10 + 48) & serial
    Next i
    
    ' finally, append one more symbol that depends on username length
    serial = serial & Chr(((Len(username) + 112) Mod 10) + 48)
    Text2.Text = serial
End Sub

 

Great!!! It works perfectly.

 

Thanks kao.

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.