小妹的作业,总算做出,但是好像算法很烂...
public class task2_2 {
final static int FirstPrintableChar = 32;    //the first character is " "
final static int NumPrintableChars = 95;  //the Num of characters

public static String createKey() {
     String key="";
for (int i=0; i<95; i++){
int  seed = (int)(Math.random()*95);
int temp=seed+32;
while (key.indexOf((char)temp)>-1){
    temp=(temp+1)%95+32;
}

key=key+(char)temp;
}
        return key;
} public static void main(String[] args)
{// char []key;
String key;
String sentence = "This is the sentence";
String encSentence; key = createKey();
System.out.print (key);
//encSentence = encrypt(sentence, key); }
}
作业要求:
1.从char(32) 到char(127)进行加密
2.random不能使用多于95次
3.加密后的key一定是无序
4.每个字母只能用一次小妹这里等待高人优化...