|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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); |
|
#2
|
||||
|
||||
|
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... |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
I looked through all the special characters in Programming Perl and can't find the one your talking about. Can someone help me please??
|
|
#6
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Problems reading encrypted file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|