Module: ComicWalker::ItemDecoder::Unknown

Defined in:
lib/comic_walker/item_decoder/unknown.rb

Class Method Summary collapse

Class Method Details

.calcPositionWithRest_(a, f, b, e) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)
  • e (Integer)

Returns:

  • (Integer)


126
127
128
# File 'lib/comic_walker/item_decoder/unknown.rb', line 126

def calcPositionWithRest_(a, f, b, e)
  a * e + (a >= f ? b : 0)
end

.calculate_moves(width, height, rect_width, rect_height, pattern) ⇒ Array<Hash>

Calculate moves.

Parameters:

  • width (Integer)

    Width of the image

  • height (Integer)

    Height of the image

  • rect_width (Integer)

    Width of the sub-image

  • rect_height (Integer)

    Height of the sub-image

  • pattern (Integer)

    pattern? integer ranging from 1 to 4

Returns:

  • (Array<Hash>)

    List of hash that represents a move



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/comic_walker/item_decoder/unknown.rb', line 56

def calculate_moves(width, height, rect_width, rect_height, pattern)
  wcnt = width / rect_width
  hcnt = height / rect_height
  width %= rect_width
  height %= rect_height
  moves = []
  w_t0 = wcnt - (43*pattern)%wcnt
  w_t1 =
    if w_t0 % wcnt == 0
      (wcnt - 4) % wcnt
    else
      w_t0
    end
  h_t0 = hcnt - 47 * pattern % hcnt;
  h_t1 =
    if h_t0 % hcnt == 0
      (hcnt - 4) % hcnt
    else
      h_t0;
    end

  if width > 0 && height > 0
    x = w_t1 * rect_width
    y = h_t1 * rect_height
    moves.push(srcX: x, srcY: y, destX: x, destY: y, width: width, height: height)
  end

  if height > 0
    wcnt.times do |j|
      l = calcXCoordinateXRest_(j, wcnt, pattern)
      k = calcYCoordinateXRest_(l, w_t1, h_t1, hcnt, pattern)
      destX = calcPositionWithRest_(l, w_t1, width, rect_width)
      destY = k * rect_height
      srcX = calcPositionWithRest_(j, w_t1, width, rect_width)
      srcY = h_t1 * rect_height
      moves.push(srcX: srcX, srcY: srcY, destX: destX, destY: destY, width: rect_width, height: height)
    end
  end
  if width > 0
    hcnt.times do |i|
      k = calcYCoordinateYRest_(i, hcnt, pattern)
      l = calcXCoordinateYRest_(k, w_t1, h_t1, wcnt, pattern)
      destX = l * rect_width
      destY = calcPositionWithRest_(k, h_t1, height, rect_height)
      srcX = w_t1 * rect_width
      srcY = calcPositionWithRest_(i, h_t1, height, rect_height)
      moves.push(srcX: srcX, srcY: srcY, destX: destX, destY: destY, width: width, height: rect_height)
    end
  end
  wcnt.times do |j|
    hcnt.times do |i|
      p = (j + 29 * pattern + 31 * i) % wcnt
      k = (i + 37 * pattern + 41 * p) % hcnt
      q = p >= calcXCoordinateYRest_(k, w_t1, h_t1, wcnt, pattern) ? width : 0
      m = k >= calcYCoordinateXRest_(p, w_t1, h_t1, hcnt, pattern) ? height : 0
      destX = p * rect_width + q
      destY = k * rect_height + m
      srcX = j * rect_width + (j >= w_t1 ? width : 0)
      srcY = i * rect_height + (i >= h_t1 ? height : 0)
      moves.push(srcX: srcX, srcY: srcY, destX: destX, destY: destY, width: rect_width, height: rect_height)
    end
  end
  moves
end

.calcXCoordinateXRest_(a, f, b) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)

Returns:

  • (Integer)


134
135
136
# File 'lib/comic_walker/item_decoder/unknown.rb', line 134

def calcXCoordinateXRest_(a, f, b)
  (a + 61 * b) % f
end

.calcXCoordinateYRest_(a, f, b, e, d) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)
  • e (Integer)
  • d (Integer)

Returns:

  • (Integer)


162
163
164
165
166
167
168
169
170
171
172
# File 'lib/comic_walker/item_decoder/unknown.rb', line 162

def calcXCoordinateYRest_(a, f, b, e, d)
  c = 1 == d % 2
  if a < b ? c : !c
    e -= f
    b = f
  else
    e = f
    b = 0
  end
  (a + 67*d + f + 71) % e + b
end

.calcYCoordinateXRest_(a, f, b, e, d) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)
  • e (Integer)
  • d (Integer)

Returns:

  • (Integer)


144
145
146
147
148
149
150
151
152
153
154
# File 'lib/comic_walker/item_decoder/unknown.rb', line 144

def calcYCoordinateXRest_(a, f, b, e, d)
  c = 1 == d % 2
  if a < f ? c : !c
    e = b
    f = 0
  else
    e -= b
    f = b
  end
  (a + 53*d + 59*b) % e + f
end

.calcYCoordinateYRest_(a, f, b) ⇒ Integer

Parameters:

  • a (Integer)
  • f (Integer)
  • b (Integer)

Returns:

  • (Integer)


178
179
180
# File 'lib/comic_walker/item_decoder/unknown.rb', line 178

def calcYCoordinateYRest_(a, f, b)
  (a + 73*b) % f
end

.decrypt(key, bsize, data) ⇒ Array<Fixnum>

Returns Chunked decrypted data.

Parameters:

  • key (Array<Fixnum>)
  • bsize (Integer)

    block size?

  • data (Array<Fixnum>)

    Encrypted data

Returns:

  • (Array<Fixnum>)

    Chunked decrypted data



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/comic_walker/item_decoder/unknown.rb', line 22

def decrypt(key, bsize, data)
  s = []
  0.step(data.size-1, bsize) do |i|
    s << data[i]
  end

  c = Cipher.decrypt_rc4(key, s)
  # s.size == c.size

  0.step(data.size-1, bsize) do |i|
    data[i] = c.shift
  end
  data
end

.finish(key, hsize, data) ⇒ Array<Fixnum>

Returns data.

Parameters:

  • key (Array<Fixnum>)
  • hsize (Integer)

    header size?

  • data (Array<Fixnum>)

    Encrypted data

Returns:

  • (Array<Fixnum>)

    data



41
42
43
44
45
46
47
# File 'lib/comic_walker/item_decoder/unknown.rb', line 41

def finish(key, hsize, data)
  hsize = [hsize, data.size].min
  Cipher.decrypt_rc4(key, data.slice(0, hsize)).each.with_index do |x, i|
    data[i] = x
  end
  data
end

.prepare(key, data) ⇒ Array<Fixnum>

Parameters:

  • key (Array<Fixnum>)
  • data (Array<Fixnum>)

    Encrypted data

Returns:

  • (Array<Fixnum>)


11
12
13
14
15
16
# File 'lib/comic_walker/item_decoder/unknown.rb', line 11

def prepare(key, data)
  s = Cipher.gen_rc4_table(key)
  data.map.with_index do |b, i|
    b ^ s[i % 256]
  end
end