Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Euler problem #...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 4025 of 4173
Post > Topic >>

Euler problem #59

by William James <w_a_x_man@[EMAIL PROTECTED] > Apr 29, 2008 at 11:46 AM

Euler Project, problem 59
I simply tried each key, looking for one that produced
a plaintext in which 90% of the characters were letters
or spaces.

bytes = IO.read('cipher1.txt').scan(/\d+/).map{|s| s.to_i }

('aaa'..'zzz').each do |key|
  key_bytes = key.split('').map{|s| s[0]}
  key_bytes *= (bytes.size + 2) / key_bytes.size
  plain_bytes = bytes.zip( key_bytes ).map{|a,b| a ^ b }
  if plain_bytes.min >= 32 and plain_bytes.max < 127
    text = plain_bytes.map{|n| n.chr}.join
    if text.gsub(/[^a-z ]/i, "").size > bytes.size * 0.9
      puts text
      puts key
      puts plain_bytes.inject{|sum,n| sum + n }
    end
  end
end
 




 2 Posts in Topic:
Euler problem #59
William James <w_a_x_m  2008-04-29 11:46:54 
Re: Euler problem #59
William James <w_a_x_m  2008-05-01 08:17:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:21:34 CDT 2008.