Skip to content

Instantly share code, notes, and snippets.

@imhuytq
Created August 5, 2014 06:51
Show Gist options
  • Save imhuytq/0cc50144f87b35632c19 to your computer and use it in GitHub Desktop.
Save imhuytq/0cc50144f87b35632c19 to your computer and use it in GitHub Desktop.
CKFinder 2.x keygen
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CKFinder Keygen</title>
</head>
<body>
<table style="border: 1px solid #999;">
<thead>
<tr>
<th colspan="2" style="background-color: #eee; color: #333; text-align: center;">
CKFinder 2.x Keygen
</th>
</tr>
</thead>
<tbody>
<tr>
<td><label for="licenseName">License Name</label>:</td>
<td><input type="text" id="licenseName" placeholder="License Name" /></td>
</tr>
<tr>
<td><label for="licenseKey">License Name</label>:</td>
<td><input type="text" id="licenseKey" onClick="this.select();" readonly /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<button id="generateBtn">Generate</button>
</td>
</tr>
</tbody>
</table>
&copy; 2014 <a href="http://huytq.com">@huytq</a>
<script>
String.prototype.replaceAt = function(index, character) {
if (index > this.length - 1) return this;
return this.substr(0, index) + character + this.substr(index + character.length);
}
function generateKey(licenseName) {
licenseKey = "";
// Tập ký tự sử dụng trong license key
chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
// Tạo một license key ngẫu nhiên gồm 32 ký tự
for (i = 0; i <= 31; i++) {
licenseKey += chars[Math.floor((Math.random() * (chars.length - 1)))];
}
// Các ký tự quan trọng: 0, 3, 12, 25
/*
* ----------------------------------------------
* Tạo ký tự thứ 0
* ----------------------------------------------
* Công thứ:
* Là các ký tự trong tập ký tự mà có số thứ tự khi chia cho 5 sẽ dư 4.
*/
zeroChars = chars[4] + chars[9] + chars[14] + chars[19] + chars[24] + chars[29];
licenseKey = licenseKey.replaceAt(0, zeroChars[Math.floor((Math.random() * (zeroChars.length - 1)))]);
/*
* ----------------------------------------------
* Tạo ký tự thứ 3
* ----------------------------------------------
* Công thứ:
* Kiểm tra xem ký tự thứ 1 nằm ở vị trí nào trong tập ký tự. Sau đó cộng với độ
* dài của license name. Tiếp đến nhân với 9, rồi chia cho phép dịch bit trái
* của 2 và 4 lấy phần dư => Ví trí của ký tự thứ 3 ở trong tập ký tự.
*/
licenseKey = licenseKey.replaceAt(3, chars.substr(((licenseName.length + chars.indexOf(licenseKey[1])) * 9 % (2 << 4)), 1));
/*
* ----------------------------------------------
* Tạo ký tự thứ 12
* ----------------------------------------------
* Công thứ:
* Lấy vị trí trong tập ký tự của ký tự thứ 11 cộng với vị trí trong tập ký tự
* của ký tự thứ 8 rồi nhân với 9, sau đó chia cho độ dài của tập ký tự trừ đi 1
* => vị trí của ký tự thứ 12 ở trong tập ký tự
*/
licenseKey = licenseKey.replaceAt(12, chars[(chars.indexOf(licenseKey[11]) + chars.indexOf(licenseKey[8])) * 9 % (chars.length - 1)]);
/*
* ----------------------------------------------
* Tạo ký tự thứ 25
* ----------------------------------------------
* Công thứ:
* Là các ký tự trong tập ký tự mà có số thứ tự khi chia cho 8 sẽ có số dư = 7.
*/
twentyFiveChars = chars[7] + chars[15] + chars[23] + chars[31];
licenseKey = licenseKey.replaceAt(25, twentyFiveChars[Math.floor((Math.random() * (twentyFiveChars.length - 1)))]);
return licenseKey;
}
document.getElementById("generateBtn").onclick = function(event) {
event.preventDefault();
licenseName = document.getElementById('licenseName').value.trim();
if (licenseName == "") alert("Please enter License Name!");
else document.getElementById('licenseKey').value = generateKey(licenseName);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment