0

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
5
  • the whole conversion thing is very confusing to me... its using some functions that I cant find equivalent c# code for.. Commented Dec 25, 2010 at 3:18
  • 2
    Which ones are you having trouble finding? Ask specific questions and you'll get specific answers. Commented Dec 25, 2010 at 3:25
  • have you tried putting it through a vb.net to c-sharp converter ? Commented Dec 25, 2010 at 4:13
  • Should this be tagged VB instead of asp-classic? Don't see anything asp specific here. Commented Dec 25, 2010 at 6:43
  • @xoail, you should include a few sample input/outputs so someone can confirm their conversion works properly if they rewrite it for you. @yodaj007 I agree with you, this is really vbscript specific. Commented Jan 13, 2011 at 20:20

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.