-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more MC2010, substituion cipher implemented, tests, bump version
- Loading branch information
Showing
11 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ module ToyCipher | |
require 'otp' | ||
require 'playfair' | ||
require 'morse' | ||
require 'substitution' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Frevbhfyl? Ntnva? Ebg guvegrra? Whfg jung qb lbh gnxr zr sbe? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |