Forum: Ruby Unicode Character 'SUBSTITUTE' (U+001A) troubles...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Robert L. (Guest)
on 2009-03-17 18:09
(Received via mailing list)
I'm implementing a version of the "Mini-AES" (http://findarticles.com/
p/articles/mi_qa3926/is_200210/ai_n9129484) in Ruby and have all of
the bit shifts and stuff working..

The problem I'm having is with the file input.  When ever the input
file has the character U+001A (http://www.fileformat.info/info/unicode/
char/001a/index.htm), it stops reading in the line (and thus doesn't
complete the whole cipher text).

Basically, here is the code that I'm using to read the input:
fin = File.open(ARGV[0], 'r')
plainText = ""
while (line = fin.gets)
  plainText += line
end
fin.close

Here is a sample line of cipher text:
týH†a¤j{ÀìyMšyMÇÜ«àÃSÙ¿àé4þF&käj{Àì

if I read this line in, it would only read "týH†a¤j{ÀìyMšyM" and skip
the rest.
Robert L. (Guest)
on 2009-03-17 18:30
(Received via mailing list)
On Mar 17, 12:01 pm, Robert L. <removed_email_address@domain.invalid> wrote:
> fin = File.open(ARGV[0], 'r')
> the rest.
I'm using Windows btw.
Tim H. (Guest)
on 2009-03-17 19:36
Robert L. wrote:
> On Mar 17, 12:01�pm, Robert L. <removed_email_address@domain.invalid> wrote:
>> fin = File.open(ARGV[0], 'r')
>> the rest.
> I'm using Windows btw.

Open the file with "rb" instead of "r".
Robert L. (Guest)
on 2009-03-17 23:22
(Received via mailing list)
On Mar 17, 1:33 pm, Tim H. <removed_email_address@domain.invalid> wrote:
> Robert L. wrote:
> > On Mar 17, 12:01 pm, Robert L. <removed_email_address@domain.invalid> wrote:
> >> fin = File.open(ARGV[0], 'r')
> >> the rest.
> > I'm using Windows btw.
>
> Open the file with "rb" instead of "r".
> --
> Posted viahttp://www.ruby-forum.com/.

I tried using rb and the output spits out 1/2 plain text and 1/2
random Unicode.

Our project is only allowed to be run on Linux and it seems to work
fine on there, so I'll just leave the Windows problem alone unless
someone suggests a good fix.
This topic is locked and can not be replied to.