Skip to content

Instantly share code, notes, and snippets.

@perillamint
Created September 23, 2013 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perillamint/6673796 to your computer and use it in GitHub Desktop.
Save perillamint/6673796 to your computer and use it in GitHub Desktop.
욕먹을 사이퍼 코드
import java.util.Scanner;
public class Cipher {
private static char key[] = {
0x21, 0x40, 0x23, 0x24, 0x25, 0x5e, 0x26, 0x2a, 0x28, 0x29, 0x5f, 0x2d,
0x2b, 0x3d, 0x7c, 0x5c, 0x60, 0x7e, 0x7d, 0x7b, 0x5b, 0x5d, 0x27, 0x22,
0x3b, 0x3a, 0x3e, 0x3c, 0x3f, 0x2f, 0x71, 0x77, 0x65, 0x72, 0x74, 0x79,
0x0a
};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i;
System.out.println("Input 1 to encrypt or 2 to decrypt");
int mode = scanner.nextInt();
scanner.nextLine();
String plaintext, ciphertext;
switch (mode)
{
case 1:
System.out.println("Input plaintext");
plaintext = scanner.nextLine();
ciphertext = "";
for(i=0; i<plaintext.length(); i++)
{
ciphertext += key[plaintext.charAt(i) - 'a'];
}
System.out.println(ciphertext);
break;
case 2:
System.out.println("Input ciphertext");
ciphertext = scanner.nextLine();
plaintext = "";
for(i=0; i<ciphertext.length(); i++)
{
plaintext += decipher(ciphertext.charAt(i));
}
System.out.println(plaintext);
}
scanner.close();
}
public static char decipher(char cipher)
{
int i;
for(i=0; i<key.length; i++)
{
if(key[i] == cipher)
{
return (char)(i+'a');
}
}
return 0x00;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment