Encryption
[1/16] from: mattsmac:hotmai:l at: 8-Sep-2003 9:13
Hi all,
I'm trying to implement a secure message transferring system using
blowfish ecryption in rebol/command using view/pro. Non-encrypted messages
transfer perfectly, and very short (like < 10 character) messages that are
encrypted work as well. Anytime I use a slightly longer message, expecially
if it includes puctuation, the transfer gets all screwed up. I'm using a
standard tcp port with the direct, lines, and no-wait refinements. The
no-wait is for another portion of the program, not the encryption. Here is
my encryption/decryption algorithm.
encrypt: func [data]
[
crypt-key: #{5C2486ADFD7F36765A7A163E86C6FB9A}
crypt-port: make port! [
scheme: 'crypt
algorithm: 'blowfish
direction: 'encrypt
strength: 128
key: crypt-key
padding: true
]
open crypt-port
insert crypt-port data
update crypt-port
crypt-data: copy crypt-port
close crypt-port
return crypt-data
]
decrypt: func [data]
[
crypt-key: #{5C2486ADFD7F36765A7A163E86C6FB9A}
decrypt-port: make port! [
scheme: 'crypt
algorithm: 'blowfish
direction: 'decrypt
strength: 128
key: crypt-key
padding: true
]
open decrypt-port
insert decrypt-port data
update decrypt-port
result: copy decrypt-port
close decrypt-port
return to-string result
]
_________________________________________________________________
Fast, faster, fastest: Upgrade to Cable or DSL today!
[2/16] from: g:santilli:tiscalinet:it at: 8-Sep-2003 15:41
Hi Matt,
On Monday, September 8, 2003, 3:13:04 PM, you wrote:
MM> if it includes puctuation, the transfer gets all screwed up. I'm using a
MM> standard tcp port with the direct, lines, and no-wait refinements. The
Without /BINARY? You need /BINARY if you are transferring binary
data, such as encrypted text.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[3/16] from: rotenca:telvia:it at: 8-Sep-2003 16:02
> Hi all,
> I'm trying to implement a secure message transferring system using
<<quoted lines omitted: 3>>
> if it includes puctuation, the transfer gets all screwed up. I'm using a
> standard tcp port with the direct, lines, and no-wait refinements.
Try open/binary.
---
Ciao
Romano
[4/16] from: mattsmac:h:otmail at: 8-Sep-2003 10:11
Can I transfer binary and non-binary data if I use the /BINARY?
Hi Matt,
On Monday, September 8, 2003, 3:13:04 PM, you wrote:
MM> if it includes puctuation, the transfer gets all screwed up. I'm using
a
MM> standard tcp port with the direct, lines, and no-wait refinements. The
Without /BINARY? You need /BINARY if you are transferring binary
data, such as encrypted text.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
_________________________________________________________________
Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.
[5/16] from: g:santilli:tiscalinet:it at: 8-Sep-2003 16:34
Hi Matt,
On Monday, September 8, 2003, 4:11:53 PM, you wrote:
MM> Can I transfer binary and non-binary data if I use the /BINARY?
Of course. The only difference with using /BINARY versus /STRING
is that string does automatic conversion between line terminators.
I don't think you'll need it in your case. If you really do, you
could use:
set-modes port [binary: true]
before sending encrypted data and:
set-modes port [binary: false]
before sending plain text. You'll need to do the same on
receiving.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[6/16] from: mattsmac::hotmail::com at: 8-Sep-2003 10:35
I think I fixed the problem.
Using the /binary refinement wasn't giving me any results. But by making
the result of the encryption function to-string, I was able to pass it over
the port and decrypt it once it got over.
Thanks everybody
Matt
_________________________________________________________________
Compare Cable, DSL or Satellite plans: As low as $29.95.
[7/16] from: mattsmac:hotma:il at: 8-Sep-2003 10:54
... or maybe not.
_________________________________________________________________
Compare Cable, DSL or Satellite plans: As low as $29.95.
[8/16] from: mattsmac:ho:tmail at: 8-Sep-2003 10:58
Ok, maybe my inexperience is showing or I'm just dense. I need to use the
line refinement so that I can get the entire line of the message at once.
But you cannot use the binary and line refinements at the same time. How do
I get around this?
Matt
Hi Matt,
On Monday, September 8, 2003, 4:11:53 PM, you wrote:
MM> Can I transfer binary and non-binary data if I use the /BINARY?
Of course. The only difference with using /BINARY versus /STRING
is that string does automatic conversion between line terminators.
I don't think you'll need it in your case. If you really do, you
could use:
set-modes port [binary: true]
before sending encrypted data and:
set-modes port [binary: false]
before sending plain text. You'll need to do the same on
receiving.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
_________________________________________________________________
Express yourself with MSN Messenger 6.0 -- download now!
http://www.msnmessenger-download.com/tracking/reach_general
[9/16] from: greggirwin:mindspring at: 8-Sep-2003 9:48
Hi Matt,
MM> Ok, maybe my inexperience is showing or I'm just dense. I need to use the
MM> line refinement so that I can get the entire line of the message at once.
MM> But you cannot use the binary and line refinements at the same time. How do
MM> I get around this?
If you're sending binary data, there is no concept of "lines". You'll
have to send the data and decode it on the other end, breaking it up
in to lines there if necessary.
-- Gregg
[10/16] from: joel:neely:fedex at: 8-Sep-2003 10:56
Hi, Matt,
IMHO the combination of LINE and BINARY simply isn't meaningful.
BINARY means "don't interpret the byte stream, just give it
to me as a collection of 8-bit bytes." In contrast, LINE mode
asks for a specific set of interpretation rules (and changes!)
to be applied to the data.
Different environments use different conventions to delimit
lines (e.g. newline on *nix, carriage-return on old MacOS,
carriage-return-line-feed on CPM) which requires interpreting
the bytes to break the file into lines.
In LINE mode, REBOL actually looks for any of the above and
breaks the input at that point. In non-LINE, non-BINARY mode,
REBOL translates any of the above to NEWLINE internally.
Write the following data to a file (e.g. %data.raw)
#{
74686973206973206120746573740D0A746865206669727374206C696E652077
61732043524C462C2074686973206F6E65206973204E4C0A616E642074686973
206F6E65206973204352206F6E6C790D746F2073686F77207468652062656861
76696F72206F6620524541442E
}
and then read it with no refinements, LINE, and BINARY and see
how the results differ.
As for how to address your specific issue, I'd suggest that you
write your own line-parsing if you *really* thing that the idea
of LINE is relevant. Then you'll have to decide what to do if
#"^/" or #"M" happen to show up in the binary data! ;-)
-jn-
Matt MacDonald wrote:
> Ok, maybe my inexperience is showing or I'm just dense. I need
> to use the line refinement so that I can get the entire line of
> the message at once. But you cannot use the binary and line
> refinements at the same time. How do I get around this?
>
--
----------------------------------------------------------------------
Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446
Counting lines of code is to software development as
counting bricks is to urban development.
[11/16] from: mattsmac:ho:tmail at: 8-Sep-2003 12:03
Ok, good enough. So if I'm understanding correctly. I should be able to
have 2 binary ports. One sending and one receiving. Then send the data
through the sending port (as binary) and recieve it on the recieving port.
Then change it to string and parse it from there. Here is what is happening
though:
I send a simple message "Hi"
i have to do 2 reads on the recieving port, which returns 72 and 105 - both
integers. So my question is then, why do I get integers instead of binary
data, and if I need to deal with integers and somehow convert them to
characters, how do I know when to stop reading from the recieving port?
Please help this is reallllly frustrating,
Matt
Hi Matt,
MM> Ok, maybe my inexperience is showing or I'm just dense. I need to use
the
MM> line refinement so that I can get the entire line of the message at
once.
MM> But you cannot use the binary and line refinements at the same time.
How do
MM> I get around this?
If you're sending binary data, there is no concept of "lines". You'll
have to send the data and decode it on the other end, breaking it up
in to lines there if necessary.
-- Gregg
[12/16] from: tomc:darkwing:uoregon at: 8-Sep-2003 10:17
On Mon, 8 Sep 2003, Matt MacDonald wrote:
> Ok, good enough. So if I'm understanding correctly. I should be able to
> have 2 binary ports. One sending and one receiving. Then send the data
<<quoted lines omitted: 6>>
> data, and if I need to deal with integers and somehow convert them to
> characters, how do I know when to stop reading from the recieving port?
the 72 & 105 are the ASCCI values for the chars H & i
>> to-char 72
== #"H"
>> to-char 105
== #"i"
[13/16] from: greggirwin:mindspring at: 8-Sep-2003 11:43
Hi Matt,
MM> I send a simple message "Hi"
MM> i have to do 2 reads on the recieving port, which returns 72 and 105 - both
MM> integers. So my question is then, why do I get integers instead of binary
MM> data, and if I need to deal with integers and somehow convert them to
MM> characters, how do I know when to stop reading from the recieving port?
If you could post the code, that would help a lot. There's no way to
know how you're doing it otherwise. :) You should just be able to do a
COPY on the port (returns NONE when all data has been read). If you're
in no-wait mode, you just keep appending data to a buffer until you
get an empty string back, which indicates no more data is available.
-- Gregg
[14/16] from: antonr:iinet:au at: 9-Sep-2003 13:32
You can push your binary through a line port
as text.
Encrypt your text, which gives you a binary,
then use enbase, which gives a string (and
losing no information).
On the other end use debase to get the binary
back, then decrypt.
Anton.
[15/16] from: mattsmac:ho:tmail at: 9-Sep-2003 8:36
Greg,
This is the best and easiest solution anyone has given me. It's versatile
enough to support all of the various applications in my program. It seems
to be working perfectly. Thanks everyone for your help.
Matt
Re: Encryption
Anton Rolls (antonr)
9-Sep-2003/13:32:51+10:00
#30965
--------------------------------------------------------------------------------
You can push your binary through a line port
as text.
Encrypt your text, which gives you a binary,
then use enbase, which gives a string (and
losing no information).
On the other end use debase to get the binary
back, then decrypt.
Anton.
>Ok, good enough. So if I'm understanding correctly. I should be able to
>have 2 binary ports. One sending and one receiving. Then send the data
<<quoted lines omitted: 25>>
>in to lines there if necessary.
>-- Gregg
_________________________________________________________________
Use custom emotions -- try MSN Messenger 6.0!
http://www.msnmessenger-download.com/tracking/reach_emoticon
[16/16] from: mattsmac:hotma:il at: 9-Sep-2003 10:53
Whoops, I ment Anton
>From: "Matt MacDonald" <[mattsmac--hotmail--com]>
>Reply-To: [rebol-list--rebol--com]
<<quoted lines omitted: 62>>
>To unsubscribe from this list, just send an email to
>[rebol-request--rebol--com] with unsubscribe as the subject.
_________________________________________________________________
Need more e-mail storage? Get 10MB with Hotmail Extra Storage.
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted