Class: Crypto::HoleArea

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/crypto_helper.rb

Overview

HoleArea

Used to find 'holes' in a given according to a given keyword

cf. users.telenet.be/d.rijmenants/en/handciphers.htm

Used mainly by Cipher::DisruptedTransposition

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HoleArea) initialize(start_row, pos, xlen, len)

Returns a new instance of HoleArea



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/crypto_helper.rb', line 370

def initialize(start_row, pos, xlen, len)
  @a = Array.new
  @xlen = xlen.to_i
  @totalx = pos.to_i + xlen.to_i
  @totaly = (len.to_i / @totalx) + 1
  cpos = pos
  for j in start_row..(@totaly - 1) do
    for i in cpos..(pos + xlen - 1) do
      @a << [ j, i ] if (( (j * totalx) + i) < len)
    end
    # We shift by one to the right
    cpos += 1
  end
  @ylen = @a[-1][0] - start_row + 1
  @cf = (@a.size == (xlen * (xlen + 1)) / 2)
end

Instance Attribute Details

- (Object) a (readonly)

Returns the value of attribute a



368
369
370
# File 'lib/crypto_helper.rb', line 368

def a
  @a
end

- (Object) len (readonly)

Returns the value of attribute len



368
369
370
# File 'lib/crypto_helper.rb', line 368

def len
  @len
end

- (Object) totalx (readonly)

Returns the value of attribute totalx



368
369
370
# File 'lib/crypto_helper.rb', line 368

def totalx
  @totalx
end

- (Object) xlen (readonly)

Returns the value of attribute xlen



368
369
370
# File 'lib/crypto_helper.rb', line 368

def xlen
  @xlen
end

- (Object) ylen (readonly)

Returns the value of attribute ylen



368
369
370
# File 'lib/crypto_helper.rb', line 368

def ylen
  @ylen
end

Instance Method Details

- (Boolean) complete?

complete?

Flag testing whether the area is complete or not (i.e. is a full triangle)

Returns:

  • (Boolean)


402
403
404
# File 'lib/crypto_helper.rb', line 402

def complete?
  @cf
end

- (Object) each

each

Needed for every Enumerable



391
392
393
394
395
# File 'lib/crypto_helper.rb', line 391

def each
  @a.each do |c|
    yield c
  end
end