简体   繁体   中英

Help converting some classic asp code to c# (.net 3.5)

I have this block of code in a .asp file that I am struggling to convert to c#... can anyone help me?

Function EncodeCPT(ByVal sPinCode, ByVal iOfferCode, ByVal sShortKey, ByVal sLongKey)
    Dim vob(2), encodeModulo(256), decodeX, ocode
    decodeX = " abcdefghijklmnopqrstuvwxyz0123456789!$%()*+,-.@;<=>?[]^_{|}~"
    if len(iOfferCode) = 5 then
        ocode = iOfferCode Mod 10000
    else
        ocode = iOfferCode
    end if
    vob(1) = ocode Mod 100
    vob(0) = Int((ocode-vob(1)) / 100)
    For i = 1 To 256
        encodeModulo(i) = 0
    Next
    For i = 0 To 60
        encodeModulo(asc(mid(decodeX, i + 1, 1))) = i
    Next
    'append offer code to key
    sPinCode = lcase(sPinCode) & iOfferCode
    If Len(sPinCode) < 20 Then
        sPinCode = Left(sPinCode & " couponsincproduction", 20)
    End If
    'encode
    Dim i, q, j, k, sCPT, s1, s2, s3
    i = 0
    q = 0
    j = Len(sPinCode)
    k = Len(sShortKey)
    sCPT = ""
    For i = 1 To j
        s1 = encodeModulo(asc( mid(sPinCode, i, 1)) )
        s2 = 2 * encodeModulo( asc( mid(sShortKey, 1 + ((i - 1) Mod k), 1) ) )
        s3 = vob(i Mod 2)
        q = (q + s1 + s2 + s3) Mod 61
        sCPT = sCPT & mid(sLongKey, q + 1, 1)
    Next
    EncodeCPT = sCPT
End Function

What you have here seems to be pretty standard VBScript code.

Perhaps you could look at some C# tutorial to get the basics or maybe go for VB.NET instead of C#.

The syntax is pretty much the same as VBScript, but remember, the .NET framework is object oriented so some feature or functions are not implemented the same way.

For example, if you want to get the length of a string, you would be using myString.Length instead of Len(myString).

Here are a few C# and VB.NET tutorials for you to look at.

http://www.csharp-station.com/Tutorial.aspx

http://www.csharpkey.com/csharp/Lesson01.htm

http://www.programmersheaven.com/2/VB-NET-School

http://www.homeandlearn.co.uk/net/vbnet.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM