Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help converting vb2008 code to vb6

Status
Not open for further replies.

davidck88

Programmer
Jan 5, 2009
27
0
0
NL
Hi all i got a CreateR1 function that takes name and hard drive serial number and supposed to return R1 value. The function was actually written on vb2008 but i want some help converting it to vb6. When i post the code on vb6 visual studio some parts of the code shows on red( as i pointed in the code below). So i be happy if you guys help me convert those part to vb6.
Thanks in advance.

Code:
Private Function DecryptPass(ByVal sNic As String, ByVal sSerial As String, ByVal sEncryptedPass As String) As String
        'Create R1 Encryption Key
        Dim R1 As String 
        R1= CreateR1(sNic, sSerial)
        'Decrypt Password
        DecryptedPass(R1, sEncryptedPass)
    End Function

vb2008 code:
Code:
Private Function CreateR1(ByVal Nic As String, ByVal Serial As String) As String
        ''Dim s As String = String.Empty
        Dim s As String
            s = vbNullString
        Dim i As Integer
        i = 0
        If Nic.Length > Serial.Length Then
            For Each c As Char In Nic ======================>Shows on red
                Dim sTemp As String
                Try
                    sTemp = Serial.Chars(i)
                    s = s & Nic.Chars(i) & sTemp
                Catch
                    s = s & Nic.Chars(i)
                End Try            ======================>Shows on red
                i = i + 1
            Next
        Else
            For Each c As Char In Serial ======================>Shows on red
                Dim sTemp As String
                Try
                    sTemp = Nic.Chars(i)
                    s = s & sTemp & Serial.Chars(i)
                Catch
                    s = s & Serial.Chars(i)
                End Try                ======================>Shows on red
                i = i + 1
            Next
        End If
       '' Return s.Substring(s.Length - 1) & s.Substring(0, s.Length - 1)
        CreateR1 = s.Substring(s.Length - 1) & s.Substring(0, s.Length - 1)
    End Function
CreateR1
 
Got to admit, my cryptography knowledge isn't particularly spectacular but after a quick google I know what you're talking about with the Vigenère cipher [wink]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
HarleyQuinn and strongm thank you both.
Having this constrain that no nick can be less then 5 characters(Minimum 5 characters).I don't know about limitation of serial(is in Hex format and it is hard drive serial) name.Having all the above in mind do you guys think there is any chance that Nic becomes smaller then serial(In hex format)?

I think i will ask the author to privde me with more sample data ...possible a sample data
that nick is smaller then serial!!

strong does your new solution will work even if there is not space between sEncrypted?

Furthermore,is it possible to reverse the code so it takes DecryptPass=ataturk and returns sEncrypted=2698 3368 2707 3561 2998 3567 2905?
 
strong does your new solution will work even if there is not space between sEncrypted?
No, but it would be simple enough to write something to add a space after every fourth character (it might not be the quickest way to add the space but to show strongm I take in what he posts you could very easily do this with regular expressions [wink]).

Furthermore,is it possible to reverse the code so it takes DecryptPass=ataturk and returns sEncrypted=2698 3368 2707 3561 2998 3567 2905?
Yes, quite possible, you (on a very basic level) employ the logic in the decryption and reverse it.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
>strong does your new solution will work even if there is not space between sEncrypted?

Not as it stands, no. But since you know VB6 it shouldn't be too much work to make the minor modifications necessary.

>is it possible to reverse the code ... returns sEncrypted=2698 3368 2707 3561 2998 3567 2905

No

Mainly because the 4th digit in each numeric block is discarded in the decryption. The decryption routine does not care at all what that digit is, and thus there is no information about how or why those particular digits were chosen. It may simply be random or there may be some sort of algorithm that gerates it (e.g. some sort of check character); we just can't tell from whjat we have here. And since we can't tell we can't recreate it

(try passing "269- 336- 270- 356- 299- 356- 290-" as sEncrypted to my DecryptedPass and you'll still get "ataturk)
 
strongm said:
Mainly because the 4th digit in each numeric block is discarded in the decryption. The decryption routine does not care at all what that digit is, and thus there is no information about how or why those particular digits were chosen. It may simply be random or there may be some sort of algorithm that gerates it (e.g. some sort of check character); we just can't tell from whjat we have here. And since we can't tell we can't recreate it
That's a very good point, I'd not allowed that there might be some logic rather than a random single digit integer added to the three digits.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I think you're right.

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top