자바 간단한 암호화 방법
public class Encryption{
public String encryptionPassword(String strKey){
if(strKey==null||strKey.length()==0){
return "";
}
int iLen = strKey.length();
String strEncryption ="";
for(int iCnt=0;iCnt<iLen;iCnt++){
//암호화 (문자열의 짝수, 홀수 위치 구분)
if(iCnt%2==0){ //홀수문자
strEncryption += (char) ((byte) strKey.charAt(iCnt) - iLen + iCnt);
}else{//짝수문자
strEncryption += (char) ((byte) strKey.charAt(iCnt) + iLen + iCnt);
}
}
return strEncryption;
}
public String decryptionPassword(String strKey){
if(strKey==null||strKey.length()==0){
return "";
}
int iLen = strKey.length();
String strDecryption ="";
for(int iCnt=0;iCnt<iLen;iCnt++){
//암호화 (문자열의 짝수, 홀수 위치 구분)
if(iCnt%2==0){ //홀수문자
strDecryption += (char) ((byte) strKey.charAt(iCnt) + iLen - iCnt);
}else{//짝수문자
strDecryption += (char) ((byte) strKey.charAt(iCnt) - iLen - iCnt);
}
}
return strDecryption;
}
public static void main(String[] args){
String key ="abc$%";
Encryption e = new Encryption();
System.out.println(key);
System.out.println(e.encryptionPassword(key));
System.out.println(e.decryptionPassword(e.encryptionPassword(key)));
}
}