因此,我有一個值作爲整數從類返回,並根據輸入的文本的長度多次完成。我可以打印出每個字符的輸出,但我想將輸出合併爲一個字符串。這是輸出的一個例子。將int值插入字符串而不重新分配原始字符串值
輸入明文:喜
H的vaule是7
加密值721的解密值是7
的我的vaule是8
加密值爲330解密值爲8
我希望它打印出最終密文爲"721330"
,以便它將它發送到數據庫並將該值與數據庫中的值存儲進行比較。
這樣做的最好方法是什麼?
@SuppressWarnings(「資源」) 公共靜態無效的主要(字串[] args){
int p = 29;
int q = 41;
int d = 83;
int n = 0;
int w = 0;
int e=27;
int c =1;
String plainText;
String Str = new String("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
//System.out.println(m);
n = p*q;
//System.out.println("The n value equals " + n);
w = (p-1)*(q-1);
//System.out.println("The w value equals " + w);
int qo=0;
int re=0;
w = w*1+d*0;
d = w*0+d*1;
qo = w/d;
//System.out.println("quotient value " + qo);
re = w-qo*d;
//System.out.println("reminder value " + re);
qo=d/re;
//System.out.println("quotient value " + qo);
re = d-qo*re;
//System.out.println("reminder value " + re);
Scanner scn=new Scanner(System.in);
System.out.println("Enter plain-text:");
plainText=scn.nextLine();
plainText=plainText.toUpperCase();
char[] chars = plainText.toCharArray();
for (int i=0;i<chars.length;i++)
{
int m= Str.indexOf(chars[i]);
System.out.println("The value of " +chars[i] + " is " + m +"\n");
toBin(e);
//System.out.println("The binary value of e " + toBin(e));
de_encryption(c,n,m,toBin(e));
int C = de_encryption(c,n,m,toBin(e));
//String final_output = String.valueOf(C);
StringBuilder sb = new StringBuilder();
int part = C;
sb.append(part);
String result = sb.toString();
//I want the final_output value to be appended into a stringbuilder
System.out.println("The encrypted value is " + result);
toBin(d);
//System.out.println("The binary value of d " + toBin(d));
int D = de_encryption(c,n,C,toBin(d));
StringBuilder sb1 = new StringBuilder();
int part1 = D;
sb1.append(part1);
String result1 = sb1.toString();
System.out.println("The decrypted value is "+ result1 +"\n");
}
}
你不需要包裝一個字符串用另一個字符串。 –