Skip to content

Commit

Permalink
more MC2010, substituion cipher implemented, tests, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
jodell committed Aug 2, 2010
1 parent ac1354f commit bbbcdea
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 9 deletions.
5 changes: 3 additions & 2 deletions ROADMAP
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
* LICENSE
* Support supplying a key file

-==-
0.5
-==-
* String extension for phone numbers
* Ruby gem support
* matrix display (m x n)

-==-
0.6
-==-
* Basic Morse Code!
* substitution cipher

1.0
* Large text testing
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

spec = Gem::Specification.new do |s|
s.name = "toycipher"
s.version = "0.5" # FIXME
s.version = IO.readlines(File.dirname(__FILE__) + '/VERSION', 'r').first.chomp
s.author = "Jeffrey ODell"
s.email = "[email protected]"
s.homepage = "http://github.com/jodell/toycipher"
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.6
1 change: 1 addition & 0 deletions lib/toycipher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ module ToyCipher
require 'otp'
require 'playfair'
require 'morse'
require 'substitution'
end
38 changes: 38 additions & 0 deletions lib/toycipher/substitution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'toycipher'

class ToyCipher::Substitution < ToyCipher::ToyCipherBase
def initialize
super
end

def key=(key)
new_key = case key
when String
key.split(//)
when Array
key
end
@key = @alph.zip(new_key).inject({}) do |acc, pair|
acc[pair.first] = pair.last
acc
end
end

def encrypt(plaintext = @plaintext)
normalize(ciphertext).split(//).inject('') do |acc, c|
acc += @key[c]
end
end

def decrypt(ciphertext = @ciphertext, key = @key)
normalize(ciphertext).split(//).inject('') do |acc, c|
acc += @key.invert[c]
end
end

def brute
@alph.each do |c|
end
end

end
Binary file added pkg/toycipher-0.6.gem
Binary file not shown.
11 changes: 5 additions & 6 deletions script/mc2010/keifer_pi.diff
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
643383

4062862

066470938

105559644

19091456

82925409

46034 # missing in first half of keifer
05882 # ??? seems misplaced, extra in keifer

5 12 17 9 6 3 # dear friend

FNVBQDZEXOPUHTLSJKACWIMYRG

6 14 22 2 4

1 change: 1 addition & 0 deletions script/mc2010/kenji.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Frevbhfyl? Ntnva? Ebg guvegrra? Whfg jung qb lbh gnxr zr sbe?
2 changes: 2 additions & 0 deletions script/mc2010/kenji.raw.answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jodell@benedict~/git/toycipher/script/mc2010>../toycipher -d caesar -k 12 < kenji.raw
SERIOUSLYAGAINROTTHIRTEENJUSTWHATDOYOUTAKEMEFOR
69 changes: 69 additions & 0 deletions script/mc2010/mask
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

bottom, right, top, left
01128456510
151702147323074
65123707267
456510146414132

serial
0112845651015170214732307465123707267456510146414132

bottom
.`) - 0
>.) - 1
>.) - 1
..) - 2
><) - 8
`.) - 4
``) - 5
>`) - 6
``) - 5
>.) - 1
.`) - 0
right
>.) - 1
``) - 5
>.) - 1
.<) - 7
.`) - 0
..) - 2
>.) - 1
`.) - 4
.<) - 7
`<) - 3
..) - 2
`<) - 3
.`) - 0
.<) - 7
`.) - 4
top
>`) - 6
``) - 5
>.) - 1
..) - 2
`<) - 3
.<) - 7
.`) - 0
.<) - 7
..) - 2
>`) - 6
.<) - 7

left
`.) - 4
``) - 5
>`) - 6
``) - 5
>.) - 1
.`) - 0
>.) - 1
`.) - 4
>`) - 6
`.) - 4
>.) - 1
`.) - 4
>.) - 1
`<) - 3
..) - 2


46 changes: 46 additions & 0 deletions test/tc_substitution.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@


require 'test_helper'

class TestSubstitutionCipher < Test::Unit::TestCase

def setup
@cipher = ToyCipher::Substitution.new
end

def teardown
end

def test_substitution
key = 'FNVBQDZEXOPUHTLSJKACWIMYRG'
ciphertext = <<-EoC
MQA
FRFZF
XTBQUX
NQKFCQU
RCEFCEW
HFTXTZQ
TWXCDVF
TTLCVLTV
LVCFVRSE
QKMEXVE
EWHFTXT
ZQTWXC
RVFTTL
CKQAL
UIQ
EoC
@cipher.key = key
puts @cipher.key.sort.inspect
puts @cipher.decrypt(ciphertext)

# 'WE SAY AGAIN DELIBERATELY THAT HUMAN INGENUITF CANNOT
# CONCOCT A CYPHER WHICH HUMAN INGENUITY CANNOT RESOLVE'
# - Edgar Allen Poe (via LosT)
#
plaintext = 'WESAYAGAINDELIBERATELYTHATHUMANINGENUITF' +
'CANNOTCONCOCTACYPHERWHICHHUMANINGENUITYCANNOTRESOLVE'
assert_equal plaintext, @cipher.decrypt(ciphertext)
end

end

0 comments on commit bbbcdea

Please sign in to comment.