All pastes #747225 Raw Edit

rotten

public text v1 · immutable
·published 2007-10-23 20:54 UTC
rendered paste body
#!/usr/bin/perl -tw
# rotten.pl - take a text scream via sdtin ("file |rotation.pl <#>" or "rotation.pl <#> < file") 
# and output each character shifted (or 'rotated') a given <n> number of positions up or down the character group, 
# which is stored in an array.  The array of characters startes from the Decimal value 32 (" ") and goes to "~" by 
# default.  This set will work for any english language text, but will need to be expanded or altered for other 
# languages. the name rotten comes from the type of cipher, ROT(N)
# 
# If this looks familiar, its because ROT13 and ROT47 is what it's based on. This script merely allows for non 
# alpha-numeric characters to be endcoded (limited to the current character set in the array below), and allows 
# for a shift value of other than 13 or 47 to be used (why? good question, guess variation is the spice of life, 
# and having the oportunity to tweak the character set and shift value further obfuscates text, although sharing the 
# resulting text requires collaboration ahead of time).
# 
# To decode text repeat the process with either the negative value of <#> or <#>'s compliment (character set length 
# - <#>).
#
# Use this script in full or in part however with or without attribution to its creator (search google for 
# "ROT13 ROT47" and you quickly see that this notion is not new, therefore this version of the same thing 
# deserves no special distinction; specifically, see http://en.wikipedia.org/wiki/ROT13 as to why you really
# don't want to use this Caeser cipher for important data...).
# 

my $DEBUG=0;
my $rotate = shift;
$rotate = 13 unless $rotate =~ /^\d+?$/;
my $text = "";
while (<>) {
    $text .= $_;
}
my @txtAry = split ("",$text);

# ASCI char short list array - ASCII character array used for A-Za-z case insensative
#my @alphabet = ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');

# ASCI char long list array - ASCII character set beginning at Dec 32m Hex 20
#my @alphabet = (" ","!","\"","\#","\$","\%","\&","\'","\(","\)","\*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~");

my @alphabet = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

my $alpha_len = @alphabet;
# $rotate = $aplha_len - $rotate if $rotate < 0 && ! $rotate >= $aphla_len;
my $offset = 0;
print "Rotate: $rotate\nText: $text\nText Array:" . @txtAry ."\n" if $DEBUG==1;
foreach ( @txtAry ) {
    my $found = 0;
    for ( my $i=0; $i<$alpha_len && $found != 1; $i++ ) {
        # if ( lc($_) eq $alphabet[$i] ) { # Used for  ASCII char short list array
        if ( $_ eq $alphabet[$i] ) { # Used for ASCII char long list array
            print "DEBUG: found $_ at $i...\n" if $DEBUG==1;
            $offset = ($i + $rotate ) % $alpha_len;
            $_ = $alphabet[$offset];
            $found = 1;
            print "DEBUG: Finished  $_ ($offset])\n" if $DEBUG==1;
        }
        else {
            print "DEBUG: $_ does not equal ($alphabet[$i])\n" if $DEBUG==1;
        }
    }
}
my $newtext = join("", @txtAry);
print "$text\n" if $DEBUG==1;
print "$newtext\n";