Qbasicnews.com
April 12, 2021, 08:05:00 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 2 [3] 4
  Print  
Author Topic: Here's another....file I/O difficulties.  (Read 16927 times)
Moneo
Na_th_an
*****
Posts: 1971


« Reply #30 on: January 11, 2006, 05:38:38 PM »

Stylin:

The new code now works fine, matching the Winer encrypted text. Nice job, and nice explanation.

The business of chr$(0) terminating a string in FB, is a sticky wicket. Others who have not considered this, like you have, could have problems with strings whose bytes can be modified by bitwise operations. The worst part is that they may work most of the time and then suddenly...
*****
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #31 on: January 11, 2006, 06:21:02 PM »

Thanks for the explanation.
I remember a bit of that from C. If you ask me, FB ought to have a way to declared fixed-length strings, regardless of CHR$(0) terminators. ZSTRING*n can almost do this, but still uses CHR$(0).
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
stylin
Ancient QBer
****
Posts: 445


« Reply #32 on: January 11, 2006, 06:37:48 PM »

Quote from: "Zack"
Thanks for the explanation.
I remember a bit of that from C. If you ask me, FB ought to have a way to declared fixed-length strings, regardless of CHR$(0) terminators. ZSTRING*n can almost do this, but still uses CHR$(0).

You can declare fixed-length strings, but I think the issue here might be a bug: notice that passing a string by value (making a copy of it) acts differently than initializing a new string with a reference value (making a copy of it). I'm going to ask @ fb.net and see what the deal is.
Logged

stylin:
stylin
Ancient QBer
****
Posts: 445


« Reply #33 on: January 11, 2006, 08:19:30 PM »

Sorry for the double-post.

For those interested: How strings get passed by value

So, it seems that null-spersed-strings passed by value get truncated "by design", since a pointer is passed instead of the descriptor - which means we no longer have explicit length information; length must be determined incrementally - thus the truncation.

Moral of the story: for strings that may possibly contain a null character, pass by reference (if you can't safely ignore truncation). For non-modifiable strings that are guaranteed not to have a null character, pass by value, otherwise pass by reference. (if you're passing a string by reference and you don't want it modified [text, key, for example], prefer to create a local copy [result] and only use that copy throughout the function.

update: the above behavior will be changing in an indefinent amount of time Wink. strings passed by value will be deep-copied instead of having an address passed instead. happy happy, joy joy
Logged

stylin:
stylin
Ancient QBer
****
Posts: 445


« Reply #34 on: January 14, 2006, 03:38:00 PM »

Zack, you've gotten me hooked on neat little encryption methods. Here's one I just finished. It's sort of like a combination of your original algorithm, with Winer's. Here's the procedure:
Code:

'' original
'' ^^^
'' key^
''  key^
''   key^
''    key^
''     key^
''      key
''       ke
''        k

Basically, it works like Winer's by overlaying the key across the original, but mine overlaps the key, essentialy producing the same effect as the method you originally posted, but with the first len(key)-1 characters being encrypted differently. I'm not an expert, but I suppose that for this type of encryption you mght as well employ your algorithm, but I think the function looks neat nonetheless. Smiley Here is the code:

Code:
option explicit
option byval

function StylinizeText( byref text as string, byref key as string ) as string
    if( strptr(text)=0 ) then return ""
    if( strptr(key)=0 ) then return text

    dim as string result => text
    dim as integer resIndex = 0, resLength = len(result), keyLength = len(key)
    while( resIndex < resLength )
        dim as integer keyIndex = 0
        while( (keyIndex < keyLength) and ((resIndex + keyIndex) < resLength) )
            result[resIndex + keyIndex] xor= key[keyIndex]
            keyIndex += 1
         wend
        resIndex += 1
     wend : return result
 end function

function deStylinizeText( byref text as string, byref key as string ) as string
    return StylinizeText( text, key )
 end function
Logged

stylin:
Moneo
Na_th_an
*****
Posts: 1971


« Reply #35 on: January 14, 2006, 04:54:43 PM »

Albert Einstein said:
"We need to make things simple, but not simpler".
*****
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #36 on: January 15, 2006, 01:17:45 PM »

Wicked. Shocked
I wonder how easy it is to crack XOR encryption. I used to send my encrypted files to a buddy of mine and he'd always be able to crack them.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
« Reply #37 on: January 15, 2006, 03:47:08 PM »

If you use a key that is as long as the message I think it would be impossible.
Logged

/post]
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #38 on: January 15, 2006, 06:06:19 PM »

Interesting...imagine encrypting a file with another file of equal length. Or a string.
I suppose the only risk would be someone getting their hands on the password string.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #39 on: January 15, 2006, 07:08:30 PM »

That'd essentially be a one-time pad - unbreakable encryption.  However, both parties would need to get the password, which is a problem sometimes.
Logged
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
« Reply #40 on: January 15, 2006, 07:52:21 PM »

It could be a quote from a book that both parties have, and then only
have a reference as "page 57" etc. But it might be good to combine
more than one letter to make the key char so you get the whole 0 to 255
range of key character possibillities.

Also: you would perhaps want to jumble up the text in some way, so
it appears to be random chars, and not words.

Aw heck, it seems easier to just give the reciever a floppy with a normal
key on :-?  :wink:
Logged

/post]
stylin
Ancient QBer
****
Posts: 445


« Reply #41 on: January 15, 2006, 10:25:12 PM »

What's a floppy?
Logged

stylin:
Moneo
Na_th_an
*****
Posts: 1971


« Reply #42 on: January 15, 2006, 11:33:15 PM »

Quote from: "Zack"
.....
I wonder how easy it is to crack XOR encryption. I used to send my encrypted files to a buddy of mine and he'd always be able to crack them.

Why don't you send your friend a copy of a file encrypted by the enhanced Winer algorithm? Let's see if he can crack it. My guess is that you could probably give him the encryption password, and lacking the algorithm, he still wouldn't derive the unencrypted text.

I just remembered an old encryption trick that I used back in the 1970's. I had one or more dummy characters within the password, for the remote possibility that someone got a hold of the password. The algorithm knew which character(s) were dummy and just ignored them, both for encryption and decryption obviously. Easy to implement and could cause a hacker lots of headaches. I used this for a banking communications application and never had a problem.
*****
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #43 on: January 16, 2006, 07:47:30 AM »

Quote from: "stylin"
What's a floppy?


This strange thing. I never seen one. It must be some kind of alien technollogy, or made by the commies to take over the world, or something.

I think it's explosive.

Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
stylin
Ancient QBer
****
Posts: 445


« Reply #44 on: January 16, 2006, 08:40:48 AM »

Definitely looks like a communist device to me. You mean it matters what direction I insert this "floppy"?
Logged

stylin:
Pages: 1 2 [3] 4
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!