On Tue, 26 May 2009 13:45:45 +0900, Martin Boese wrote: > I was starting something like this. But it doesn't seem to work out: > > crypt = <<-ENDC > YRFFJ OSLXA PQPQY APVRR DPNSA ZAPIK > OXMQJ BOIMY XMSZZ FRIHE AUXJS IOROR > IEAHB QYAPQ YRHXJ STRIF ORIEX KOIKD > REAQK JHBOI QSFIQ AJHPA QPKIF FREKO > XMQJB OIGAA LRKIS PRNSA Z13VI PIKOX > MQJBO IGNSA ZIPVR FFYJM RXJSY IEUSH > ENDC > > ('A'[0]..'Z'[0]).each { |c| puts "#{c.chr} -> #{crypt.count(c.chr)}" } cipherside=('A'[0]..'Z'[0]).map { |c| crypt.count(c.chr) } > english = File.read('/usr/share/dict/words').upcase > > ('A'[0]..'Z'[0]).each { |c| puts "#{c.chr} ->#{english.count(c.chr)}" } englishside = ('A'[0]..'Z'[0]).map { |c| english.count(c.chr) } class Array def rotate num self[num..-1]+self[0...num] end end (0...26).each do |rot| dotprod=cipherside.zip(englishside.rotate(rot)).inject(0) do |a,(b,c)| a+b*c end printf "%d -> %d\n", rot, dotprod end 0 -> 6418143 1 -> 5568695 2 -> 5549352 3 -> 6915018 4 -> 6262198 5 -> 5279474 6 -> 4898071 7 -> 4508113 8 -> 5015397 9 -> 5761530 10 -> 6017183 11 -> 5443382 12 -> 5440166 13 -> 5944635 14 -> 5750203 15 -> 4540453 16 -> 5307004 17 -> 5184543 18 -> 5899138 19 -> 5232100 20 -> 5903220 21 -> 5759249 22 -> 6291068 23 -> 4976438 24 -> 4537099 25 -> 5448116 def decrypt msg, num msg.each_byte do |x| next if x>?Z or x<?A x+=num x-=26 if x>?Z x+=26 if x<?A print x.chr end puts end (0...26).each do |rot| decrypt crypt, rot puts end I'll let you run this to see the output, but clearly this isn't a rotation cipher. -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/