Help on translating to TSQL

  • I need help translating this code into T-SQL Code:

    *

    * PARAMETERS:

    * tcAction = "E"ncrypt/"D"ecrypt

    * tcString = character string to be Encrypted/Decrypted

    *

    *

    PARAMETERS tcAction, tcString

    LOCAL lnLen, ;

    lcString, ;

    lnXX, ;

    lnCharPos, ;

    lnAscChar, ;

    lcString2, ;

    lcRetVal, ;

    lcAction

    IF TYPE("m.gcAscii") = "U" ;

    OR NOT LEFTC(m.gcAscii,1) = CHR(255) ;

    OR NOT RIGHTC(m.gcAscii,1) = CHR(0)

    PUBLIC gcAscii

    gcAscii = SPACE(0)

    FOR lnXX = 255 TO 0 STEP -1

    gcAscii = m.gcAscii + CHR(m.lnXX)

    ENDFOR

    ENDIF

    lnLen = LENC(m.tcString)

    IF m.lcAction = "E" &&& encrypt

    lcString = SPACE(0)

    FOR lnXX = 1 TO lnLen

    lnCharPos = m.lnLen-m.lnXX+1

    lnAscChar = ASC(SUBSTRC(m.tcString,m.lnCharPos,1))+IIF(MOD(m.lnXX,2)=0,1,2)

    lcString = m.lcString + CHR(m.lnAscChar)

    ENDFOR

    RETURN SYS(15,m.gcAscii,m.lcString)

    *** SYS(15, .. , ..) Does a position translation based upon the ACSII value of each character in the string.

    ELSE &&& lcAction = "D" decrypt

    lcString = SYS(15,m.gcAscii,m.tcString)

    STORE SPACE(0) TO lcString2, lcRetVal

    FOR lnXX = 1 TO lnLen

    lcString2 = m.lcString2 + CHR(ASC(SUBSTRC(m.lcString,m.lnXX,1)) - IIF(MOD(m.lnXX,2)=0,1,2))

    * if you'd like it a little more scrambled, use this variation

    * and pay a .01/per penalty:

    *lcString2 = lcString2 + chr(asc(substrc(lcString,lnXX,1)) - ;

    IIF(mod(lnXX,7)=0,2,IIF(mod(lnXX,4)=0,1,-1)))

    ENDFOR

    FOR lnXX = 1 to lnLen

    lcRetVal = m.lcRetVal + SUBSTRC(m.lcString2,m.lnLen-m.lnXX+1,1)

    ENDFOR

    RETURN m.lcRetVal

    ENDIF

  • Do you know T-SQL at all? We aren't going to do your work for you. If you need help with certain aspects of T-SQL or patterns the forum is a good place for that, but this is a place to get hints and pointers, not solutions written for you.

  • I have tried different approaches. I posted a second thread with one of the approaches. ANY help would be appreciated. Thank you for your time on this.

    Mike

  • What are you trying to do here? I can't read that code well enough to tell what it's doing.

    If you can describe what the end result is supposed to be, I can probably help.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • David is correct on the the other thread about the @C varchar(10). I haven't looked at the code you posted too closely but it appears be a matter of looping and string building. If this is so then you are on the right track with while/begin/end. Do you also have to decrypt in the T-SQL code? You can use parameters in a stored procedure to approximate the code you posted as well.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply