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;
}
그리고 클래스는 대문자 문자로 시작해야합니다. 당신은 필요하지 않지만, 예를 들어 이클립스는 울 것입니다.