Skip to content

Commit

Permalink
master: readme, roadmap, gitignore, test & script updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jodell committed Mar 25, 2010
1 parent 0861465 commit d3ad4d8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 7 deletions.
1 change: 0 additions & 1 deletion .autotest
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tmp/*
*.log
12 changes: 12 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
== ToyCipher ==

A ruby implementation of classic ciphers, including:

* PlayFair
* One-time Pad
* Vigenere
* Caesar

== Author ==

Jeffrey O'Dell <jefferey dot odell at gmail dot com>
19 changes: 19 additions & 0 deletions ROADMAP
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

0.1

* Playfair
* Caesar
* Vigenere
* OTP

0.2

* CLI script
* tests
* documentation

0.3

* Support matrix transposition
* Brute-force heuristic

7 changes: 7 additions & 0 deletions script/toycipher
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down Expand Up @@ -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"
Expand Down
38 changes: 32 additions & 6 deletions test/tc_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,38 @@

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'
@k ||= 'playfair example'
@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
Expand Down Expand Up @@ -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

Expand All @@ -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

0 comments on commit d3ad4d8

Please sign in to comment.