Last active
January 1, 2024 13:27
-
-
Save potados99/4aa9bd41c6dc35329a80532e0c565bc1 to your computer and use it in GitHub Desktop.
표준ㅋ암호화ㅋㅋㅎ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.nio.charset.Charset; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.util.Base64; | |
class Scratch { | |
public static void main(String[] args) throws IOException { | |
String pathPrefix = "C:\\Users\\Administrator\\AppData\\Roaming\\Google\\AndroidStudio2023.1\\scratches"; | |
String filename = "20240101-123사4567-X-10-1234678.TXT"; | |
byte key = getKey(filename, Charset.forName("EUC-KR")); // 0x5A | |
System.out.printf("key: 0x%02X\n", key); | |
byte[] in = new String(Files.readAllBytes(Path.of(pathPrefix, "src.txt"))).replaceAll("\r\n", "").getBytes(Charset.forName("EUC-KR")); | |
byte[] out = encrypt(in, key); | |
Files.write(Path.of(pathPrefix, filename), out); | |
Files.write(Path.of(pathPrefix, "base64_" + filename), Base64.getEncoder().encode(out)); | |
} | |
public static byte getKey(String password, Charset charset) { | |
int acc = 0; | |
byte[] bytes = password.getBytes(charset); | |
for (byte aByte : bytes) { | |
acc += aByte & 255; | |
} | |
byte key = (byte) (acc & 255); | |
if (key == 0) { | |
key = 1; | |
} | |
return key; | |
} | |
public static byte[] encrypt(byte[] var1, byte var2) { | |
return a(var1, var2); | |
} | |
public static byte[] decrypt(byte[] var1, byte var2) { | |
return a(var1, var2); | |
} | |
public static byte[] a(byte[] in, byte key) { | |
int len; | |
byte[] out = new byte[len = in.length]; | |
for (int i = 0; i < len; ++i) { | |
out[i] = (byte) (in[i] ^ key); | |
} | |
return out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment