Last active
May 5, 2022 08:35
-
-
Save akinazuki/7e7fd30ea00f13cbab9b70f650dbfedf 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.util.Base64; | |
class Main { | |
public static String key = "Encrypt"; | |
public static void main(String[] args) { | |
if (args[0].equals("decrypt")) { | |
System.out.println(decrypt(args[1]));; | |
}else{ | |
System.out.println(encrypt(args[1])); | |
} | |
} | |
public static String decrypt(String s) { | |
byte[] decode = Base64.getDecoder().decode(s); | |
String str2; | |
int length = decode.length; | |
int length2 = key.length(); | |
int i = 0; | |
int i2 = 0; | |
while (true) { | |
int i3 = i2; | |
if (i >= length) { | |
break; | |
} | |
int i4 = i3; | |
if (i3 >= length2) { | |
i4 = 0; | |
} | |
decode[i] = (byte) (decode[i] ^ key.charAt(i4)); | |
i++; | |
i2 = i4 + 1; | |
} | |
str2 = new String(decode); | |
return str2; | |
} | |
public static String encrypt(String str_enc) { | |
byte[] s = str_enc.getBytes(); | |
int length = str_enc.length(); | |
int length2 = key.length(); | |
int i = 0; | |
int i2 = 0; | |
while (true) { | |
int i3 = i2; | |
if (i >= length) { | |
break; | |
} | |
int i4 = i3; | |
if (i3 >= length2) { | |
i4 = 0; | |
} | |
s[i] = (byte) (s[i] ^ key.charAt(i4)); | |
i++; | |
i2 = i4 + 1; | |
} | |
return Base64.getEncoder().encodeToString(s); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment