Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Here's another....file I/O difficulties.
#24
Nice work! That looks alot better. While we're on the subject of functions, though, this may be a good time to show their usefulness. Additionally, you can use the string-indexing operator ( [] ) to crisp up that code even more:
Code:
option explicit
option byval

function CipherText( text as string, key as string ) as string
    dim as integer textIndex = 0, keyIndex = 0
    dim as string result = string( len( text ), 0 )

    while( textIndex < len(text) )
        if( keyIndex > len(key) ) then keyIndex = 0
        result[textIndex] = text[textIndex] xor key[keyIndex]
        textIndex += 1 : keyIndex += 1
    wend
    return result
end function

const originalText as string = "Move 32nd platoon SSW 10 miles"
const password as string = "armypassword"

dim as string cipheredText : cipheredText = CipherText( originalText,password )
print "  original Text: " ; originalText
print "       Password: " ; Password
print "  Ciphered text: " ; cipheredText

dim as string decipheredText : decipheredText = CipherText( cipheredText,password )
print "Deciphered text: " ; decipheredText

sleep : end 0
Here, we solely work with the byte values of the strings, which is what operator[] gives us. As you may be able to guess, this is much more efficient than converting back and forth from strings to integers again and again.
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-10-2006, 10:12 PM
Here's another....file I/O difficulties. - by DrV - 01-16-2006, 03:08 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)