Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Ximp

by beretboy (Chaplain)
on Dec 02, 2001 at 04:27 UTC ( #128931=sourcecode: print w/ replies, xml ) Need Help??

Category: Cryptography
Author/Contact Info perlmonk@m-net.arbornet.org
Description: A encryption algorithm. That I whipped up. Takes file name as command line argument, -d switch sets it into decrypt mode. Key can be anything but the longer the better.XIMP stands for XIMP Is Mucho Polyalphabetic. DISCLAIMER: This should by no means be taken seriously! It was simply an experiment! This is by no means real crypto and could be cracked by anyone with even limited knowledge of cryptography.
#!/usr/bin/perl

use strict;

my @wheel1 = qw( 8 4 6 6 3 3 8 4 );
my @wheel2 = qw( 1 2 4 6 3 8 8 9 5 1 6 1 7 2 8 1 );
print "KEY:";
chomp(my $key = <STDIN>);
my @wheel3 = map(ord, split //, $key);

my $file = @ARGV[0];
$/ = undef;
print "OPENING $file\n";
open(IN, "$file") || die "painful death! (because there is no $file)";
my ($out);
my $plaintext = <IN>;
close(IN);
open(OUT, ">$file");

my @nums = map(ord, split //, $plaintext);

foreach (@nums) {
print "*";
my $x = @wheel1[0] + @wheel2[0] + @wheel3[0];

if (@ARGV[1] eq "-d") {
$out = $_ + $x;
} else {
$out = $_ - $x;
}
$out = chr $out;

print OUT $out;

push @wheel1, shift @wheel1;
push @wheel2, shift @wheel2;
print "\b";
}

Comment on Ximp
Download Code
Re: Ximp
by sparkyichi (Deacon) on Dec 02, 2001 at 04:57 UTC
    It's enigma all over again. The code is short and to the point, just how Perl should be. Sparky
Re: Ximp
by Zaxo (Archbishop) on Dec 02, 2001 at 12:55 UTC

    This is fun but not too serious crypo. Your wheels have period 16. Give wheel0 9 elements instead of 8 and the period goes to 144=9*16. If the keyword is relatively prime in length, multiply by that length to get the new period. With a long enough plaintext, it's pretty easy to deduce the repetition length and language. From that follows character frequency analysis.

    It's also a concern that addition of random elements in a fixed range _reduces_ randomness.

    After Compline,
    Zaxo

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://128931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-08-22 09:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (152 votes), past polls