문자열을 ASCII 값으로 변환 한 다음 다시 문자열이나 문자열로 해독하는 간단한 암호화 프로그램을 만들려고합니다. 무엇을 당신이하려는 것은 사실 (? 암호화 전) 인코딩 자바 문자열 (UTF-16 기준)의 ASCII에서 인 경우어떻게 문자열을 ASCII 값으로 변경하고 다시 문자열로 변경할 수 있습니까?
import java.io.*;
import javax.swing.*;
public class SimpleEncryption {
public static void main (String [] args) throws Exception
{
BufferedReader inKb = new BufferedReader (new InputStreamReader (System.in));
for(int i=0; i<10; i++)
{
String ans = JOptionPane.showInputDialog ("Hello User, would you like to encrypt or decrypt?");
ans = ans.toUpperCase();
int a = 0;
if (ans.contains("EN")||ans.contains("ENCRYPT"))
{
String pass = "";
pass = JOptionPane.showInputDialog ("Please type your phrase into input:");
for (int j=0; j<pass.length(); j++)
{
char c = pass.charAt(j);
a = (int) c;
System.out.print(a);
}
break;
}
if (ans.contains("DE")||ans.contains("DECRYPT"))
{
String pass = "";
pass = JOptionPane.showInputDialog ("Please type the encrypted code into input:");
for (int k=0; k<pass.length(); k++)
{
char c = pass.charAt(k);
a = (int)(c);
i = (char) a;
System.out.print(a);
}
break;
}
System.out.println("Sorry I don't understand, please retry.");
}
}
}
당신은 당신이하고 싶은 것을 말했고, 약간의 코드가 주어졌지만 실제 질문은 없습니다. ('char'에서'int' 로의 변환은 UTF-16 코드 단위의 유니 코드 값을 줄 것입니다 ... ASCII를 넘어서 생각하십시오.) –
무엇이 당신의 질문입니까? –
어떻게 사용자가 지정한 문자열을 ASCII 값 (암호화)으로 변경 한 다음 값 (예 : hello = 104101108108111)을 가져 와서 문자 (암호 해독)로 변경할 수 있습니까? – user1644257