루덴스코드 Blog


자바 공부하시는 분들 참고하세요.

소수구하는 알고리즘을 이용한 클래스 강의 자료입니다.

이클립스에서 실행하세요.


///////////////////////////////////////////

// PrimeNumberMake.java

///////////////////////////////////////////


package com.javastudy.primesecure;

import java.util.Random;


public class PrimeNumberMake {

private long passwordElement1; 

private long passwordElement2; 

private long passMultiValue;


public PrimeNumberMake() {

Random randNum = new Random();

passwordElement1 = primeMake(1_234_567_890L+randNum.nextInt(100_000_000));

passwordElement2 = primeMake(2_345_678_901L+randNum.nextInt(100_000_000));

passMultiValue = passwordElement1 * passwordElement2;

}

public long getPasswordElement1() {

return passwordElement1;

}


public long getPasswordElement2() {

return passwordElement2;

}


public long getPassMultiValue() {

return passMultiValue;

}


public long primeMake(long startNumber) {

long i = startNumber;

boolean priNum = false;

while(!priNum) {

i++;

priNum = true;

if ((i%2==0)||(i%3==0)) priNum = false;

else {

for (int j=6; j<Math.sqrt(i); j=j+6) {

if((i%(j-1)==0)||(i%(j+1)==0)) { 

priNum=false; 

break;

}

}

}

}

return i;

}

}


///////////////////////////////////////////

// MainPrime.java

///////////////////////////////////////////


package com.javastudy.primesecure;


public class MainPrime {


public static void main(String[] args) {

PrimeNumberMake pswd = new PrimeNumberMake();

System.out.println("첫번째 소수값 : "+pswd.getPasswordElement1());

System.out.println("두번째 소수값 : "+pswd.getPasswordElement2());

System.out.println("두소수의 곱   : "+pswd.getPassMultiValue());

}

}



Comment +0