Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl -w ############################ ## Name: SabreHex ## ## Author: Thomas Stanley ## ############################ use strict; use Crypt::CipherSaber; use Term::ReadKey; use Getopt::Std; use vars qw/$opt_d $opt_e $opt_h $opt_o $opt_v/; my $infile; my $outfile; system('clear'); ########################## getopts('vhd:e:o:'); if($opt_h and $opt_d and $opt_o){ $infile = $opt_d; $outfile = $opt_o; &DECRYPT($infile,$outfile); }elsif($opt_h and $opt_e and $opt_o){ $infile = $opt_e; $outfile = $opt_o; &ENCRYPT($infile,$outfile); }elsif($opt_d and $opt_o){ $infile = $opt_d; $outfile = $opt_o; &DECRYPTNOHEX($infile,$outfile); }elsif($opt_e and $opt_o){ $infile = $opt_e; $outfile = $opt_o; &ENCRYPTNOHEX($infile,$outfile); }elsif($opt_v){ die"SabreHex Version 1.06 by Thomas Stanley\n"; }else{ die"\n\tUsage: SabreHex [hdeov] [filename]\n\t\t -h: Hex Mode\n\t\t -d: Decrypt [filename]\n\t\t -e: Encrypt [filename]\n\t\t -o: Outputfile [filename]\n\t\t -v: Version\n"; } ########################### sub DECRYPT(){ my $inputfile = shift; my $outputfile = shift; print"\n"; print"Please enter the key phrase to decode the file (Input will be +hidden): "; ReadMode 2; my $key = <STDIN>; ReadMode 0; chomp($key); print"\n"; my $SABRE = new Crypt::CipherSaber($key); open (FH1,"$inputfile")||die "Can't open $inputfile : $!\n"; my $encoded = <FH1>; $encoded = Dehexed($encoded); my $decoded = $SABRE->decrypt($encoded); open (FH2,">$outputfile")||die "Can't open $outputfile : $!\n"; print FH2 $decoded; close FH1; close FH2; unlink $inputfile; } sub ENCRYPT(){ my $inputfile = shift; my $outputfile = shift; print"\n"; print"Enter the key phrase to encrypt the file (Input will be hidden +): "; ReadMode 2; my $key = <STDIN>; ReadMode 0; chomp($key); print"\n"; my $SABRE = new Crypt::CipherSaber($key); open(FH1,"$inputfile")||die "Can't open $inputfile: $!\n"; my @text = <FH1>; my $text; my $l=@text; for(my $x=0;$x<$l;$x++){ $text.=$text[$x]; } my $encrypted = $SABRE->encrypt($text); $encrypted = Hexed($encrypted); open(FH2,">$outputfile")||die "Can't open $outputfile: $!\n"; print FH2 $encrypted; close FH1; close FH2; unlink $inputfile; } sub Hexed(){ my $encrypted = shift; my @conversion = split //,$encrypted; my $elements = @conversion; my $num; my $hexed; for(my $x=0;$x<$elements;$x++){ $num = ord $conversion[$x]; $conversion[$x] = sprintf("%02x",$num); } for(my $y=0;$y<$elements;$y++){ $hexed .= $conversion[$y]; } return $hexed; } sub Dehexed(){ my $encrypted = shift; my $l = length $encrypted; my @conversion=(); my $dehexed; my $c = $l/2; my $x = 0; for(my $y=0;$y<$c;$y++){ $conversion[$y] = substr($encrypted,$x,2); $x+=2; } my $len = @conversion; for(my $z=0;$z<$len;$z++){ $dehexed .= chr hex $conversion[$z]; } return $dehexed; } sub DECRYPTNOHEX(){ my $inputfile = shift; my $outputfile = shift; print"\n"; print"Please enter the key phrase to decode the file (Input will be +hidden): "; ReadMode 2; my $key = <STDIN>; ReadMode 0; chomp($key); print"\n"; my $SABRE = new Crypt::CipherSaber($key); open (FH1,"$inputfile")||die "Can't open $inputfile : $!\n"; my $encoded = <FH1>; my $decoded = $SABRE->decrypt($encoded); open (FH2,">$outputfile")||die "Can't open $outputfile : $!\n"; print FH2 $decoded; close FH1; close FH2; unlink $inputfile; } sub ENCRYPTNOHEX(){ my $inputfile = shift; my $outputfile = shift; print"\n"; print"Enter the key phrase to encrypt the file (Input will be hidden +): "; ReadMode 2; my $key = <STDIN>; ReadMode 0; chomp($key); print"\n"; my $SABRE = new Crypt::CipherSaber($key); open(FH1,"$inputfile")||die "Can't open $inputfile: $!\n"; my @text = <FH1>; my $l=@text; my $text; for(my $x=0;$x<$l;$x++){ $text.=$text[$x]; } my $encrypted = $SABRE->encrypt($text); open(FH2,">$outputfile")||die "Can't open $outputfile: $!\n"; print FH2 $encrypted; close FH1; close FH2; unlink $inputfile; }

In reply to SabreHex by TStanley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found