Cipher plugin using Atbash (somewhat similar to ROT13)

master
tagawa 2013-01-25 16:30:15 +09:00
parent 99b429b827
commit 1d55fac7a4
2 changed files with 65 additions and 0 deletions

45
lib/DDG/Goodie/Atbash.pm Normal file
View File

@ -0,0 +1,45 @@
package DDG::Goodie::Atbash;
# ABSTRACT: A simple substitution cipher using a reversed alphabet
use DDG::Goodie;
primary_example_queries 'atbash hello';
secondary_example_queries 'atbash svool';
description 'A simple substitution cipher using a reversed alphabet';
name 'Atbash';
code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Atbash.pm';
category 'transformations';
topics 'cryptography';
attribution web => ['http://kyokodaniel.com/tech/', 'Daniel Davis'],
github => ['https://github.com/tagawa', 'tagawa'],
twitter => ['https://twitter.com/ourmaninjapan', 'ourmaninjapan'];
triggers start => 'atbash';
zci is_cached => 1;
handle remainder => sub {
if ($_) {
my $char;
my $result;
while (/(.)/g) {
if ($1 =~ /([a-z])/) {
# Substitute lowercase characters
$char = chr(219 - ord $1);
}
elsif ($1 =~ /([A-Z])/) {
# Substitute uppercase characters
$char = chr(155 - ord $1);
}
else { $char = $1; }
$result .= $char;
}
return "Atbash: $result";
}
return;
};
1;

20
t/Atbash.t Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => 'atbash';
zci is_cached => 1;
ddg_goodie_test(
[qw(
DDG::Goodie::Atbash
)],
'atbash test' => test_zci('Atbash: gvhg'),
'atbash This is a test' => test_zci('Atbash: Gsrh rh z gvhg'),
'atbash Gonna party like it\'s 1999!' => test_zci('Atbash: Tlmmz kzigb orpv rg\'h 1999!'),
);
done_testing;