Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'jcode'
- module CRA
- def self.decrypt(str)
- $text = str
- $chars = {
- 'a' => 0,
- 'b' => 0,
- 'c' => 0,
- 'd' => 0,
- 'e' => 0,
- 'f' => 0,
- 'g' => 0,
- 'h' => 0,
- 'i' => 0,
- 'j' => 0,
- 'k' => 0,
- 'l' => 0,
- 'm' => 0,
- 'n' => 0,
- 'o' => 0,
- 'p' => 0,
- 'q' => 0,
- 'r' => 0,
- 's' => 0,
- 't' => 0,
- 'u' => 0,
- 'v' => 0,
- 'w' => 0,
- 'x' => 0,
- 'y' => 0,
- 'z' => 0,
- '_SPACE_' => 0
- }
- $text.each_char{|x|
- case x.to_s.downcase
- when 'a' then $chars['a'] = $chars['a'] += 1
- when 'b' then $chars['b'] = $chars['b'] += 1
- when 'c' then $chars['c'] = $chars['c'] += 1
- when 'd' then $chars['d'] = $chars['d'] += 1
- when 'e' then $chars['e'] = $chars['e'] += 1
- when 'f' then $chars['f'] = $chars['f'] += 1
- when 'g' then $chars['g'] = $chars['g'] += 1
- when 'h' then $chars['h'] = $chars['h'] += 1
- when 'i' then $chars['i'] = $chars['i'] += 1
- when 'j' then $chars['j'] = $chars['j'] += 1
- when 'k' then $chars['k'] = $chars['k'] += 1
- when 'l' then $chars['l'] = $chars['l'] += 1
- when 'm' then $chars['m'] = $chars['m'] += 1
- when 'n' then $chars['n'] = $chars['n'] += 1
- when 'o' then $chars['o'] = $chars['o'] += 1
- when 'p' then $chars['p'] = $chars['p'] += 1
- when 'q' then $chars['q'] = $chars['q'] += 1
- when 'r' then $chars['r'] = $chars['r'] += 1
- when 's' then $chars['s'] = $chars['s'] += 1
- when 't' then $chars['t'] = $chars['t'] += 1
- when 'u' then $chars['u'] = $chars['u'] += 1
- when 'v' then $chars['v'] = $chars['v'] += 1
- when 'w' then $chars['w'] = $chars['w'] += 1
- when 'x' then $chars['x'] = $chars['x'] += 1
- when 'y' then $chars['y'] = $chars['y'] += 1
- when 'z' then $chars['z'] = $chars['z'] += 1
- when ' ' then $chars['_SPACE_'] = $chars['_SPACE_'] += 1
- end
- }
- $sorted = {}
- $c = $chars.sort
- file = File.open('result.txt', 'wb')
- $c.each{|x,k|
- puts "#{x.upcase} => #{k}"
- file.write("#{x.upcase} => #{k}")
- file.write("\n")
- }
- file.close
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement