# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 1.t' use strict; use warnings; ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test; BEGIN { plan tests => 5 }; ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. BEGIN { push(@INC, "./blib/arch/auto/Cyfer"); } use Cyfer::Hash; use Cyfer::BlockCipher; use Cyfer::StreamCipher; use Cyfer::Pk; use Cyfer::KeyEx; sub bin2hex { my ($raw) = @_; my @a = split(//, $raw); my @b; foreach my $x (@a) { push(@b, sprintf("%02x", ord($x))); } return join("", @b); } sub test_hash { my $a = new Cyfer::Hash("MD5"); $a->Update("Hello World"); my $res = $a->Finish(); return 1 if (bin2hex($res) eq "b10a8db164e0754105b7a99be72e3fe5"); return 0; } sub test_bcipher { my $a = new Cyfer::BlockCipher("Blowfish", "Forty-Two", "ECB", ""); my $str = "A quick brown fox jumps over the lazy dog"; my $str1 = $a->Encrypt($str); my $str2 = $a->Decrypt($str1); return 1 if ($str eq substr($str2, 0, length($str))); return 0; } sub test_scipher { my $a = new Cyfer::StreamCipher("RC4", "Forty-Two"); my $b = new Cyfer::StreamCipher("RC4", "Forty-Two"); my $str = "A quick brown fox jumps over the lazy dog"; my $str1 = $a->Encrypt($str); my $str2 = $b->Decrypt($str1); return 1 if ($str eq $str2); return 0; } sub test_pk { my $str = "A quick brown fox jumps over the lazy dog"; my $a = new Cyfer::Pk("RSA"); $a->GenerateKey(512); my ($privkey, $pubkey) = $a->ExportKey(); my $b = new Cyfer::Pk("RSA"); $b->ImportKey('', $pubkey); my $str1 = $a->Encrypt($str); my $c = new Cyfer::Pk("RSA"); $c->ImportKey($privkey, ''); my $str2 = $c->Decrypt($str1); return 1 if ($str eq substr($str2, 0, length($str))); return 0; } sub test_keyex { my $alice = new Cyfer::KeyEx("DH"); $alice->GenerateKey(); my $a = $alice->PublicKey(); my $bob = new Cyfer::KeyEx("DH"); $bob->GenerateKey(); my $b = $bob->PublicKey(); $alice->ComputeKey($b); $bob->ComputeKey($a); my $sa = $alice->SharedKey(100); my $sb = $bob->SharedKey(100); return 1 if ($sa eq $sb); return 0; } ok(test_hash()); ok(test_bcipher()); ok(test_scipher()); ok(test_pk()); ok(test_keyex());