#!/usr/bin/perl -w # # Script for creating a cryptogram out of a plaintext # ascii file. # # By: Rob Hudson # Created: 22 Jan 2000 use Text::Wrap; my $alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; my $inFile = $ARGV[0] if ($ARGV[0] ne "") or die "No file specified\n"; # Read it, Scrunch it, Up it. open IN, $inFile or die "Can't open input file: $!"; my $text = ""; while () { s/[\s]+/ /g; $text .= $_; } close (IN); $text = uc($text); # Build random alphabet string, not allowing repeat letters my @alpha = split //, $alpha; my $substit = join '', fisher_yates_shuffle(\@alpha); # Have to use an eval since $vars don't get interpreted # inside a tr call. eval "\$text =~ tr/$alpha/$substit/"; print wrap ("","", $text), "\n"; # Fisher Yates Shuffle algorithm found in perlfaq4 sub fisher_yates_shuffle { my $array = shift; for (my $i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i, $j] = @$array[$j, $i]; } return join '', @$array; }