Sha256: 8357a3e15854fe9b02c68bfa2ff3fa0e02747a9ac70dbec781625584f052be04
Contents?: true
Size: 721 Bytes
Versions: 267
Compression:
Stored size: 721 Bytes
Contents
class Crypto def initialize(plaintext) @plaintext = plaintext end def normalize_plaintext @normalized ||= @plaintext.downcase.gsub(/\W/, '') end def plaintext_segments normalize_plaintext.chars. each_slice(size). map{ |s| s.join('') }. to_a end def size Math.sqrt(normalize_plaintext.length).ceil end def ciphertext transposed.join('') end def normalize_ciphertext transposed.join(' ') end private def transposed chunk_size = size chunks = plaintext_segments.map do |s| Array.new(chunk_size) { |i| s[i] or '' } end chunks.transpose.map{ |s| s.join('') } end end
Version data entries
267 entries across 267 versions & 1 rubygems