Skip to content

Instantly share code, notes, and snippets.

@scmanjarrez
Created March 20, 2016 18:24
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 scmanjarrez/cbfa6900349c090fcaec to your computer and use it in GitHub Desktop.
Save scmanjarrez/cbfa6900349c090fcaec to your computer and use it in GitHub Desktop.
Decode/decypher MEGA mega://enc? links
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mega Decrypter</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css">
</head>
<body>
<div class="header">
<h1>Mega Decrypter</h1>
<h2>Deciphers mega://enc? links</h2>
</div>
<input type="text" style="width:1000px" onchange="decryptURL(this.value)" placeholder="Paste link here and press enter">
<div id="result"></div>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
<script>
var decryptURL = function(url) {
// mega://enc?sjh3hoftyW8m5MmJDKW1c4TApgdMHLa2t7vtGQnag8VhGElc7r2JMrOdLqX0qpGR-MIqFh0jjxR0-NlAKxAuTQ
var urlpatterns = {
megadownloaderapp: {
regexp: new RegExp("mega://enc\\?([A-Za-z0-9-_,]+)", 'i'),
process: megadownloaderappDecrypt
}
};
for (pattern in urlpatterns) {
var match = urlpatterns[pattern].regexp.exec(url);
if (match != null) {
document.getElementById("result").innerHTML = urlpatterns[pattern].process(match[1]);
break;
}
}
};
var megadownloaderappDecrypt = function(str) {
// Password is "k1o6Al-1kz¿!z05y", but System.Text.Encoding.ASCII.GetBytes in VB.NET replaces 8-bit characters with '?'
var password = "k1o6Al-1kz?!z05y";
// IV = {121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62}
var iv = CryptoJS.enc.Hex.parse("79F10A01844A0B27FF5B2D4E0ED3163E");
while (password.length < 32) { password += "X"; } // 256 bit password padding
// Recover Base64 from encoded string
var b64str = str;
b64str += "==".substring((2 - b64str.length * 3) & 3);
b64str = b64str.replace(new RegExp("-", 'g'), "+").replace(new RegExp("_", 'g'), "/").replace(new RegExp(",", 'g'), "");
// Decoding step
var encryptedText = CryptoJS.enc.Base64.parse(b64str);
var key = CryptoJS.enc.Utf8.parse(password);
var aes = CryptoJS.algo.AES.createDecryptor(key, {
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
iv: iv
});
var decrypted = aes.finalize(encryptedText);
// Helper function to convert hex to ASCII
var hex2ascii = function(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
// Return final URL
return 'https://mega.co.nz/#' + hex2ascii(decrypted.toString());
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment