Advertisement
Guest User

Krypto

a guest
Oct 23rd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.92 KB | None | 0 0
  1. /**
  2.  * Created by Mateusz on 2017-10-19.
  3.  */
  4.  
  5. fun charToInt(a: Char): Int {
  6.     return a.toInt() - 97;
  7. }
  8.  
  9. fun intToChat(a: Int): Char {
  10.     return a.toChar() + 97;
  11. }
  12.  
  13. fun drawStars(n: Int): String {
  14.     var result = ""
  15.     val nStars = n * 100 / 64
  16.     for (i in 0..nStars) {
  17.         result += "*"
  18.     }
  19.     return result
  20. }
  21.  
  22. fun main(args: Array<String>) {
  23.  
  24.     val tab = IntArray(26, { x -> 0 })
  25.     var text: String = """eolqh pqqiv tbjym pgxms jracb dwfac jpzia uoxck lgjyt nwfvh pbjyc zglim lzpmb
  26.    hhzgb kshiv jabaz ekpdz acasb uojtz oomvx dkpqb kotek laxsq zqahh vhplz nwfjn
  27.    afayc kwmus lykuj nwqcr lzfgj ccuen xcxcz nbjya jzpvx awfem tscsr dhbfr tsqic
  28.    pxstk tkzqn msden rctgx dzbwy pqjmh pgqly pqjqh lcotz dpzwl znfnd rcocd kfpvh
  29.    ocqij tbjyt coacr kupln kybtd xdpjq ksaes zfztz xwbms mmdqk lrdur eomvx dgjyo
  30.    lbfgh koncz dhlln wsntm tsouv traim jausq lbfgm tskyr ehpvn hwfgc zdsuv omqly
  31.    jajis pamoc kwxsq znocz uodsb sgjyl pguqd xwxmo lbjuk zazmk yctwh lhfhj ecqly
  32.    pguly pubtz doemo coxcd ozjqn dqjhh pdpqh ywfha lqtcd ywlif zapqh dwftd ddsuv
  33.    tsefh hwocd zpbqh lxbmh pppaz kbbwy jhptd ywfjn efaya fxbmh pupvz ndphh pkbtr
  34.    eosui lgjyf znbxn hcmcb toaxn vcowz hmqyk ywbdz ushio cnzez koocz"""
  35.  
  36.     text = text.replace(" ", "")
  37.     text = text.replace("\n", "")
  38.     println(text);
  39.     println(text.length)
  40.  
  41.     for (k in 0..4) {
  42.  
  43.         println("Pozycja " + k)
  44.  
  45.         for (i in text.indices step 5) {
  46.             var index = (i + k) % 640
  47.             tab[charToInt(text[index])]++
  48.         }
  49.         for (i in tab.indices) {
  50.             var index = (i + k) % 26
  51.             println(intToChat(index) + " - " + tab[index] + "  " + drawStars(tab[index]))
  52.         }
  53.         for (j in tab.indices) {
  54.  
  55.             tab[j] = 0;
  56.         }
  57.     }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     var powtorzenia: HashMap<String, ArrayList<Int>>
  64.     var len = 4
  65.     var i = 0
  66.     var j = 1
  67.     var word = ""
  68.     while (i < text.length) {
  69.         if (i + len < text.length) {
  70.  
  71.             word = text.substring(i, (i + len))
  72.         } else {
  73.             break
  74.         }
  75.         while (j < text.length) {
  76.  
  77.             var word2 = ""
  78.             if ((j + len) < text.length) {
  79.  
  80.                 word2 = text.substring(j, (j + len))
  81.             } else {
  82.                 break
  83.             }
  84.  
  85.             if (word.equals(word2) && i != j) {
  86. //                if (powtorzenia.containsKey(word)) {
  87. //                    val indeksy = powtorzenia.get(word)
  88. //                    indeksy.add(j)
  89. //                    powtorzenia.replace(word, )
  90. //
  91. //                }
  92.                 println(i.toString() + " " + word + ", " + j.toString() + " " + word2)
  93.             }
  94.             j++;
  95.         }
  96.         j = 0
  97.         i++
  98.     }
  99.  
  100.     var klucz = "lobuz"
  101.  
  102.     for (i in text.indices) {
  103.         var odszyfrowane = intToChat((charToInt(text[i]) + charToInt(klucz[i % 5])) % 26)
  104.         print(odszyfrowane)
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement