While working on a RC4 based encryption function, i was faced with a strange problem. FYI, i'm not familar with encrytion/decryption, in fact the only encryption function i really understand is rot13. But for such rookies as i am, the www and Google was made ;\)

To implement a RC4 function you mostly need the operators XOR (^) and Mod, as well as the functions Asc(), Chr() and Len(). Because i never get the correct encryption result, i decided to do some testing on Chr() and Len()
 Code:
dim $OutString, $i

for $i=128 to 143  ; -> 16 Chars
  $OutString = $OutString + chr($i)
next
; Big Surprise
messagebox("Length of should be 16 but it is " + len($Outstring), "String Length")

; Now we split the loop to detect where the additional char is hiding
dim $OutString1, $OutString2, $OutString3, $OutString4

for $i=128 to 131 ; -> 4 Chars
  $OutString1 = $OutString1 + chr($i)
next
for $i=132 to 135; -> 4 Chars
  $OutString2 = $OutString3 + chr($i)
next
for $i=136 to 139; -> 4 Chars
  $OutString3 = $OutString3 + chr($i)
next
for $i=140 to 143; -> 4 Chars
  $OutString4 = $OutString4 + chr($i)
next

; Bigger Surprise :-)
messagebox("Length of $$Outstring should be 16 but it is " + len($Outstring) + @crlf +
           "Length of $$Outstring1 should be 4 but it is " + len($Outstring1) + @crlf +
           "Length of $$Outstring2 should be 4 but it is " + len($Outstring2) + @crlf +
           "Length of $$Outstring3 should be 4 but it is " + len($Outstring3) + @crlf +
           "Length of $$Outstring4 should be 4 but it is " + len($Outstring4), "String Length")

; Let's take a look on the content of $Outstring
for $i=1 to len($Outstring)
  messagebox("This is the Asc-Value of Char #" + $i + " inside $$OutString: " + Asc(substr($Outstring, $i, 1)) + " (should be " + cstr($i + 127) + ")", "Asc()")
next

Ok, i'll never get the encryption function to work correctly, if there is no "1 to 1"-relation between Asc() and Chr() and the length of the inputstring equals the length of the outputstring

Any ideas?
--
Andre

_________________________
The trouble with the world is that the stupid are cocksure and the intelligent are full of doubt. (Bertrand Russell)