Skip to content

Instantly share code, notes, and snippets.

@dchest
Created February 14, 2013 15:45
Show Gist options
  • Select an option

  • Save dchest/4953638 to your computer and use it in GitHub Desktop.

Select an option

Save dchest/4953638 to your computer and use it in GitHub Desktop.
reversing vPass2
encrypt = function(data, length) {
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$%,()*-./;:<=>?[\]^_{|}~".split("");
var chars_length = chars.length;
var data_length = data.length;
// Data is required
if(data == "") {
return "";
}
// Default value for length
length = length || data_length;
// Calculate the offset of the first character.
for(var last = 0, i = 0; i < data_length; i++) {
last = (data.charCodeAt(i) + 31 * last) % 59;
}
// Grow data if it's shorter than required length
while(data_length < length) {
data += data;
data_length += data_length;
}
data = data.slice(0, length);
//last = 0;
// Generate the encrypted string.
for(var ret = "", i = 0; i < length; i++) {
ret += chars[last = (i + last + data.charCodeAt(i)) % chars_length];
}
return ret;
};
decrypt = function(data, length) {
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$%,()*-./;:<=>?[\]^_{|}~";
var chars_length = chars.length;
var data_length = data.length;
var tab = {};
for (var i = 0; i < chars_length; i++) {
tab[chars.charCodeAt(i)] = i;
}
// Data is required
if(data == "") {
return "";
}
// Default value for length
length = length || data_length;
// Calculate the offset of the first character.
for(var last = 0, i = 0; i < data_length; i++) {
last = (data.charCodeAt(i) + 31 * last) % 59;
}
// Grow data if it's shorter than required length
while(data_length < length) {
data += data;
data_length += data_length;
}
data = data.slice(0, length);
var res = [];
for (var j = 0; j < 59; j++) {
prev = j;
// Generate the encrypted string.
for(var ret = "", i = 0; i < data_length; i++) {
var cur = tab[data.charCodeAt(i)];
ch = (cur + 85) - prev - i;
prev = cur;
//console.log(data[i], prev, ch);
if (ch < 65) ch += 85;
ret += String.fromCharCode(ch);
}
res.push(ret);
}
return res;
};
console.log(encrypt("insecure", 10));
console.log(decrypt("o)NgyCl8Dl", 10));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment