Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使我的编码/解码器仅使用某些ASCII字符_Java_Encoding_Decode_Encode - Fatal编程技术网

Java 如何使我的编码/解码器仅使用某些ASCII字符

Java 如何使我的编码/解码器仅使用某些ASCII字符,java,encoding,decode,encode,Java,Encoding,Decode,Encode,做一个项目,我需要对我输入的密码进行编码和解码。我的问题是,如何使我的编码/解码器只使用ASCII字符33-122 我会把我的代码放进去,但我不认为这有多大区别 import java.util.Scanner; 公共类密码 { 公共静态void main(字符串[]args) { 扫描仪kb=新扫描仪(System.in); 扫描仪kb1=新扫描仪(System.in); 字符串密码; 字符串加密密码; int加密编号; int密码长度; 查尔·塞弗; 查尔·德西弗; System.out.

做一个项目,我需要对我输入的密码进行编码和解码。我的问题是,如何使我的编码/解码器只使用ASCII字符33-122

我会把我的代码放进去,但我不认为这有多大区别

import java.util.Scanner;
公共类密码
{
公共静态void main(字符串[]args)
{
扫描仪kb=新扫描仪(System.in);
扫描仪kb1=新扫描仪(System.in);
字符串密码;
字符串加密密码;
int加密编号;
int密码长度;
查尔·塞弗;
查尔·德西弗;
System.out.println(“输入密码。必须为8个字符或更长”);
密码=kb.nextLine();
passwordLength=password.length();
while(密码长度<8)
{
如果(密码长度>=8)
{
打破
}
其他的
{
System.out.println(“您的密码当前为“+passwordLength+”个字符,密码至少需要8个字符”);
密码=kb.nextLine();
passwordLength=password.length();
}
}
System.out.println(“您的密码是”+密码);
System.out.println(“选择一个介于1和10之间的encrpytion”);
encryptionNumber=kb.nextInt();
而(encryptionNumber<1 | | encryptionNumber>10)
{

如果(encryptionNumber>=1&&encryptionNumber有很多方法可以做到这一点。最好的方法是使用正则表达式来验证您的输入。阅读有关类的内容。更简单但不是有效的解决方案是遍历字符串中的每个字符并单独验证它。

有很多方法可以做到这一点。最好的方法是使用正则表达式表达式来验证您的输入。阅读有关类的内容。更简单但不是有效的解决方案是遍历字符串中的每个字符并单独验证它。

以下是我为使其正常工作所做的更改

import java.util.Scanner;
公共类密码
{
公共静态void main(字符串[]args)
{
扫描仪kb=新扫描仪(System.in);
扫描仪kb1=新扫描仪(System.in);
字符串密码;
字符串加密密码;
int加密编号;
int密码长度;
查尔·塞弗;
查尔·德西弗;
System.out.println(“输入密码。必须为8个字符或更长”);
密码=kb.nextLine();
//检查密码是否大于8个字符
passwordLength=password.length();
while(密码长度<8)
{
如果(密码长度>=8)
{
打破
}
其他的
{
System.out.println(“您的密码当前为“+passwordLength+”个字符,密码至少需要8个字符”);
密码=kb.nextLine();
passwordLength=password.length();
}
}
System.out.println(“您的密码是”+密码);
System.out.println(“选择一个介于1和10之间的encrpytion”);
encryptionNumber=kb.nextInt();
而(encryptionNumber<1 | | encryptionNumber>10)
{
如果(encryptionNumber>=1&&encryptionNumber 122)
{
密码=(char)((password.charAt(i)+encryptionNumber)-122)+32);
}
系统输出打印(密码);
}
System.out.println(“”);
//用于解密密码
System.out.println(“现在输入加密密码以便解密”);
encryptedPassword=kb1.nextLine();
for(int i=0;iif((encryptedPassword.charAt(i)-encryptionNumber)以下是我为使其正常工作所做的更改

import java.util.Scanner;
公共类密码
{
公共静态void main(字符串[]args)
{
扫描仪kb=新扫描仪(System.in);
扫描仪kb1=新扫描仪(System.in);
字符串密码;
字符串加密密码;
int加密编号;
int密码长度;
查尔·塞弗;
查尔·德西弗;
System.out.println(“输入密码。必须为8个字符或更长”);
密码=kb.nextLine();
//检查密码是否大于8个字符
passwordLength=password.length();
while(密码长度<8)
{
如果(密码长度>=8)
{
打破
}
其他的
{
System.out.println(“您的密码当前为“+passwordLength+”个字符,密码至少需要8个字符”);
密码=kb.nextLine();
passwordLength=password.length();
}
}
System.out.println(“您的密码是”+密码);
System.out.println(“选择一个介于1和10之间的encrpytion”);
encryptionNumber=kb.nextInt();
而(encryptionNumber<1 | | encryptionNumber>10)
{
如果(encryptionNumber>=1&&encryptionNumber 122)
{
密码=(char)((password.charAt(i)+encryptionNumber)-122)+32);
}
系统输出打印(密码);
}
System.out.println(“”);
//用于解密密码
System.out.println(“现在输入加密密码以便解密”);
encryptedPassword=kb1.nextLine();
for(int i=0;i如果((encryptedPassword.charAt(i)-encryptionNumber)将我的代码更改为此,现在就可以正常工作将我的代码更改为此,现在就可以正常工作