Java 如何为字母替换密码(groovy)创建编码器和解码器?

Java 如何为字母替换密码(groovy)创建编码器和解码器?,java,encoding,groovy,decoding,Java,Encoding,Groovy,Decoding,基本上,我必须在groovy上设计和实现它,这是为了编码和解码特定的段落?您可以查看这个 这显示了编解码器的典型用例 基本上类似于(从该链接) 您不会使用HtmlUtils,但其结构是相同的 编辑——下面是一个关于如何进行替换的示例。注意,这可能更为groovy,它不处理标点符号,但应该会有所帮助 def plainText = 'hello' def solutionChars = new char[plainText.size()] for (def i = 0; i < plain

基本上,我必须在groovy上设计和实现它,这是为了编码和解码特定的段落?

您可以查看这个

这显示了编解码器的典型用例

基本上类似于(从该链接)

您不会使用HtmlUtils,但其结构是相同的

编辑——下面是一个关于如何进行替换的示例。注意,这可能更为groovy,它不处理标点符号,但应该会有所帮助

def plainText = 'hello'
def solutionChars = new char[plainText.size()]
for (def i = 0; i < plainText.size(); i++){
        def currentChar = plainText.charAt(i)
        if (Character.isUpperCase(currentChar))
                solutionChars[i] = Character.toLowerCase(currentChar)
        else
                solutionChars[i] = Character.toUpperCase(currentChar)

}

def cipherText = new String(solutionChars)
println(solutionChars)

你对哪一部分有问题?基本上,我一直在启动代码,只是想要结构。@ben,那么我的答案是适用的。是的,如果它仍然给我带来问题,我会留下一篇帖子。只需重新搜索一些我一直坚持的东西,让abitOr更符合groovy:
“hello”。收集{c->Character.isUpperCase((Character)c)?c.toLowerCase():c.toUpperCase()}.join(“”)
;-)
def plainText = 'hello'
def solutionChars = new char[plainText.size()]
for (def i = 0; i < plainText.size(); i++){
        def currentChar = plainText.charAt(i)
        if (Character.isUpperCase(currentChar))
                solutionChars[i] = Character.toLowerCase(currentChar)
        else
                solutionChars[i] = Character.toUpperCase(currentChar)

}

def cipherText = new String(solutionChars)
println(solutionChars)
def plainText = 'hello'
def cipherText = ""
plainText.each {c ->
    if (Character.isUpperCase((Character)c))
        cipherText += c.toLowerCase()
    else
        cipherText += c.toUpperCase()
}

println(cipherText)