Created
September 21, 2013 20:49
-
-
Save ex/6654044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Decrypt | |
text = "Uid nx, aex jcdjipx iu wzux zp, ta wxtpa jtdaws, ai etkx vis.\n" + | |
"Dcos zyexdzaxr aex Jxdw jezwipijes iu etkzyg nidx aety iyx hts\n" + | |
"ai ri aex ptnx aezyg. Z zyexdzaxr aeta jezwipijes udin Wtdds Htww,\n" + | |
"hei zp ns exdi tqactwws. Z htya ai ntfx Dcos cpxdp udxx. Z htya ai\n" + | |
"gzkx aexn aex udxxrin ai qeiipx. Jxijwx tdx rzuuxdxya. Jxijwx qeiipx\n" + | |
"rzuuxdxya qdzaxdzt. Oca zu aexdx zp t oxaaxd hts tniyg ntys\n" + | |
"twaxdytazkxp, Z htya ai xyqicdtgx aeta hts os ntfzyg za qinuidatowx.\n" + | |
"Pi aeta'p heta Z'kx adzxr ai ri.\n" + | |
"Z htya ai piwkx jdiowxnp Z nxxa zy aex rtzws wzux os cpzyg qinjcaxdp,\n" + | |
"pi Z yxxr ai hdzax jdigdtnp. Os cpzyg Dcos, Z htya ai qiyqxyadtax aex\n" + | |
"aezygp Z ri, yia aex ntgzqtw dcwxp iu aex wtygctgx, wzfx patdazyg hzae\n" + | |
"jcowzq kizr pinxaezyg pinxaezyg pinxaezyg ai pts, \"jdzya exwwi hidwr.\"\n" + | |
"Z vcpa htya ai pts, \"jdzya aezp!\" Z riy'a htya tww aex pcddicyrzyg\n" + | |
"ntgzq fxshidrp. Z vcpa htya ai qiyqxyadtax iy aex atpf. Aeta'p aex otpzq\n" + | |
"zrxt. Pi Z etkx adzxr ai ntfx Dcos qirx qiyqzpx tyr pcqqzyqa.\n" + | |
"Scfzezdi Ntapcniai. (hhh.tdaznt.qin/zyak/dcos)" | |
freqLang = "TEOIARNSHLMYUCWDGPFBVKJ" | |
len = text.length | |
frequency = Hash.new | |
for k in 0..(len - 1) | |
c = text[k, 1].upcase | |
if c =~ /[A-Z]/ | |
if frequency.has_key?(c) then frequency[c] = frequency[c] + 1 | |
else frequency[c] = 1 end | |
end | |
end | |
dic = Hash.new | |
freqText = "" | |
index = 0 | |
frequency.sort{ |a,b| b[1]<=>a[1] }.collect{ |a| | |
#puts(a[0] + " - " + a[1].to_s) | |
freqText += a[0] | |
dic[a[0].upcase] = freqLang[index, 1] | |
index += 1 | |
} | |
puts(freqLang) | |
puts(freqText) | |
decrypted = ""; | |
len = text.length; | |
for k in 0..(len - 1) | |
uper = false | |
c = text[k, 1] | |
if c =~ /[A-Z]/ then uper = true | |
else c = c.upcase end | |
if dic.has_key?(c) | |
if uper then decrypted += dic[c] | |
else decrypted += dic[c].downcase end | |
else decrypted += c end | |
end | |
puts(decrypted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment