Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Registration KEY
Message
De
18/03/2003 14:25:03
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00766017
Message ID:
00767201
Vues:
46
What I meant by "rotating" the translation table is illustrated by the following example:
cTran1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
cTran2 = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"
x = Encode("Hello, world")
? x
? Decode(x)
RETURN

FUNCTION Encode
    PARAMETER cRaw
    LOCAL I,cRet,cTmp

    cRet = ""
    FOR I=1 TO LEN(m.cRaw)
        cTmp = SUBSTR(m.cRaw,m.I,1)
        nPos = AT(m.cTmp,m.cTran1)
        IF m.nPos>0 THEN
            cRet = m.cRet + SUBSTR(cTran2,((m.nPos+m.I-2)%LEN(m.cTran1))+1,1)
        ELSE
            cRet = m.cRet + m.cTmp
        ENDIF
    ENDFOR
    RETURN m.cRet
ENDPROC

FUNCTION Decode
    PARAMETERS cCode
    LOCAL I,cRet

    cRet = ""
    FOR I=1 TO LEN(m.cCode)
        cTmp = SUBSTR(m.cCode,m.I,1)
        nPos = AT(m.cTmp,m.cTran2)
        IF m.nPos>0 THEN
            cRet = m.cRet + SUBSTR(m.cTran1,(m.nPos-m.I)%LEN(m.cTran2)+1,1)
        ELSE
            cRet = m.cRet + m.cTmp
        ENDIF
    ENDFOR
    RETURN m.cRet
ENDPROC
The orignal encoding that I started with is a simple ROT13 (the alphabetic characters are "rotated" by 13 characters). I then proceeded to add a minor modification that would "shift" the encodings with each character to make the encoding a bit less obvious.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform