如何解决没有数组的凯撒移位加密?
我需要弄清楚如何加密消息,并且消息应该只是小写字母。我应该为我输入的每个字母增加3个字符。例如,如果其中一个字符为“ c”,则需要为“ f”。我什至不应该使用for循环,但是我不知道如何执行此操作。到目前为止,这是我的代码,
import javax.swing.JOptionPane;
final int KEY = 3;
String userInput;
String encryptedText;
String decryptedText;
void setup()
{
noLoop();
}
void draw()
{
userInput = JOptionPane.showInputDialog("Enter your favourite colour: ");
caesarEncrypt();
}
void caesarEncrypt()
{
for(int i = 0; i < userInput.length(); i++)
{
encryptedText = (userInput.charAt(i) + KEY) % 26;
}
println("You entered the plaintext: " + userInput);
println("and the ciphertext is: " + encryptedText);
}
void caesarDecrypt()
{
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。