Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 13th, 2001, 01:31 PM
KilerCris KilerCris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58 KilerCris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to KilerCris Send a message via AIM to KilerCris Send a message via Yahoo to KilerCris
Unhappy

I am using Crypt::RC4 to encrypt files. It is opened, encrypted, and saved properly, but when I try to open it again from perl it stops reading the file in the middle of a line. I can open the file just fine in any editor.
http://kilercris.cjb.net/proj/debug


How can I get the complete contents of the encrypted file into a string

source for test.cgi is:
---------------------------------------
#!/usr/bin/perl
use RC4;
$key = "c0c0c0";
print "Content-type: text/html\n\n";

open(TESTFILE,"testfile.txt");
$fcont = join('',<TESTFILE>);
close(TESTFILE);

$fcont = RC4($key,$fcont);

open (OUTFILE,">encrypted.txt");
print OUTFILE $fcont;
close(OUTFILE);

open (CHK,"encrypted.txt");
$fcont = join('',<CHK>);
print $fcont;
close(CHK);

Reply With Quote
  #2  
Old April 13th, 2001, 04:25 PM
vpopper's Avatar
vpopper vpopper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: Southern California
Posts: 73 vpopper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 24 sec
Reputation Power: 9
I know this is probably just a test script, but why do you read the contents in a second time when you already have the contents is $fcont?

Another potential problem is the snippet

$fcont = join('',<TESTFILE>;

Note there is no closing paren ')'. I would use this instead:

{ local($/) = undef; $fcont = <TESTFILE>; }

It might help if you could post the good section of the file vs. what was read...

Reply With Quote
  #3  
Old April 13th, 2001, 05:47 PM
KilerCris KilerCris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58 KilerCris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to KilerCris Send a message via AIM to KilerCris Send a message via Yahoo to KilerCris
There are closing parenthesis..smilies at them up..I'll turn them off..this is just a debug script

I've read the file in many ways...while loop...reading into array....I've tried reading teh file with read()..but no matter what perl always stops reading the file in teh middle of a line..possibly an EOF symbol..I tried taking out all \012 and \015 but that didn't help

Reply With Quote
  #4  
Old April 14th, 2001, 02:05 AM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
unfortunarly i don't have a book infront of me and i'm on a slow connection so i can't easily search for the info, but there is a special perl variable $+ or something that lets you set the default end of line value.

The encrypt is possibly inadvertantly setting a character to the default perl value.

What you can do when you find the character (and where-ever you find out which one it is, there will probably also be a better explanation of how to do this than i provide here) is something like

Code:
sub readSpecialFile {
my $location = shift;
my @fileLines;
 local $+ = ''; <-- $+ is not the right special var, just an example
 open(FILE, $location);
  while (<FILE>){
   push @fileLines, $_;
  }
 close(FILE);
 return @fileLines;
}

Setting the special var to null must be done using local and inside it's own sub-routine.

Hope that helps some what.

Reply With Quote
  #5  
Old April 14th, 2001, 02:00 PM
KilerCris KilerCris is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58 KilerCris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to KilerCris Send a message via AIM to KilerCris Send a message via Yahoo to KilerCris
I looked through all the special characters in Programming Perl and can't find the one your talking about. Can someone help me please??

Reply With Quote
  #6  
Old April 16th, 2001, 10:39 AM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
Now that i'm back at work, the special variable is: $/

Setting it to empty will allow you to read the entire file contents into one variable. From there you can probably split the variable at new lines to break it into an array.

Good Luck.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Problems reading encrypted file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT