FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Perl how to encrypt your text file contents with Perl





pirate
So basically iv been looking at perl security and although this is not the best way to secure your files it is one method, so here you go do with as you wish:

Whole code writen by me:
Quote:

Code:

#!C:/Perl/bin/perl.exe -w

use Digest::SHA1;
use Digest::MD5;
    print q{
    :: The text file must be located in the same directory.
    };

    print "\n\nText - Encryption - Text\n\n::>> ";

    chomp ($word = <STDIN>);
    open (FILE, ">$word")|| die"Could not locate file...";;

    print q{
    Encryption Method?

    1) MD5
    2) SHA1
    };
    print "\n\n::>> ";
    chomp ($type = <STDIN>);
    if ($type eq 1){&md5}
    elsif ($type eq 2){&sha1}

    sub md5{
    $md5 = Digest::MD5->new;
    $md5->add(<FILE>);
    $digest = $md5->hexdigest;

    print FILE "::Crypted:: - $digest";
    close (FILE);
    }

    sub sha1{
    $sha1 = Digest::SHA1->new;
    $sha1->add(<FILE>);
    $shahash = $sha1->hexdigest;
    print FILE "::Crypted:: - $shahash";
    close (FILE);
    }


Peterssidan
I'm not very good at Perl but to me it looks like you are using a hash function (MD5 or SHA-1) to create a hash value of the file content. In that case I wouldn't call it an encryption. If it is encrypted you should be able to decrypt to it's original form.

hmm, for some reason I get the same hash for all files
d41d8cd98f00b204e9800998ecf8427e for MD5
da39a3ee5e6b4b0d3255bfef95601890afd80709 for SHA-1
are you sure your code is working at all and what is the purpose?
cybersa
As mentioned above MD5 and SHA1 is a hash.
Mostly hash is used as Password.
For example:
Sign In:
If user typed Password as "test" in the login box,it would converted into MD5 hash(098f6bcd4621d373cade4e832627b4f6)
Then server will compare it with other hash in the database.
If it is matched,it moves to next.

I have done one program like this:http://www.cybapps.com/cybcrypt.html
It use MD5 Hash and XOR Encryption.
Related topics
users online, using php and text file
"Forms To Go" create scripts in PHP, ASP and Perl
Visual Basic Tutorial - File I/O in VB: Text Files
styling text string read from plain text file
Reading from text file into Flash
Deleting certain lines from text file
HELP, reading text file from USB drive in visual basic
is it possible to get a html text box to load a .txt file?
download a text-file daily
how to add a text file in mp3 data using java ?
Use a .hta file as GUI for script or IEobj
English Dictionary in text file or sql database
edit option not available for a text file
want to delete first 5 lines in a text file
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.