From d3ad4d82871ee20efe56df44301f59897b739d2d Mon Sep 17 00:00:00 2001 From: Jeffrey ODell Date: Thu, 25 Mar 2010 10:13:01 -0500 Subject: [PATCH] master: readme, roadmap, gitignore, test & script updates --- .autotest | 1 - .gitignore | 2 ++ README | 12 ++++++++++++ ROADMAP | 19 +++++++++++++++++++ script/toycipher | 7 +++++++ test/tc_cli.rb | 38 ++++++++++++++++++++++++++++++++------ 6 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 .gitignore create mode 100644 README create mode 100644 ROADMAP diff --git a/.autotest b/.autotest index 47d4329..771d96c 100644 --- a/.autotest +++ b/.autotest @@ -15,7 +15,6 @@ end # Override autotest default magic to rerun all tests every time a # change is detected on the file system. class Autotest - def get_to_green begin rerun_all_tests diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c8b02d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tmp/* +*.log diff --git a/README b/README new file mode 100644 index 0000000..798a55f --- /dev/null +++ b/README @@ -0,0 +1,12 @@ +== ToyCipher == + +A ruby implementation of classic ciphers, including: + +* PlayFair +* One-time Pad +* Vigenere +* Caesar + +== Author == + +Jeffrey O'Dell diff --git a/ROADMAP b/ROADMAP new file mode 100644 index 0000000..d889548 --- /dev/null +++ b/ROADMAP @@ -0,0 +1,19 @@ + +0.1 + +* Playfair +* Caesar +* Vigenere +* OTP + +0.2 + +* CLI script +* tests +* documentation + +0.3 + +* Support matrix transposition +* Brute-force heuristic + diff --git a/script/toycipher b/script/toycipher index 163b272..6e2b548 100755 --- a/script/toycipher +++ b/script/toycipher @@ -19,6 +19,7 @@ class OptParseToyCipher opts.on("-i", "--input-file file", "Input file for encryption or decryption") do |f| options[:infile] = f end + opts.on("--demo", "Example Ciphers") { options[:demo] = true } opts.on("-d", "--decrypt [ciphertext]", "Ciphertext to decrypt") { |d| options[:ciphertext] = d } opts.on("-e", "--encrypt [plaintext]", "Plaintext to encrypt") { |e| @@ -80,6 +81,12 @@ def print_result(results) end end +def prepare_input + stream = IO.readlines @options[:infile] +end + +prepare_input_file if @options[:infile] + @keys.each do |k| # FIXME: Move this @cipher = instance_eval "ToyCipher::#{@options[:cipher]}.new" diff --git a/test/tc_cli.rb b/test/tc_cli.rb index cb8af75..5d39eb6 100755 --- a/test/tc_cli.rb +++ b/test/tc_cli.rb @@ -5,6 +5,27 @@ class TestCli < Test::Unit::TestCase + SHMOO_ANS_1 = <<-SHMOO +OYETLZZZZBNZTTZRUWTPAHXOANNOEEAZCRHEZYZIZATEZZZHTTZZCIEEASDTZSLEKQALKRADYIODBLMY +KOZTEZOHYRZCOZFETZROLETZTETUSZNTAZEYEMBZTKZWEZYAOZRZHNMRTADRDOTCFMELMYQCLDQHTRCY +AUPYVNNAOOTRZYIDZTASLZSCEZISSZTHECRZPOUHOESHANOVZTENEGEZZIOZRYRWLRALEELDQHTRCYET +YZRZEOLVUKHYBOGZHONEZTZRZCNZAGEESIZIOUTAZZOASOUEGHSOAZMWIDLSIYZHLBZSALEECGQDCAIY +ZRECRTYEZEEPUUUOOZSZTETEOOUMGRDZAPKSNSZDMIMTYWZZEETZTRBHZZLTSQATTSQOSTSOZHVYPODL +SHMOO + + SHMOO_CT = <<-SHMOO +VFLASGGGGIUGAAGYBDAWHOEVHUUVLLHGJYOLGFGPGHALGGGOAAGGJPLLHZKAGZSLRXHSRYHKFPVKISTF +XBMGRMBULEMPBMSRGMEBYRGMGRGHFMAGNMRLRZOMGXMJRMLNBMEMUAZEGNQEQBGPSZRYZLDPYQDUGEPL +BVQZWOOBPPUSAZJEAUBTMATDFAJTTAUIFDSAQPVIPFTIBOPWAUFOFHFAAJPASZSXMSBMFFMERIUSDZFU +QRJRWGDNMCZQTGYRZGFWRLRJRUFRSYWWKARAGMLSRRGSKGMWYZKGSREOAVDKAQRZDTRKSDWWUYIVUSAQ +KCPNCEJPKPPAFFFZZKDKEPEPZZFXRCOKLAVDYDKOXTXEJHKKPPEKECMSKKWEDBLEEDBZDEDZKSGJAZOW +SHMOO + + TF = { + :out_f => '/tmp/test_toycipher_cli.out', + :shmoocon2010_1 => '/tmp/shmoocon2010_1' + }.freeze + def setup @cli ||= File.expand_path(File.dirname(__FILE__)) + '/../script/toycipher' @pt ||= 'Hide the gold in the tree stump' @@ -12,11 +33,10 @@ def setup @k2 ||= 'foo bar' @pf_ciphertext ||= 'BM ND ZB XD KY BE JV DM UI XM MN UV IF ' @pf_ciphertext2 ||= 'CM EG UG GH AJ CJ PU CG UA KB KX UN JU ' - @outfile ||= '/tmp/test_toycipher_cli.out' end def teardown - FileUtils.rm @outfile if File.exists? @outfile + TF.each { |k, f| FileUtils.rm f if File.exists?(f) } end def test_cli_help @@ -53,11 +73,11 @@ def test_cli_playfair2 end def test_cli_out_file - args = "-e '#{@pt}' -c playfair -k '#{@k}' -o #{@outfile}" - puts "Running '#{@clie} #{args}'" + args = "-e '#{@pt}' -c playfair -k '#{@k}' -o #{TF[:out_f]}" + #puts "Running '#{@clie} #{args}'" cli_out = %x[#{@cli} #{args}].chomp assert_equal '', cli_out - assert_equal true, File.exists?(@outfile) + assert_equal true, File.exists?(TF[:out_f]) #assert_equal @pf_ciphertext, IO.readlines(@outfile).first.chomp end @@ -66,11 +86,17 @@ def test_pretty_output def test_multi_keys args = "-e '#{@pt}' -c playfair -k '#{@k},#{@k2}' " - puts "Running '#{@clie} #{args}'" + #puts "Running '#{@clie} #{args}'" cli_out = %x[#{@cli} #{args}].chomp #puts cli_out assert_equal [@pf_ciphertext, @pf_ciphertext2].join("\n"), cli_out end + def test_shmoocon2010_part1 + shmooct = File.open(TF[:shmoocon2010_1], 'w') { |f| f << SHMOO_CT } + args = "-e -i #{TF[:shmoocon2010_1]} -c caesar -k 'G'" + cli_out = %x[#{@cli} #{args}].chomp + end + end