Javier, I guess you missed my earlier post, so here it is again:
function rc4 pText, pKey
-- initialize
repeat with i = 0 to 255
put i into S1[i]
end repeat
put 0 into i
repeat with n = 0 to 255
add 1 to i
if i > length(pkey) then put 1 into i
put charToNum(char i of pKey) into S2[n]
end repeat
put 0 into j
repeat with i = 0 to 255
put (j + S1[i] + S2[i]) mod 256 into j
put S1[i] into temp
put S1[j] into S1[i]
put temp into S1[j]
end repeat
-- encrypt/decrypt
put 0 into i ; put 0 into j
repeat for each char c in pText
put charToNum(c) into tChar
put (i + 1) mod 256 into i
put (j + S1[i]) mod 256 into j
put S1[i] into temp
put S1[j] into S1[i]
put temp into S1[j]
put (S1[i] + S1[j]) mod 256 into t
put S1[t] into K
put numToChar(tChar bitXor K) after tOutput
end repeat
return binToHex(tOutput)
end rc4
function binToHex pString
repeat for each char c in pString
get charToNum(c)
put baseConvert(it,10,16) into tTemp
if it < 16 then put "0" before tTemp
put tTemp after tHex
end repeat
return tHex
end binToHex
Best,
Mark Smith
On 13 Jul 2007, at 20:16, Javier Miranda wrote:
Can this "pseudocode" be implemented using Revolution? It´s an
encryption
alogorithm called Alleged RC4, there are a number of base
convesions and
module operations, also there is array manipulation. Itried and
failed
miserably.
FUNCION CifrarMensajeRC4(string Mensaje, string Key ) : string
NUMERO State[256], X = 0, Y = 0, Index1 = 0, Index2 = 0 , NMen, I
string MensajeCifrado = ""
INICIO
PARA I = 0 HASTA 255 HACER
State[I] = I
FIN PARA
PARA I = 0 to 255
Index2 = ( ObtieneASCII(key[Index1]) + State[I] + Index2 ) MODULE 256
IntercambiaValor( State[I], State[Index2] ) // exchange variable
values
Index1 = (Index1 + 1) MODULO lenght(Key)
FIN PARA
PARA I = 0 to lenght(Mensaje)-1
X = (X + 1) MODULO 256
Y = (State[X] + Y) MODULE 256
IntercambiaValor( State[X] , State[Y] )
NMen = ObtieneASCII(Mensaje[I]) XOR State[(State[X] + State[Y])
MODULE 256]
MensajeCifrado = MensajeCifrado + "-" +
RellenaCero(ConvierteAHexadecimal(NMen)) // add a 0 if its only
one char in
the string
END PARA
RETURN ObtieneSubCadena(MensajeCifrado, 1, LargoCadena
(MensajeCifrado) - 1);
end FUNCION
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
[email protected]
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution