以下代码旨在根据ASCII
“秘密”值解密message :mmZ\\dxZmx]Zpgy
它应该打印出的内容是:“黎明时进攻!”
它当前显示的内容是:“在007F黎明时攻击007F?”
所以基本上,现在x = "007F"
和y = "?"
我需要x = SPACE
“”,并且y = "!"
谢谢你的时间。
public class decryption
{
public static void main(String[] args)
{
String secretMessage = ":mmZ\\dxZmx]Zpgy";
System.out.println(decryption(secretMessage, 88));
}//end main
public static String decryption(String s, int n)
{
int originalChar, decryptedChar;
String message = "";
char c;
for(int i = 0; i < s.length(); ++i)
{
c = s.charAt(i);
decryptedChar = (int)c;
if(decryptedChar + n > 126)
originalChar = 32 + ((decryptedChar + n) - 113);
else
{originalChar = decryptedChar + n;
c = c;}
message = message + (char)originalChar;
}//end for loop
return message;
}//end method
}//end class
我修好了它。问题在于ASCII值> 126是不正确的,因此简单地减去95就可以解决解密问题!
public class decryption
{
public static void main(String[] args)
{
String secretMessage = ":mmZ\\dxZmx]Zpgy";
System.out.println(decryption(secretMessage, 88));
}//end main
public static String decryption(String s, int n)
{
int originalChar, decryptedChar;
String message = "";
char c;
for(int i = 0; i < s.length(); ++i)
{
c = s.charAt(i);
decryptedChar = (int)c;
if(decryptedChar + n > 126)
originalChar = 32 + ((decryptedChar + n) - 113);
else
{originalChar = decryptedChar + n;
c = c;}
if (originalChar > 126)
originalChar = originalChar - 95;
message = message + (char)originalChar;
}//end for loop
return message;
}//end method
}//end class
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句