Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Mateusz on 2017-10-19.
- */
- fun charToInt(a: Char): Int {
- return a.toInt() - 97;
- }
- fun intToChat(a: Int): Char {
- return a.toChar() + 97;
- }
- fun drawStars(n: Int): String {
- var result = ""
- val nStars = n * 100 / 64
- for (i in 0..nStars) {
- result += "*"
- }
- return result
- }
- fun main(args: Array<String>) {
- val tab = IntArray(26, { x -> 0 })
- var text: String = """eolqh pqqiv tbjym pgxms jracb dwfac jpzia uoxck lgjyt nwfvh pbjyc zglim lzpmb
- hhzgb kshiv jabaz ekpdz acasb uojtz oomvx dkpqb kotek laxsq zqahh vhplz nwfjn
- afayc kwmus lykuj nwqcr lzfgj ccuen xcxcz nbjya jzpvx awfem tscsr dhbfr tsqic
- pxstk tkzqn msden rctgx dzbwy pqjmh pgqly pqjqh lcotz dpzwl znfnd rcocd kfpvh
- ocqij tbjyt coacr kupln kybtd xdpjq ksaes zfztz xwbms mmdqk lrdur eomvx dgjyo
- lbfgh koncz dhlln wsntm tsouv traim jausq lbfgm tskyr ehpvn hwfgc zdsuv omqly
- jajis pamoc kwxsq znocz uodsb sgjyl pguqd xwxmo lbjuk zazmk yctwh lhfhj ecqly
- pguly pubtz doemo coxcd ozjqn dqjhh pdpqh ywfha lqtcd ywlif zapqh dwftd ddsuv
- tsefh hwocd zpbqh lxbmh pppaz kbbwy jhptd ywfjn efaya fxbmh pupvz ndphh pkbtr
- eosui lgjyf znbxn hcmcb toaxn vcowz hmqyk ywbdz ushio cnzez koocz"""
- text = text.replace(" ", "")
- text = text.replace("\n", "")
- println(text);
- println(text.length)
- for (k in 0..4) {
- println("Pozycja " + k)
- for (i in text.indices step 5) {
- var index = (i + k) % 640
- tab[charToInt(text[index])]++
- }
- for (i in tab.indices) {
- var index = (i + k) % 26
- println(intToChat(index) + " - " + tab[index] + " " + drawStars(tab[index]))
- }
- for (j in tab.indices) {
- tab[j] = 0;
- }
- }
- var powtorzenia: HashMap<String, ArrayList<Int>>
- var len = 4
- var i = 0
- var j = 1
- var word = ""
- while (i < text.length) {
- if (i + len < text.length) {
- word = text.substring(i, (i + len))
- } else {
- break
- }
- while (j < text.length) {
- var word2 = ""
- if ((j + len) < text.length) {
- word2 = text.substring(j, (j + len))
- } else {
- break
- }
- if (word.equals(word2) && i != j) {
- // if (powtorzenia.containsKey(word)) {
- // val indeksy = powtorzenia.get(word)
- // indeksy.add(j)
- // powtorzenia.replace(word, )
- //
- // }
- println(i.toString() + " " + word + ", " + j.toString() + " " + word2)
- }
- j++;
- }
- j = 0
- i++
- }
- var klucz = "lobuz"
- for (i in text.indices) {
- var odszyfrowane = intToChat((charToInt(text[i]) + charToInt(klucz[i % 5])) % 26)
- print(odszyfrowane)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement