Cipher

in #ita4 months ago

class AtbashCipher {

static String plain =  "abcdefghijklmnopqrstuvwxyz"
static String cipher = "zyxwvutsrqponmlkjihgfedcba"


static String encode(phrase) {
    String res = ""
    int k = 0
    phrase = phrase.toLowerCase()
    for(char lett : phrase.toCharArray()){
        if(Character.isDigit(lett)){
            res += String.valueOf(lett)
            k++
            if(k==5){
                res += " "
                k=0
            }    
        }
        else if (!Character.isLetterOrDigit(lett)|| Character.isWhitespace(lett)){
            continue
        }
        else{
             int ind = plain.indexOf(lett.toString())
             res += String.valueOf(cipher[ind])
             k++
             if(k==5){
                    res += " "
                    k=0
            } 
        }
    }
    
    return res.trim()
}

static String decode(phrase) {
    return encode(phrase).replace(" ", "")
}

}

Sort:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)

The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.