TYPE QRC4 EXTENDS QOBJECT
PRIVATE:
stateTable(256) AS BYTE
randomIndex AS BYTE
i AS LONG
j AS LONG
k AS LONG
n AS LONG
PUBLIC:
SUB Reset
FOR QRC4.i = 0 TO 255
QRC4.stateTable(QRC4.i) = QRC4.i
NEXT
QRC4.i = 0
QRC4.j = 0
END SUB
SUB Init (key AS STRING)
QRC4.Reset
QRC4.n = LEN(key)
IF 0 < QRC4.n THEN
QRC4.j = 0
FOR QRC4.i = 0 TO 255
QRC4.k = (QRC4.i MOD QRC4.n) + 1
QRC4.j = (QRC4.j + QRC4.stateTable(QRC4.i) + ASC(key[QRC4.k])) AND 255
SWAP QRC4.stateTable(QRC4.i), QRC4.stateTable(QRC4.j)
NEXT
END IF
QRC4.i = 0
QRC4.j = 0
END SUB
FUNCTION Pipe (str AS STRING) AS STRING
QRC4.n = LEN(str)
FOR QRC4.k = 1 TO QRC4.n
QRC4.i = (QRC4.i + 1) AND 255
QRC4.j = (QRC4.j + QRC4.stateTable(QRC4.i)) AND 255
QRC4.randomIndex = (QRC4.stateTable(QRC4.i) + QRC4.stateTable(QRC4.j)) AND 255
SWAP QRC4.stateTable(QRC4.i), QRC4.stateTable(QRC4.j)
result = result & CHR$(ASC(str[QRC4.k]) XOR QRC4.stateTable(QRC4.randomIndex))
NEXT
END FUNCTION
CONSTRUCTOR
Reset
END CONSTRUCTOR
END TYPE
|