Skip to content

Instantly share code, notes, and snippets.

@jnovack
Last active July 20, 2021 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnovack/72b40da1005a97c5677533d59c73dbac to your computer and use it in GitHub Desktop.
Save jnovack/72b40da1005a97c5677533d59c73dbac to your computer and use it in GitHub Desktop.
Javascript function() to decrypt Type 7 passwords from Cisco
function crackPassword(password) {
var crypttext = password.toUpperCase();
var plaintext = '';
var xlate = "dsfd;kfoA,.iyewrkldJKDHSUBsgvca69834ncxv9873254k;fg87";
var seed, i, val = 0;
if(crypttext.length & 1)
return;
seed = (crypttext.charCodeAt(0) - 0x30) * 10 + crypttext.charCodeAt(1) - 0x30;
if (seed > 15 || isNaN(crypttext.charAt(0)) || isNaN(crypttext.charAt(1)))
return;
for (i = 2 ; i <= crypttext.length; i++) {
if(i !=2 && !(i & 1)) {
plaintext += String.fromCharCode(val ^ xlate.charCodeAt(seed++));
seed %= xlate.length;
val = 0;
}
val *= 16;
if(!isNaN(crypttext.charAt(i))) {
val += crypttext.charCodeAt(i) - 0x30;
continue;
}
if(crypttext.charCodeAt(i) >= 0x41 && crypttext.charCodeAt(i) <= 0x46) {
val += crypttext.charCodeAt(i) - 0x41 + 0x0a;
continue;
}
if(crypttext.length != i)
return;
}
console.log(plaintext);
return plaintext;
}
@karan-joshi-01
Copy link

I Don't know why but I'm not getting a log.

I Know the encryption/decryption algorithm. I have built it up in python. But I want in JS. Please help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment