Skip to content

Instantly share code, notes, and snippets.

@JoeUnsung
Last active December 17, 2016 17:56
Show Gist options
  • Save JoeUnsung/55419abfaad92ed6c743cd4d740662f3 to your computer and use it in GitHub Desktop.
Save JoeUnsung/55419abfaad92ed6c743cd4d740662f3 to your computer and use it in GitHub Desktop.
Making string as a secret mode
import java.util.*;
import java.lang.*;
class Main {
public static String reverseString(String s) {
return ( new StringBuffer(s) ).reverse().toString();
}
public static void main(String[] args) {
char listAlpha[] = new char[26];
int listInt[] = new int[26];
for(int i = 0 ; i < 26 ; i++){
listInt[i] = i;
}
String alpha = "abcdefghijklmnopqrstuvwxyz";
Scanner sc = new Scanner(System.in);
String temp1 = sc.next();
System.out.println("입력한 단어 : " + temp1);
//정방향으로 입력받은 단어의 번호를 구하기
String word = "";
for(int i = 0 ; i < temp1.length() ; i++){
word += alpha.indexOf(temp1.charAt(i));
}
System.out.println(word);
System.out.println();
// 역방향으로 단어를 뒤집기
String temp2 = reverseString(temp1);
System.out.println("뒤집은 단어 : " + temp2);
String word2 = "";
for(int i = 0 ; i < temp2.length() ; i++){
word2 += alpha.indexOf(temp2.charAt(i));
}
System.out.println(word2);
System.out.println();
int temp3 = Integer.parseInt(word) + Integer.parseInt(word2);
String word3 = Integer.toString(temp3);
System.out.println("암호화된 숫자 : " + word3);
// 암호화된 숫자를 암호화된 문자로 변경
String final_word ="";
if (word3.length()%2 == 0){
for(int i = 0 ; i < word3.length() ; i += 2){
//System.out.println(word3.substring(i,i+2));
final_word += alpha.charAt(Integer.parseInt(word3.substring(i,i+2))%26);
}
}
else if(word3.length()%2 == 1){
for(int i = 0 ; i < word3.length()-1 ; i += 2){
//System.out.println(word3.substring(i,i+2));
final_word += alpha.charAt(Integer.parseInt(word3.substring(i,i+2))%26);
}
final_word += alpha.charAt(Integer.parseInt(word3.substring(word3.length()-1));
}
System.out.println();
System.out.println(final_word);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment