08-19-2005, 05:53 PM
I recognised whad Chaos said but I didn't know it per se,
but It speeded up the only thing I knew how to do in encryption: XOR
For speed I only coded it to support keys with a 2^x length although it
will work with other lengths but not use the key to the full extent...
[syntax="qbasic"]option explicit
option dynamic
declare function xorstring(msg as string, key as string) as string
function xorstring(msg as string, key as string) as string
dim ans as string
dim l as integer
ans=space$(len(msg))
l=len(key)-1
for n=0 to len(msg)-1
ans[n]=msg[n] xor key[n and l]
next
xorstring=ans
end function[/syntax]
Each benchmark were made on a P4 2.6 GHz 1,000,000 times
with the function above called with fixed length strings filled with garble
unit: byte (b)
200b msg, 128b key: 3.53µs
2,000b msg, 1024b key: 5.65µs
20,000b msg, 16384b key: 27.7µs
but It speeded up the only thing I knew how to do in encryption: XOR
For speed I only coded it to support keys with a 2^x length although it
will work with other lengths but not use the key to the full extent...
[syntax="qbasic"]option explicit
option dynamic
declare function xorstring(msg as string, key as string) as string
function xorstring(msg as string, key as string) as string
dim ans as string
dim l as integer
ans=space$(len(msg))
l=len(key)-1
for n=0 to len(msg)-1
ans[n]=msg[n] xor key[n and l]
next
xorstring=ans
end function[/syntax]
Each benchmark were made on a P4 2.6 GHz 1,000,000 times
with the function above called with fixed length strings filled with garble
unit: byte (b)
200b msg, 128b key: 3.53µs
2,000b msg, 1024b key: 5.65µs
20,000b msg, 16384b key: 27.7µs
/post]