【发布时间】:2016-12-20 19:55:32
【问题描述】:
我想制作一个根据文本长度加密文本的程序。例如,如果单词是“test”,那么因为“test”有 4 个字母,它会将单词中的每个字母移动到下一个字母的第 4 个。这将使“测试”变为“xiwx”。我已经完成了我的程序的一部分。就是这样:
public static void main(String[] args){
string.toLowerCase();
int charPos = 0;
int length = 0;
for(int i = 0; i < string.length(); i++){
charPos = 0;
length = 0;
while(!(string.charAt(i) == ' ')){
length = charPos;
charPos++;
}
length--;
for(int j = 0; j<=length; j++){
char cha =string.charAt(i);
//HERE IS WHERE THE CHAR ADDING WILL HAPPEN
}
i++;
}
}//end
【问题讨论】:
-
你可以做
char shifted = cha + 3。需要小心从 Z 滚回 A。 -
你有什么问题?
-
@Thilo 我该如何使用它?
-
查看其他“凯撒密码”代码,例如stackoverflow.com/questions/30007467/caesar-cipher-java 可以看到,可以使用
c + 4“添加四个字母”。 -
我知道你可以只做(字母)+长度。但是现在它将显示为该字母的 ascii 数字...
标签: java encryption char string-length