Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Here's another....file I/O difficulties.
#28
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:
Reply


Messages In This Thread
Here's another....file I/O difficulties. - by Anonymous - 01-10-2006, 01:26 PM
Here's another....file I/O difficulties. - by stylin - 01-11-2006, 11:27 AM
Here's another....file I/O difficulties. - by DrV - 01-16-2006, 03:08 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)