【发布时间】:2023-03-05 04:21:01
【问题描述】:
我本质上想反转加密来解密消息。谁能帮我创建代码来做到这一点?谢谢!!
/** * 加密和解密字符串 * @作者(安德鲁·格鲁伯) * @版本(2016 年 1 月 11 日) */
公共类逻辑
{
public static void main(String[] args){
//Encryption
String mm= "where is the moose that everyone is talking about";
final int nr=6; //number or rows
int nc; //number of columns
nc=mm.length()/nr;
if(mm.length()% nr !=0){
nc++;
}
while(mm.length()<nr*nc){ //insert spaces
mm+=" ";
}
String[][] ar=new String [nr][nc];
for(int i=0; i<mm.length(); i++){
//eaach character in the string is stored
ar[i%nr][i/nr]=mm.substring(i,i+1);
}
String outStr=""; //output string
for(int r=0; r<nr; r++){
for(int c=0; c<nc; c++){
outStr+=ar[r][c];
}
}
System.out.println(outStr);
//Decryption
String test=outStr;
Decyrption();
}
static void Decyrption(){
【问题讨论】:
-
“帮助你”我假设你的意思是“我们为你做”?
-
好吧,我真正需要的只是如何将其放回数组中并相应地将其重新排列回字符串中。我知道该怎么做,但我只需要一些帮助来编码。不,我不要求你做所有这一切。当然这会有所帮助,但我不会那样学得最好。谢谢! +redFive
标签: java arrays encryption