Skip to content

Instantly share code, notes, and snippets.

@skslater
Created March 16, 2015 13:16
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 skslater/63155d45d6edfd09b95e to your computer and use it in GitHub Desktop.
Save skslater/63155d45d6edfd09b95e to your computer and use it in GitHub Desktop.
SAP Upgrade Key Generator
// generator.js
function generate()
{
if (event.preventDefault) {
event.preventDefault(); }
else {
event.returnValue = false; }
var hexkey = [0, 0, 0, 0, 0];
var sid = document.getElementsByName("sid")[0].value.toUpperCase();
var host = document.getElementsByName("host")[0].value.toUpperCase();
var sysnr = document.getElementsByName("sysnr")[0].value;
if (sid.length != 3)
{
showError("SID must be 3 letters");
return false;
}
if (host.length == 0)
{
showError("Host cannot be blank");
return false;
}
if ((sysnr.length == 0) || (sysnr.length > 2))
{
showError("System number must be 1-2 digits");
return false;
}
var sidsys = sid + zeroPad(sysnr);
hostlen = host.length;
if ((hostlen > 0) && (hostlen < 5))
{
host = host + Array(6 - hostlen).join(" ");
}
if ((hostlen > 5) && (hostlen < 10))
{
host = host + Array(11 - hostlen).join(" ");
}
if ((hostlen > 10) && (hostlen < 15))
{
host = host + Array(16 - hostlen).join(" ");
}
if (host.length < 15)
{
host = host + Array(16 - host.length).join('\0');
}
for (i = 0; i < 5; i++)
{
hexkey[i] = ((((0 ^ sidsys.charCodeAt(i)) ^ host.charCodeAt(i)) ^ host.charCodeAt(i + 5)) ^ host.charCodeAt(i + 10));
}
hexkey[0] = ((hexkey[0] ^ 84) ^ 0);
hexkey[1] = ((hexkey[1] ^ 131) ^ 11);
hexkey[2] = ((hexkey[2] ^ 194) ^ 46);
hexkey[3] = ((hexkey[3] ^ 52) ^ 105);
hexkey[4] = ((hexkey[4] ^ 119) ^ 188);
strkey = "" + zeroPad(hexkey[0].toString(16).toUpperCase()) + zeroPad(hexkey[1].toString(16).toUpperCase()) + zeroPad(hexkey[2].toString(16).toUpperCase()) + zeroPad(hexkey[3].toString(16).toUpperCase()) + zeroPad(hexkey[4].toString(16).toUpperCase());
showNotice("Your installation key is " + strkey);
return false;
}
function showError(text)
{
var notice = document.getElementById("notice");
notice.innerHTML = text;
notice.className = "error";
}
function showNotice(text)
{
var notice = document.getElementById("notice");
notice.innerHTML = text;
notice.className = "notice";
}
function zeroPad(n)
{
return (n.length < 2) ? ("0" + n) : n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment