[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

caesar() in linux ?

I am trying to rebuild some of my old perl programs into linux.
I have read about caesar and rot13, but I have no man pages on them.

Is there a library or something I must do?
 

Thanks

Rockman
0
rockmansattic
Asked:
rockmansattic
  • 2
  • 2
  • 2
1 Solution
 
wesly_chenCommented:
0
 
jdfoxCommented:
Here's a good man page for doing source filters in perl on linux, with example code for the caesar cypher rot13:

http://www.die.net/doc/linux/man/man1/perlfilter.1.html

0
 
rockmansatticAuthor Commented:
Sorry, after reading my question, I didnot explain properly.

I am actually looking for a function caesar() or ROT() or linux/unix/fedora...
I have several perl scritps that I want to redo, not just run in unix enviroment.

I need a simple example of a working ROT or Caesar txt file , something like this



#!/bin/ah
echo "filename"; filename = read()

% tr "[a-z][A-Z]" "[n-z][a-m][N-Z][A-M]" < filename


blah blah blah

Thanks
Rockman
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
wesly_chenCommented:
Hi

Is this what are your looking for?
------
package CaesarVMethod;
  use base qw(Template::Plugin::VMethods);
  @SCALAR_OPS = ( "caesar",
                  "rot13"   => sub { caesar($_[0],"13") } );
  sub caesar
  {
    $string = shift;
    $string =~ tr/A-Za-z/B-ZAb-za/ for 1..$_[0];
    return $string;
  }
------

Wesly
0
 
rockmansatticAuthor Commented:
that looks like what I need, but how do you use it?

uped pts
Thanks
0
 
jdfoxCommented:
That snippet is calling the VMethods plugin module for Template Toolkit, a template processing system intended mainly for web content:
http://www.template-toolkit.org/

That's why "use base" is calling it from the Template package on the second line.

Here's the CPAN page for VMethods on CPAN for more info:
http://search.cpan.org/~markf/Template-Plugin-VMethods-0.03/lib/Template/Plugin/VMethods.pm

So if you're not using Template Toolkit, that will probably be of limited use for you.

These scripts will both decrypt:
http://www.sentex.net/~ajy/perl/caesar
http://search.cpan.org/~juerd/Crypt-Caesar-0.01/Caesar.pm

Do you need to encrypt too?
Here's a good simple Perl script to encrypt and decrypt Caesar:
alphabet_lower=abcdefghijklmnopqrstuvwxyz
alphabet_upper=`echo $alphabet_lower | tr "[a-z]" "[A-Z]"`
function rotx() {
  local offset=`expr $1 % 26 + 1`
  test $offset -lt 1 && offset=`expr 26 + $offset`
  rot_lower1=`echo $alphabet_lower | cut -c$offset-26`
  rot_lower2=`echo $alphabet_lower | cut -c-\`expr $offset - 1\``
  rot_upper1=`echo $alphabet_upper | cut -c$offset-26`
  rot_upper2=`echo $alphabet_upper | cut -c-\`expr $offset - 1\``
  echo "${rot_lower1}${rot_lower2}${rot_upper1}${rot_upper2}"
}
function caesar() {
  local offset=$1; shift
  echo $* | tr ${alphabet_lower}${alphabet_upper} `rotx $offset`
}

You can encrypt a message with this using the following syntax:
caesar <s> your message here ...

example: caesar 35 only you can read this...
xwuh hxd ljw anjm cqrb...

Or you can decrypt it with a -s.
example:  caesar -35 xwuh hxd ljw anjm cqrb...
only you can read this...

More info here:
http://www.maenad.net/geek/gpg/encryption_explanation.txt
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now