#!/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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.