文字列内の各文字間にランダムな文字列を生成する方法は?

exionoblivion:

私はインターフェイスを実装する必要があり、コードを持っている、と目的は次のように文字列を取ることですmycookisredし、その中で、元の単語からそれぞれの間のランダムな文字列を挿入します。つまり、この場合には、例えばを妨げる可能性がmeynciovoksidswrbendn別の例は、完全性のために:mycleverpassword文字列がなる可能性がありますmxyschlmezvievrppeaysisvwcoorydc

私は私のコードは、その目的のために、正確に右ではないですけど、缶誰かが助けを喜ばか、この開始点から何をすべきかに私を導きますか?

   import java.util.Random;

  public class password implements Encryptable
{
    private String message;
    private boolean encrypted;
    private int shift;
    private Random generator;

    public password(String msg)
    {
        message = msg;
        encrypted = false;
        generator = new Random();
        shift = generator.nextInt(10) + 5;
    }
    public void encrypt()
    {
        if (!encrypted)
        {
            String masked = "";
            for ( int index = 0; index < message.length(); index++)
            masked = masked + (char)(message.charAt(index) +shift);
            message = masked;
            encrypted = true;
        }
    }
    public String decrypt()
    {
        if (!encrypted)
        {
            String unmasked = "";
            for ( int index = 0; index < message.length(); index++)
            unmasked = unmasked + (char)(message.charAt(index) - shift);
            message = unmasked;
            encrypted = false;
        }
        return message;
    }
    public boolean isEncrypted()
    {
        return encrypted;
    }
    public String toString()
    {
        return message;
    }

}
public class passwordTest
{
  public static void main(String[] args)
  {
      password hide = new password("my clever password");
      System.out.println(hide);

      hide.encrypt();
      System.out.println(hide);

      hide.decrypt();
      System.out.println(hide);
  }


}


public interface Encryptable
{
    public void encrypt();
    public String decrypt();
}
ILikeSahne:

単なる文字列をランダム化し、正規化するためにこれを使用します。

private String randomize(String s) {
    String re = "";
    int len = s.length();
    for(int i = 0; i < len - 1; i++) {
        char c = s.charAt(i);
        re += c;
        re += (char) (generator.nextInt('z' - 'a') + 'a');
    }
    re += s.charAt(len - 1);
    return re;
}

private String normalize(String s) {
    String re = "";
    for(int i = 0; i < s.length(); i+=2) {
        re += s.charAt(i);
    }
    return re;
}

そして、クラスは大文字で始める必要があります。あなたはする必要はありませんが、例えばEclipseは泣くでしょう。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=230673&siteId=1