caesar()  in linux ?

Posted on 2004-11-04
Last Modified: 2010-05-18
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?


Question by:rockmansattic
    LVL 38

    Expert Comment

    LVL 5

    Expert Comment

    Here's a good man page for doing source filters in perl on linux, with example code for the caesar cypher rot13:

    LVL 10

    Author Comment

    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

    echo "filename"; filename = read()

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

    blah blah blah

    LVL 38

    Expert Comment


    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;

    LVL 10

    Author Comment

    that looks like what I need, but how do you use it?

    uped pts
    LVL 5

    Accepted Solution

    That snippet is calling the VMethods plugin module for Template Toolkit, a template processing system intended mainly for web content:

    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:

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

    These scripts will both decrypt:

    Do you need to encrypt too?
    Here's a good simple Perl script to encrypt and decrypt Caesar:
    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:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now