Decryption the URL using JAVASCRIPT
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/JavaScript">
var decryptedTxt;
$(document).ready(function(){
var ciphertext="t5jWAyFv/Uo=";
var password="vick";
decrypt(ciphertext, password);
alert(decryptedTxt);
});
'use strict';
var Tea = {};
/**
* Decrypts text using Corrected
*
* @param {string} ciphertext - String to be decrypted.
* @param {string} password - Password to be used for decryption (1st 16 chars).
* @returns {string} Decrypted text.
*/
function decrypt(ciphertext, password) {
ciphertext = String(ciphertext);
password = String(password);
if (ciphertext.length == 0) return('');
// v is n-word data vector; converted to array of longs from base64 string
var v = Tea.strToLongs(ciphertext.base64Decode());
// k is 4-word key; simply convert first 16 chars of password as key
var k = Tea.strToLongs(password.utf8Encode().slice(0,16));
var n = v.length;
v = Tea.decode(v, k);
var plaintext = Tea.longsToStr(v);
// strip trailing null chars resulting from filling 4-char blocks:
plaintext = plaintext.replace(/\0+$/,'');
decryptedTxt=plaintext.utf8Decode();
return decryptedTxt;
}
/**
decodes array of unsigned 32-bit integers using 128-bit key.
*
* @param {number[]} v - Data vector.
* @param {number[]} k - Key.
* @returns {number[]} Decoded vector.
*/
Tea.decode = function(v, k) {
var n = v.length;
var z = v[n-1], y = v[0], delta = 0x9E3779B9;
var mx, e, q = Math.floor(6 + 52/n), sum = q*delta;
while (sum != 0) {
e = sum>>>2 & 3;
for (var p = n-1; p >= 0; p--) {
z = v[p>0 ? p-1 : n-1];
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
y = v[p] -= mx;
}
sum -= delta;
}
return v;
};
/**
* Converts string to array of longs (each containing 4 chars).
* @private
*/
Tea.strToLongs = function(s) {
// note chars must be within ISO-8859-1 (Unicode code-point <= U+00FF) to fit 4/long
var l = new Array(Math.ceil(s.length/4));
for (var i=0; i<l.length; i++) {
// note little-endian encoding - endianness is irrelevant as long as it matches longsToStr()
l[i] = s.charCodeAt(i*4) + (s.charCodeAt(i*4+1)<<8) +
(s.charCodeAt(i*4+2)<<16) + (s.charCodeAt(i*4+3)<<24);
}
return l; // note running off the end of the string generates nulls since bitwise operators
}; // treat NaN as 0
/**
* Converts array of longs to string.
* @private
*/
Tea.longsToStr = function(l) {
var a = new Array(l.length);
for (var i=0; i<l.length; i++) {
a[i] = String.fromCharCode(l[i] & 0xFF, l[i]>>>8 & 0xFF, l[i]>>>16 & 0xFF, l[i]>>>24 & 0xFF);
}
return a.join(''); // use Array.join() for better performance than repeated string appends
};
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Extend String object with method to encode multi-byte string to utf8
* - monsur.hossa.in/2012/07/20/utf-8-in-javascript.html */
if (typeof String.prototype.utf8Encode == 'undefined') {
String.prototype.utf8Encode = function() {
return unescape( encodeURIComponent( this ) );
};
}
/** Extend String object with method to decode utf8 string to multi-byte */
if (typeof String.prototype.utf8Decode == 'undefined') {
String.prototype.utf8Decode = function() {
try {
return decodeURIComponent( escape( this ) );
} catch (e) {
return this; // invalid UTF-8? return as-is
}
};
}
/** Extend String object with method to encode base64
* - developer.mozilla.org/en-US/docs/Web/API/window.btoa, nodejs.org/api/buffer.html
* note: if btoa()/atob() are not available (eg IE9-), try github.com/davidchambers/Base64.js */
if (typeof String.prototype.base64Encode == 'undefined') {
String.prototype.base64Encode = function() {
if (typeof btoa != 'undefined') return btoa(this); // browser
if (typeof Buffer != 'undefined') return new Buffer(this, 'utf8').toString('base64'); // Node.js
throw new Error('No Base64 Encode');
};
}
/** Extend String object with method to decode base64 */
if (typeof String.prototype.base64Decode == 'undefined') {
String.prototype.base64Decode = function() {
if (typeof atob != 'undefined') return atob(this); // browser
if (typeof Buffer != 'undefined') return new Buffer(this, 'base64').toString('utf8'); // Node.js
throw new Error('No Base64 Decode');
};
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if (typeof module != 'undefined' && module.exports) module.exports = Tea; // CommonJS export
if (typeof define == 'function' && define.amd) define([''], function() { return Tea; }); // AMD
</script>
</head>
</html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/JavaScript">
var decryptedTxt;
$(document).ready(function(){
var ciphertext="t5jWAyFv/Uo=";
var password="vick";
decrypt(ciphertext, password);
alert(decryptedTxt);
});
'use strict';
var Tea = {};
/**
* Decrypts text using Corrected
*
* @param {string} ciphertext - String to be decrypted.
* @param {string} password - Password to be used for decryption (1st 16 chars).
* @returns {string} Decrypted text.
*/
function decrypt(ciphertext, password) {
ciphertext = String(ciphertext);
password = String(password);
if (ciphertext.length == 0) return('');
// v is n-word data vector; converted to array of longs from base64 string
var v = Tea.strToLongs(ciphertext.base64Decode());
// k is 4-word key; simply convert first 16 chars of password as key
var k = Tea.strToLongs(password.utf8Encode().slice(0,16));
var n = v.length;
v = Tea.decode(v, k);
var plaintext = Tea.longsToStr(v);
// strip trailing null chars resulting from filling 4-char blocks:
plaintext = plaintext.replace(/\0+$/,'');
decryptedTxt=plaintext.utf8Decode();
return decryptedTxt;
}
/**
decodes array of unsigned 32-bit integers using 128-bit key.
*
* @param {number[]} v - Data vector.
* @param {number[]} k - Key.
* @returns {number[]} Decoded vector.
*/
Tea.decode = function(v, k) {
var n = v.length;
var z = v[n-1], y = v[0], delta = 0x9E3779B9;
var mx, e, q = Math.floor(6 + 52/n), sum = q*delta;
while (sum != 0) {
e = sum>>>2 & 3;
for (var p = n-1; p >= 0; p--) {
z = v[p>0 ? p-1 : n-1];
mx = (z>>>5 ^ y<<2) + (y>>>3 ^ z<<4) ^ (sum^y) + (k[p&3 ^ e] ^ z);
y = v[p] -= mx;
}
sum -= delta;
}
return v;
};
/**
* Converts string to array of longs (each containing 4 chars).
* @private
*/
Tea.strToLongs = function(s) {
// note chars must be within ISO-8859-1 (Unicode code-point <= U+00FF) to fit 4/long
var l = new Array(Math.ceil(s.length/4));
for (var i=0; i<l.length; i++) {
// note little-endian encoding - endianness is irrelevant as long as it matches longsToStr()
l[i] = s.charCodeAt(i*4) + (s.charCodeAt(i*4+1)<<8) +
(s.charCodeAt(i*4+2)<<16) + (s.charCodeAt(i*4+3)<<24);
}
return l; // note running off the end of the string generates nulls since bitwise operators
}; // treat NaN as 0
/**
* Converts array of longs to string.
* @private
*/
Tea.longsToStr = function(l) {
var a = new Array(l.length);
for (var i=0; i<l.length; i++) {
a[i] = String.fromCharCode(l[i] & 0xFF, l[i]>>>8 & 0xFF, l[i]>>>16 & 0xFF, l[i]>>>24 & 0xFF);
}
return a.join(''); // use Array.join() for better performance than repeated string appends
};
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/** Extend String object with method to encode multi-byte string to utf8
* - monsur.hossa.in/2012/07/20/utf-8-in-javascript.html */
if (typeof String.prototype.utf8Encode == 'undefined') {
String.prototype.utf8Encode = function() {
return unescape( encodeURIComponent( this ) );
};
}
/** Extend String object with method to decode utf8 string to multi-byte */
if (typeof String.prototype.utf8Decode == 'undefined') {
String.prototype.utf8Decode = function() {
try {
return decodeURIComponent( escape( this ) );
} catch (e) {
return this; // invalid UTF-8? return as-is
}
};
}
/** Extend String object with method to encode base64
* - developer.mozilla.org/en-US/docs/Web/API/window.btoa, nodejs.org/api/buffer.html
* note: if btoa()/atob() are not available (eg IE9-), try github.com/davidchambers/Base64.js */
if (typeof String.prototype.base64Encode == 'undefined') {
String.prototype.base64Encode = function() {
if (typeof btoa != 'undefined') return btoa(this); // browser
if (typeof Buffer != 'undefined') return new Buffer(this, 'utf8').toString('base64'); // Node.js
throw new Error('No Base64 Encode');
};
}
/** Extend String object with method to decode base64 */
if (typeof String.prototype.base64Decode == 'undefined') {
String.prototype.base64Decode = function() {
if (typeof atob != 'undefined') return atob(this); // browser
if (typeof Buffer != 'undefined') return new Buffer(this, 'base64').toString('utf8'); // Node.js
throw new Error('No Base64 Decode');
};
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
if (typeof module != 'undefined' && module.exports) module.exports = Tea; // CommonJS export
if (typeof define == 'function' && define.amd) define([''], function() { return Tea; }); // AMD
</script>
</head>
</html>
No comments:
Post a Comment