rubyzip 0.9.1 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (54) hide show
  1. data/ChangeLog +92 -450
  2. data/NEWS +18 -0
  3. data/README +1 -1
  4. data/Rakefile +14 -13
  5. data/install.rb +4 -3
  6. data/lib/zip/ioextras.rb +11 -1
  7. data/lib/zip/stdrubyext.rb +0 -0
  8. data/lib/zip/tempfile_bugfixed.rb +0 -0
  9. data/lib/zip/zip.rb +57 -24
  10. data/lib/zip/zipfilesystem.rb +1 -0
  11. data/lib/zip/ziprequire.rb +0 -0
  12. data/samples/example.rb +0 -0
  13. data/samples/example_filesystem.rb +0 -1
  14. data/samples/gtkRubyzip.rb +0 -0
  15. data/samples/qtzip.rb +0 -0
  16. data/samples/write_simple.rb +0 -0
  17. data/samples/zipfind.rb +0 -0
  18. data/test/alltests.rb +0 -0
  19. data/test/data/notzippedruby.rb +0 -0
  20. data/test/gentestfiles.rb +0 -0
  21. data/test/ioextrastest.rb +0 -0
  22. data/test/stdrubyexttest.rb +0 -0
  23. data/test/zipfilesystemtest.rb +14 -4
  24. data/test/ziprequiretest.rb +0 -0
  25. data/test/ziptest.rb +30 -9
  26. metadata +76 -88
  27. data/lib/download_quizzes.rb +0 -119
  28. data/lib/quiz1/t/solutions/Bill Guindon/solitaire.rb +0 -205
  29. data/lib/quiz1/t/solutions/Carlos/solitaire.rb +0 -111
  30. data/lib/quiz1/t/solutions/Dennis Ranke/solitaire.rb +0 -111
  31. data/lib/quiz1/t/solutions/Florian Gross/solitaire.rb +0 -301
  32. data/lib/quiz1/t/solutions/Glen M. Lewis/solitaire.rb +0 -268
  33. data/lib/quiz1/t/solutions/James Edward Gray II/solitaire.rb +0 -132
  34. data/lib/quiz1/t/solutions/Jamis Buck/bin/main.rb +0 -13
  35. data/lib/quiz1/t/solutions/Jamis Buck/lib/cipher.rb +0 -230
  36. data/lib/quiz1/t/solutions/Jamis Buck/lib/cli.rb +0 -24
  37. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_deck.rb +0 -30
  38. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_key-stream.rb +0 -19
  39. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_keying-algorithms.rb +0 -31
  40. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb +0 -66
  41. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_unkeyed-algorithm.rb +0 -17
  42. data/lib/quiz1/t/solutions/Jamis Buck/test/tests.rb +0 -2
  43. data/lib/quiz1/t/solutions/Jim Menard/solitaire_cypher.rb +0 -204
  44. data/lib/quiz1/t/solutions/Jim Menard/test.rb +0 -47
  45. data/lib/quiz1/t/solutions/Moses Hohman/cipher.rb +0 -97
  46. data/lib/quiz1/t/solutions/Moses Hohman/deck.rb +0 -140
  47. data/lib/quiz1/t/solutions/Moses Hohman/solitaire.rb +0 -14
  48. data/lib/quiz1/t/solutions/Moses Hohman/test_cipher.rb +0 -68
  49. data/lib/quiz1/t/solutions/Moses Hohman/test_deck.rb +0 -146
  50. data/lib/quiz1/t/solutions/Moses Hohman/test_util.rb +0 -38
  51. data/lib/quiz1/t/solutions/Moses Hohman/testsuite.rb +0 -5
  52. data/lib/quiz1/t/solutions/Moses Hohman/util.rb +0 -27
  53. data/lib/quiz1/t/solutions/Niklas Frykholm/solitaire.rb +0 -151
  54. data/lib/quiz1/t/solutions/Thomas Leitner/solitaire.rb +0 -198
@@ -1,24 +0,0 @@
1
- class CLI
2
-
3
- ENCRYPTED = /^([A-Z]{5} )*[A-Z]{5}$/
4
-
5
- attr_writer :cipher
6
- attr_writer :options
7
-
8
- def run
9
- return unless @options.run_app?
10
-
11
- @cipher.use_algorithm @options.keying_algorithm
12
-
13
- @options.strings.each do |arg|
14
- if arg =~ ENCRYPTED
15
- puts arg.inspect
16
- puts " (decrypt)--> #{@cipher.decrypt(arg).inspect}"
17
- else
18
- puts arg.inspect
19
- puts " (encrypt)--> #{@cipher.encrypt(arg).inspect}"
20
- end
21
- end
22
- end
23
-
24
- end
@@ -1,30 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_Deck < Test::Unit::TestCase
6
-
7
- def setup
8
- @deck = Deck.new
9
- end
10
-
11
- def test_content
12
- expected = (1..52).to_a + [ "A", "B" ]
13
- assert_equal expected, @deck.to_a
14
- end
15
-
16
- def test_shuffle
17
- @deck.cipher_shuffle!
18
- expected = (2..52).to_a + [ "A", "B", 1 ]
19
- assert_equal expected, @deck.to_a
20
- end
21
-
22
- def test_letter
23
- expected = %w{ D W J nil X H Y R F D G }
24
- expected.each do |expected_letter|
25
- @deck.cipher_shuffle!
26
- assert_equal expected_letter, @deck.cipher_letter || "nil"
27
- end
28
- end
29
-
30
- end
@@ -1,19 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_KeyStream < Test::Unit::TestCase
6
-
7
- def setup
8
- @stream = KeyStream.new
9
- @stream.deck = Deck.new
10
- end
11
-
12
- def test_next
13
- expected = %w{ D W J X H Y R F D G }
14
- expected.each do |expected_letter|
15
- assert_equal expected_letter, @stream.next
16
- end
17
- end
18
-
19
- end
@@ -1,31 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_KeyingAlgorithms < Test::Unit::TestCase
6
-
7
- class MockRegistry
8
- def service( name )
9
- return "found" if name == "something.mock"
10
- return nil
11
- end
12
- end
13
-
14
- def setup
15
- @algorithms = KeyingAlgorithms.new
16
- @algorithms.algorithms = { "mock" => "something.mock" }
17
- @algorithms.registry = MockRegistry.new
18
- end
19
-
20
- def test_get_not_found
21
- assert_raise( RuntimeError ) do
22
- @algorithms.get( "bogus" )
23
- end
24
- end
25
-
26
- def test_get_found
27
- svc = @algorithms.get( "mock" )
28
- assert_equal svc, "found"
29
- end
30
-
31
- end
@@ -1,66 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_SolitaireCipher < Test::Unit::TestCase
6
-
7
- class MockAlgorithms
8
- def get( name )
9
- MockAlgorithm.new
10
- end
11
- end
12
-
13
- class MockDeck
14
- def cipher_shuffle!
15
- end
16
-
17
- def cipher_letter
18
- "X"
19
- end
20
- end
21
-
22
- class MockAlgorithm
23
- def new_deck
24
- MockDeck.new
25
- end
26
- end
27
-
28
- def setup
29
- @cipher = SolitaireCipher.new( UnkeyedAlgorithm.new )
30
- @cipher.algorithms = MockAlgorithms.new
31
- @cipher.stream = KeyStream.new
32
- end
33
-
34
- def test_use_algorithm
35
- @cipher.use_algorithm "mock"
36
- assert_equal "FCJJM", @cipher.encrypt( "HELLO" )
37
- assert_equal "JGNNQ", @cipher.decrypt( "HELLO" )
38
- end
39
-
40
- def test_encrypt
41
- msg = "Code in Ruby! Live longer."
42
- expected = "GLNCQ MJAFF FVOMB JIYCB"
43
- assert_equal expected, @cipher.encrypt( msg )
44
- end
45
-
46
- def test_decrypt_bad
47
- assert_raise( RuntimeError ) do
48
- @cipher.decrypt( "not good" )
49
- end
50
-
51
- assert_raise( RuntimeError ) do
52
- @cipher.decrypt( "BOGUS 12345" )
53
- end
54
- end
55
-
56
- def test_decrypt_good
57
- msg = "CLEPK HHNIY CFPWH FDFEH"
58
- expected = "YOURCIPHERISWORKINGX"
59
- assert_equal expected, @cipher.decrypt( msg )
60
-
61
- msg = "ABVAW LWZSY OORYK DUPVH"
62
- expected = "WELCOMETORUBYQUIZXXX"
63
- assert_equal expected, @cipher.decrypt( msg )
64
- end
65
-
66
- end
@@ -1,17 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_UnkeyedAlgorithm < Test::Unit::TestCase
6
-
7
- def setup
8
- @algo = UnkeyedAlgorithm.new
9
- end
10
-
11
- def test_new_deck
12
- expected = (1..52).to_a + [ "A", "B" ]
13
- deck = @algo.new_deck
14
- assert_equal expected, deck.to_a
15
- end
16
-
17
- end
@@ -1,2 +0,0 @@
1
- Dir.chdir File.dirname( __FILE__ )
2
- Dir["tc_*.rb"].each { |test| load test }
@@ -1,204 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- RANKS = %w(A 2 3 4 5 6 7 8 9 10 J Q K)
4
- SUITS = %w(C D H S)
5
- JOKER_RANK = 'joker'
6
- JOKER_VALUE = -1
7
-
8
- class Card
9
- def Card.value_to_chr(value)
10
- i = value
11
- i -= 26 while i > 26
12
- (i + ?A - 1).chr
13
- end
14
- def Card.chr_to_value(chr)
15
- i = chr[0] - ?A + 1
16
- i += 26 while i < 0
17
- i
18
- end
19
-
20
- def initialize(rank, suit)
21
- @rank = rank
22
- @suit = suit
23
- if rank == JOKER_RANK
24
- @value = JOKER_VALUE
25
- else
26
- @value = (SUITS.index(suit) * 13) + RANKS.index(rank) + 1
27
- end
28
- end
29
-
30
- def to_s
31
- # return @value.to_s if @value != JOKER_VALUE
32
- # return @suit.to_s
33
- "#{@rank}#{@suit} #{@value.to_s}"
34
- end
35
-
36
- def to_i
37
- @value
38
- end
39
-
40
- def chr
41
- Card.value_to_chr(@value)
42
- end
43
- end
44
-
45
- class Deck
46
-
47
- def initialize
48
- @cards = []
49
- SUITS.each { | suit |
50
- RANKS.each { | rank | @cards << Card.new(rank, suit) }
51
- }
52
- @joker_a = Card.new(JOKER_RANK, 'A')
53
- @cards << @joker_a
54
- @joker_b = Card.new(JOKER_RANK, 'B')
55
- @cards << @joker_b
56
- end
57
-
58
- # Keys the deck and returns itself.
59
- def key
60
- # do nothing; keyed when initialized
61
- self
62
- end
63
-
64
- # Return the next kestream value as a number (not a string).
65
- # Keep going until we have a non-joker value.
66
- def next_keystream
67
- val = JOKER_VALUE
68
- until val != JOKER_VALUE
69
- val = generate_next_keystream_value
70
- end
71
- val
72
- end
73
-
74
- # Return the next keystream value as a number 1-26 (not a string).
75
- def generate_next_keystream_value
76
- move(@joker_a, 1)
77
- move(@joker_b, 2)
78
- triple_cut()
79
- count_cut()
80
- return output_number()
81
- end
82
-
83
- # Move a card a certain distance. Wrap around the end of the deck.
84
- def move(card, distance)
85
- old_pos = @cards.index(card)
86
- new_pos = old_pos + distance
87
- new_pos -= (@cards.length-1) if new_pos >= @cards.length
88
- @cards[old_pos,1] = []
89
- @cards[new_pos,0] = [card]
90
- end
91
-
92
- # Perform a triple cut around the two jokers. All cards above the top
93
- # joker move to below the bottom joker and vice versa. The jokers and the
94
- # cards between them do not move.
95
- def triple_cut
96
- i = @cards.index(@joker_a)
97
- j = @cards.index(@joker_b)
98
- j, i = i, j if j < i # make sure i < j
99
- @cards = slice(j+1, -1) + slice(i, j) + slice(0, i-1)
100
- end
101
-
102
- # Perform a count cut using the value of the bottom card. Cut the bottom
103
- # card's value in cards off the top of the deck and reinsert them just
104
- # above the bottom card.
105
- def count_cut
106
- i = @cards[@cards.length - 1].to_i
107
- @cards = slice(i, -2) + slice(0, i-1) + [@cards[@cards.length-1]]
108
- end
109
-
110
- # Returns a non-nil cut of cards from the deck.
111
- def slice(from, to)
112
- slice = @cards[from..to]
113
- return slice || []
114
- end
115
-
116
- # Return the output number (not letter). Convert the top card to it's
117
- # value and count down that many cards from the top of the deck, with the
118
- # top card itself being card number one. Look at the card immediately
119
- # after your count and convert it to a letter. This is the next letter in
120
- # the keystream. If the output card is a joker, no letter is generated
121
- # this sequence. This step does not alter the deck.
122
- def output_number
123
- i = @cards[0].to_i
124
- i -= @cards.length if i >= @cards.length
125
- num = @cards[i].to_i
126
- num -= 26 if num > 26
127
- num
128
- end
129
-
130
- def to_s
131
- @cards.join(' ')
132
- end
133
- end
134
-
135
- class CryptKeeper
136
-
137
- def initialize(deck)
138
- @keyed_deck = deck
139
- end
140
-
141
- def decrypt(str)
142
- @deck = @keyed_deck.dup
143
- answer = ""
144
- str.split(//).each { | c |
145
- if c == ' '
146
- answer << ' '
147
- next
148
- end
149
-
150
- msg_num = Card.chr_to_value(c)
151
- key = @deck.next_keystream
152
- diff = msg_num - key
153
- diff += 26 if diff < 1
154
- answer << Card.value_to_chr(diff)
155
- }
156
- answer
157
- end
158
-
159
- def encrypt(str)
160
- @deck = @keyed_deck.dup
161
- answer = ''
162
- str.split(//).each { | c |
163
- if c == ' '
164
- answer << ' '
165
- next
166
- end
167
-
168
- msg_num = Card.chr_to_value(c)
169
- key = @deck.next_keystream
170
- sum = msg_num + key
171
- sum -= 26 if sum > 26
172
- answer << Card.value_to_chr(sum)
173
- }
174
- answer
175
- end
176
-
177
- def crypto_each(str)
178
- @deck = @keyed_deck.dup
179
- str.split(//).each { | c | yield c }
180
- end
181
-
182
- end
183
-
184
- def prep_arg(str)
185
- str = str.upcase.gsub(/[^A-Z]/, '')
186
- words = []
187
- while str.length > 0
188
- words << str[0...5]
189
- str[0...5] = ''
190
- end
191
-
192
- last_len = words[words.length-1].length
193
- words[words.length-1] += ('X' * (5 - last_len)) if last_len < 5
194
- words.join(' ')
195
- end
196
-
197
- if __FILE__ == $0
198
- if ARGV[0]
199
- puts CryptKeeper.new(Deck.new.key).decrypt(prep_arg(ARGV[0]))
200
- else
201
- puts CryptKeeper.new(Deck.new.key).decrypt('CLEPK HHNIY CFPWH FDFEH')
202
- puts CryptKeeper.new(Deck.new.key).decrypt('ABVAW LWZSY OORYK DUPVH')
203
- end
204
- end
@@ -1,47 +0,0 @@
1
- #! /usr/bin/env ruby
2
-
3
- require 'test/unit.rb'
4
- require 'test/unit/ui/console/testrunner'
5
- require 'solitaire_cypher.rb'
6
-
7
- class SolitaireCypherTest < Test::Unit::TestCase
8
-
9
- KNOWN_PLAINTEXT = 'CODEI NRUBY LIVEL ONGER'
10
- KNOWN_CYPHER = 'GLNCQ MJAFF FVOMB JIYCB'
11
-
12
- def setup
13
- @deck = Deck.new.key
14
- @crypt_keeper = CryptKeeper.new(@deck)
15
- end
16
-
17
- def test_value_to_chr
18
- assert_equal('A', Card.value_to_chr(1))
19
- assert_equal('Z', Card.value_to_chr(26))
20
- end
21
-
22
- def test_chr_to_value
23
- assert_equal(1, Card.chr_to_value("A"))
24
- assert_equal(26, Card.chr_to_value("Z"))
25
- end
26
-
27
- def test_keystream
28
- expected = %w(D W J X H Y R F D G)
29
- deck = Deck.new.key
30
- expected.each { | exp |
31
- key = deck.next_keystream
32
- if exp != Card.value_to_chr(key)
33
- @errors << "expected #{exp}, key = #{Card.value_to_chr(key)}"
34
- end
35
- }
36
- end
37
-
38
- def test_decrypt_known_cypher
39
- assert_equal(KNOWN_PLAINTEXT, @crypt_keeper.decrypt(KNOWN_CYPHER))
40
- end
41
-
42
- def test_encrypt_known_message
43
- assert_equal(KNOWN_CYPHER, @crypt_keeper.encrypt(KNOWN_PLAINTEXT))
44
- end
45
- end
46
-
47
- Test::Unit::UI::Console::TestRunner.run(SolitaireCypherTest)