Help converting some classic asp code to c# (.net 3.5)
        Posted  
        
            by 
                xoail
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by xoail
        
        
        
        Published on 2010-12-25T02:52:18Z
        Indexed on 
            2010/12/25
            2:54 UTC
        
        
        Read the original article
        Hit count: 514
        
c#
|asp-classic
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
© Stack Overflow or respective owner