Jump to content
XdotY

[Java Script] Protejare fisiere .js

Recommended Posts

Posted (edited)

De multe ori mi s-a intamplat ca dupa ce m-am chinuit zile,chiar saptamani la diferite scripturi JS,sa ma trezesc ca vine cate unul si altul si imi fura codul fara sa lase un © macar ,asa ca mi-am dezvoltat propria metoda de encriptie.Ma folosesc de ASP si cookieuri pentru a encripta codul in cadrul functiilor Java Script.Bineinteles exista o metoda de a trece peste aceasta encriptie zi a decoda codul,insa 99% din useri nu vor reusii,asa ca este o metoda cat se poate de buna.

Sursa:

http://rapidshare.com/files/235556770/Encryption_js.zip.html

cipher.js


var cipher_block_size=64, encoding_buffer=1024;
function b0f(c) {
return c < 16 ? '0' + c.toString(16) : c.toString(16);
}
function bff(c) {
return parseInt(c, 16);
}
function salt(s) {
var n = 0;
for (var i=0; i<s.length; i++) n += i&s.charCodeAt(i);
return b0f(n%256);
}
function encrypt(s,k) {
if (s.length > cipher_block_size) {
var m=parseInt(s.length/cipher_block_size), t=Math.round(m/2)*cipher_block_size;
return encrypt(s.substr(0, t), k) + encrypt(s.substr(t), k);
}
var r=parseInt(Math.random()*256), o=b0f(r), i;
for (i=0; i<s.length; i++) {
o += b0f(s.charCodeAt(i)^r^k.charCodeAt(i%k.length));
}
return o;
}
function decrypt(s,k) {
var dbs = (cipher_block_size+1)*2;
if (s.length > dbs) {
var m=parseInt(s.length/dbs), t=Math.round(m/2)*dbs;
return decrypt(s.substr(0, t), k) + decrypt(s.substr(t), k);
}
var n=bff(s.substr(0,2)), o='';
for (var i=2; i<s.length; i+=2) {
o += String.fromCharCode(bff(s.substr(i,2))^n^k.charCodeAt((i-2)/2%k.length));
}
return o;
}
function encipher(f) {
var s=f.stream.value, k=salt(f.key.value), r=k, b=encoding_buffer,
p=0, n=Math.floor(s.length/b)+1;
while (n > p++) {
self.status = 'Encrypting block ' + p + '/' + n;
r += encrypt(s.substr((p-1)*b, , f.key.value);
}
f.stream.value = r;
self.status = 'Done';
}
function decipher(f) {
var s=f.stream.value.substr(2), k=salt(f.key.value), r='',
b=2*(encoding_buffer+encoding_buffer/cipher_block_size), p=0, n=Math.floor(s.length/b)+1;
if (k != f.stream.value.substr(0, 2)) {
if (!confirm('The key is probably incorrect.\nContinue decryption?'))
return;
}
while (p++ < n) {
self.status = 'Decrypting block ' + p + '/' + n;
r += decrypt(s.substr((p-1)*b, , f.key.value);
}
f.stream.value = r;
return self.status = 'Done';
}

cookies.js


function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}


function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}


function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}


function fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}

serverCipher.js


<%
var cipher_block_size=64, encoding_buffer=1024;
function b0f(c) {
return c < 16 ? '0' + c.toString(16) : c.toString(16);
}
function bff(c) {
return parseInt(c, 16);
}
function salt(s) {
var n = 0;
for (var i=0; i<s.length; i++) n += i&s.charCodeAt(i);
return b0f(n%256);
}
function encrypt(s,k) {
if (s.length > cipher_block_size) {
var m=parseInt(s.length/cipher_block_size), t=Math.round(m/2)*cipher_block_size;
return encrypt(s.substr(0, t), k) + encrypt(s.substr(t), k);
}
var r=parseInt(Math.random()*256), o=b0f(r), i;
for (i=0; i<s.length; i++) {
o += b0f(s.charCodeAt(i)^r^k.charCodeAt(i%k.length));
}
return o;
}
function decrypt(s,k) {
var dbs = (cipher_block_size+1)*2;
if (s.length > dbs) {
var m=parseInt(s.length/dbs), t=Math.round(m/2)*dbs;
return decrypt(s.substr(0, t), k) + decrypt(s.substr(t), k);
}
var n=bff(s.substr(0,2)), o='';
for (var i=2; i<s.length; i+=2) {
o += String.fromCharCode(bff(s.substr(i,2))^n^k.charCodeAt((i-2)/2%k.length));
}
return o;
}
function encipher(f) {
var s=f.stream.value, k=salt(f.key.value), r=k, b=encoding_buffer,
p=0, n=Math.floor(s.length/b)+1;
while (n > p++) {
self.status = 'Encrypting block ' + p + '/' + n;
r += encrypt(s.substr((p-1)*b, , f.key.value);
}
f.stream.value = r;
self.status = 'Done';
}
function decipher(f) {
var s=f.stream.value.substr(2), k=salt(f.key.value), r='',
b=2*(encoding_buffer+encoding_buffer/cipher_block_size), p=0, n=Math.floor(s.length/b)+1;
if (k != f.stream.value.substr(0, 2)) {
if (!confirm('The key is probably incorrect.\nContinue decryption?'))
return;
}
while (p++ < n) {
self.status = 'Decrypting block ' + p + '/' + n;
r += decrypt(s.substr((p-1)*b, , f.key.value);
}
f.stream.value = r;
return self.status = 'Done';
}
%>

main.asp


<%@Language=JAVAScript%>


<!--#include file="serverCipher.js"-->


<%
var randomKey = "";
var i;
for (i=0; i < 4; i++)
{
randomKey += "" + Math.round(10 * Math.random(),0);
}
Response.Cookies.Item("Key") = randomKey;
%>

<HTML>
<HEAD>
<TITLE>My main page</TITLE>
</HEAD>
<BODY>


<script src="cookies.js">
</script>
<script src="cipher.js">
</script>


<%
function escapeJS(s) {
Response.Write("eval(decrypt(\"" + encrypt(s,randomKey) + "\",a));" + "\n");
}


%>
<script>
function secretFunction() {
var a = getCookie("Key");
<%
//encripted code
escapeJS("var b = 1;");
escapeJS("var c = 1;");
escapeJS("alert('The result is : ' + (b + c));");
%>
}
</script>

<P> Welcome to XdotY's home page...</P>

<input type="button" value="Secret calculation..." onclick="secretFunction()">

</BODY>
</HTML>

Edited by XdotY

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...