01-11-2006, 11:27 AM
The problem was due to string copying; the string was getting truncated at the null character when it was being passed in. The original code you posted earlier used the same string. Passing by reference and explicitly copying solves the problem. Here is the updated code:
Code:
option explicit
option byval
function ZackText( byref text as string, key as string ) as string
dim as string result => text
dim as integer textIndex = 0, keyIndex = 0
while( textIndex < len(text) )
if( keyIndex = len(key) ) then keyIndex = 0
result[textIndex] xor= key[keyIndex]
textIndex += 1 : keyIndex += 1
wend
return result
end function
function WinerText( byref text as string, key as string ) as string
dim as string result => text
dim as integer L = len(key)
dim as integer i, Pass
for i = 1 to len(text)
Pass = asc(mid$(key, (i mod L) - L * ((i mod L) = 0), 1))
mid$(result,i,1) = chr$(asc(mid$(text,i,1)) xor Pass)
next
return result
end function
const originalText as string = "Move 32nd platoon SSW 10 miles"
const key as string = "armypassword"
dim as string zackedText : zackedText = ZackText( originalText, key )
dim as string wineredText : wineredText = WinerText( originalText, key )
dim as string deZackedText : deZackedText = ZackText( zackedText, key )
dim as string deWineredText : deWineredText = WinerText( wineredText, key )
print " original Text: " ; originalText
print " Password: " ; key
print
print " Zacked text: " ; zackedText
print " Winered text: " ; wineredText
print
print " DeZacked text: " ; deZackedText
print " DeWinered text: " ; deWineredText
sleep : end 0
stylin: