Skip to content

Instantly share code, notes, and snippets.

@MrMohebi
Last active April 20, 2022 11:48
Show Gist options
  • Save MrMohebi/e03f54fce9c8759dc93a05dd05f1925d to your computer and use it in GitHub Desktop.
Save MrMohebi/e03f54fce9c8759dc93a05dd05f1925d to your computer and use it in GitHub Desktop.
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
class HelloWorld {
public static void main(String[] args) {
String xOctals = "\\151\\152\\153\\226";
System.out.println(xOctals);
String[] xOctalsArr = xOctals.split("\\\\");
StringBuilder convertedOctals = new StringBuilder();
for (int i = 1; i < xOctalsArr.length; i++) {
String octal = xOctalsArr[i];
convertedOctals.append((char) Integer.parseInt(octal, 8));
}
String pass = convertedOctals.toString();
byte[] bytesPass = new byte[pass.length()];
for (int i = 0; i < pass.length(); i++) {
bytesPass[i] = (byte) pass.charAt(i);
}
System.out.println(md5Binery(bytesPass));
}
public static String md5Binery(final byte[] s) {
final String MD5 = "MD5";
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest
.getInstance(MD5);
digest.update(s);
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuilder hexString = new StringBuilder();
for (byte aMessageDigest : messageDigest) {
String h = Integer.toHexString(0xFF & aMessageDigest);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment