Page tree

Content


Blog

Blog Posts

Table of Contents

Cryptoclans

Cryptoclans rock.

This Perl script takes as input a pipe-delimited file where:

  • each line is a puzzle
  • the first field is the topic
  • each additional field is an item

Try it with family member names, favorite meals, old pets, whatever. 

Note that a character might be the same in plaintext and ciphertext. I may change that later.

cryptoclans_pl.txt


cryptoclans.pl
#!/bin/perl -T

# Copyright (c) 2010 Jason Filley jason@snakelegs.org
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Purpose: create cryptoclans
# Usage:  create a pipe-delimited file with the first field being the topic,
#       and each additional field is the item.
# cat yourfile.txt | cryptoclans.pl
#
# Example:
# Pets|dog|cat|fish|parakeet|lemur|skunk|guinea pig|iguana
# Car Make|Ford|Dodge|Chrysler|Toyota|Honda|Hyundai|Jeep
# Dog Breeds|Sheltie|Boxer|German Shepherd|Poodle|Rottweiler|Australian Terrier|Whippet

use warnings;
use List::Util 'shuffle';

my $AllowedLetters     = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
my $AllowedPunctuation = ' \'-';

while (<STDIN>) {

    my @line = split( '\|', $_ );
    $topic = shift(@line);

    # Create ciphertext alphabet
    @ciphertext = split '', $AllowedLetters;
    @ciphertext = shuffle(@ciphertext);
    my $cipher = join '', @ciphertext;
    my @outlist = ();

    print "$topic\n";
    print( "-" x length($topic) );
    print "\n";

    foreach $item (@line) {
        $item = uc($item);
        chomp $item;

        $output = '';

        foreach my $byte ( split //, $item ) {

            if ( $AllowedPunctuation =~ /$byte/ ) {
                $output .= $byte;

            }
            elsif ( $AllowedLetters =~ /$byte/ ) {

                #find its index in the plaintext array
                $index = index( $AllowedLetters, $byte );

                #find the ciphertext character with the same index
                $char = substr( $cipher, $index, 1 );
                $output .= $char;
            }
            else {
                die 'Bad character in input!\n';
            }
        }

        push @outlist, "$output";
    }

    print map { "$_ \n" } @outlist;
    print "\n\n";
}


Example output:


Cryptoclans sample output
$ cat input.txt
Pets|dog|cat|fish|parakeet|lemur|skunk|guinea pig|iguana
Car Make|Ford|Dodge|Chrysler|Toyota|Honda|Hyundai|Jeep
Dog Breeds|Sheltie|Boxer|German Shepherd|Poodle|Rottweiler|Australian Terrier|Whippet

$ cat input.txt | ./cryptoclans.pl
Pets
----
VLU
TAG
QSKP
XAFABHHG
EHOZF
KBZNB
UZSNHA XSU
SUZANA


Car Make
--------
BESG
GEGVC
RLSPMACS
OEPEOQ
LEDGQ
LPWDGQN
YCCU


Dog Breeds
----------
XQWGTCW
SZFWI
HWIJOV XQWUQWIN
UZZNGW
IZTTDWCGWI
OEXTIOGCOV TWIICWI
DQCUUWT




Decoding Borderware MXtreme obfuscated Subject: lines


These were decent appliances, back in the day.  The MXtremes obfuscated the Subject: lines in the log files, which made them difficult to search.  Was just a simple substitution.

mxdecpl.txt


mxdecpl.pl
#!/usr/bin/perl
# synopsis: decode Borderware MXtreme obfuscated archived Subject: lines
# usage: mxdec.pl < file
# licence: public domain
#
# Alvin Fernald lives!
# ISBN-10: 1932350004
# ISBN-13: 978-1932350005

use strict;
use warnings;

#escape \ $ " @
my $ciphertext =
"1 \"34%7'908+[-E<)!\@#\$=^&*({}/5e]~2iwvf.zcbamstukpjlghorxyqnd,\\?6_`IHGZ>DRSAPNQJYTOXUKLMCBVWF:|;";

my $plaintext =
"!~\"#\$%&'()*+,-./0123456789:;<=>? \@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}";

while (<STDIN>) {
    if ( $_ =~ /subject=/ ) {
        my @line = split( " ", $_ );
        my $queueid = $line[5];

        if ( $_ =~ /subject=(.*)/g ) {
            print "$queueid";
            my $realsubject = &Translate($1);
            print $realsubject;
            print "\n";
        }
    }
}

sub Translate {

    my $input  = $_[0];
    my $output = "";

    # process each character in the ciphertext
    foreach my $byte ( split //, $input ) {

        # find its index in the ciphertext array
        my $index = index( $ciphertext, $byte );

        # find the plaintext character with same index
        my $char = substr( $plaintext, $index, 1 );
        $output .= $char;
    }
    return $output;
}