首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使cryptText字符与plainText字符相同?

如何使cryptText字符与plainText字符相同?
EN

Stack Overflow用户
提问于 2014-03-11 12:21:54
回答 1查看 79关注 0票数 0
代码语言:javascript
复制
package edu.secretcode;

import java.util.Scanner;

/**
 * Creates the secret code class.
 * 
 * @author
 * 
 */
public class SecretCode {
    /**
     * Perform the ROT13 operation
     * 
     * @param plainText
     *            the text to encode
     * @return the rot13'd encoding of plainText
     */

    public static String rotate13(String plainText) {
        StringBuffer cryptText = new StringBuffer("");
        for (int i = 0; i < plainText.length() - 1; i++) {
            char currentChar = plainText.charAt(i);
            currentChar = (char) ((char) (currentChar - 'A' + 13)% 26 + 'A');
            cryptText.append(currentChar);
        if (currentChar <= 'A' && currentChar >= 'Z'){
            cryptText.append(plainText);
        }

        }
        return cryptText.toString();

    }

    /**
     * Main method of the SecretCode class
     * 
     * @param args
     */
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while (1 > 0) {
            System.out.println("Enter plain text to encode, or QUIT to end");
            Scanner keyboard = new Scanner(System.in);
            String plainText = keyboard.nextLine();
            if (plainText.equals("QUIT")) {
                break;
            }
            String cryptText = SecretCode.rotate13(plainText);
            String encodedText = SecretCode.rotate13(plainText);

            System.out.println("Encoded Text: " + encodedText);
        }

    }

}

在静态字符串rotate13方法和if语句中,如果字符小于'A‘或大于'Z',则使cryptText字符与plainText字符相同。我的问题是如何使cryptText字符与纯文本字符相同?我所拥有的是不起作用的,我完全被困在这上面了。任何建议都是非常感谢的。提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-11 12:31:40

你的情况是wrong..Change

代码语言:javascript
复制
if (currentChar <= 'A' && currentChar >= 'Z')

代码语言:javascript
复制
if (currentChar < 'A' || currentChar > 'Z')
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22325602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档