Skip to content

Instantly share code, notes, and snippets.

@makeding
Created Oct 29, 2021
Embed
What would you like to do?
const _0x22517d = _0x2c9e;
(function (_0x2018e5, _0xd122c5) {
const _0x4a600d = _0x2c9e
, _0x2e34d2 = _0x2018e5();
while (!![]) {
try {
const _0x4d38c4 = -parseInt(_0x4a600d(0x1b1)) / 0x1 * (parseInt(_0x4a600d(0x1ad)) / 0x2) + -parseInt(_0x4a600d(0x1b2)) / 0x3 * (parseInt(_0x4a600d(0x1b6)) / 0x4) + -parseInt(_0x4a600d(0x1ae)) / 0x5 * (-parseInt(_0x4a600d(0x1b4)) / 0x6) + parseInt(_0x4a600d(0x1ab)) / 0x7 * (parseInt(_0x4a600d(0x1af)) / 0x8) + parseInt(_0x4a600d(0x1b5)) / 0x9 + -parseInt(_0x4a600d(0x1b3)) / 0xa + -parseInt(_0x4a600d(0x1a9)) / 0xb * (-parseInt(_0x4a600d(0x1a7)) / 0xc);
if (_0x4d38c4 === _0xd122c5)
break;
else
_0x2e34d2['push'](_0x2e34d2['shift']());
} catch (_0x416145) {
_0x2e34d2['push'](_0x2e34d2['shift']());
}
}
}(_0x381b, 0x21c08),
String['prototype'].encrypt = function (password) {
var v = new Array(2), k = new Array(4), s = "", i;
plaintext = escape(this); // use escape() so only have single-byte chars to encode
// build key directly from 1st 16 chars of password
for (var i = 0; i < 4; i++) k[i] = Str4ToLong(password.slice(i * 4, (i + 1) * 4));
for (i = 0; i < plaintext.length; i += 8) { // encode plaintext into s in 64-bit (8 char) blocks
v[0] = Str4ToLong(plaintext.slice(i, i + 4)); // ... note this is 'electronic codebook' mode
v[1] = Str4ToLong(plaintext.slice(i + 4, i + 8));
code(v, k);
console.log(1, v[0], plaintext.slice(i, i + 4))
console.log(2, v[1], plaintext.slice(i + 4, i + 8))
console.log(12, LongToBase16(v[0]), LongToBase16(v[1]))
s += LongToBase16(v[0]) + LongToBase16(v[1]);
}
return s
}, String['prototype'].decrypt = function (password) {
var v = new Array(2), k = new Array(4), s = "", i;
ciphertext = escape(this); // use escape() so only have single-byte chars to encode
// build key directly from 1st 16 chars of password
for (var i = 0; i < 4; i++) k[i] = Str4ToLong(password.slice(i * 4, (i + 1) * 4));
for (i = 0; i < ciphertext.length; i += 16) { // encode plaintext into s in 64-bit (8 char) blocks
v[0] = (Base16ToLong(ciphertext.slice(i, i + 8)));
v[1] = (Base16ToLong(ciphertext.slice(i + 8, i + 16)));
decode(v, k);
console.log(v[0],LongToStr4(v[0]))
s += LongToStr4(v[0]) + LongToStr4(v[1]);
}
return s
}
);
function _0x2c9e(_0x49e6ff, _0x310d40) {
const _0x381b4c = _0x381b();
return _0x2c9e = function (_0x2c9ec6, _0x2ec3bd) {
_0x2c9ec6 = _0x2c9ec6 - 0x1a6;
let _0x4769df = _0x381b4c[_0x2c9ec6];
return _0x4769df;
}
,
_0x2c9e(_0x49e6ff, _0x310d40);
}
function code(v, k) {
// Extended TEA: this is the 1997 revised version of Needham & Wheeler's algorithm
// params: v[2] 64-bit value block; k[4] 128-bit key
var y = v[0], z = v[1];
var delta = 0x9E3779B9, limit = delta * 32, sum = 0;
while (sum != limit) {
y += (z << 4 ^ z >>> 5) + z ^ sum + k[sum & 3];
sum += delta;
z += (y << 4 ^ y >>> 5) + y ^ sum + k[sum >>> 11 & 3];
// note: unsigned right-shift '>>>' is used in place of original '>>', due to lack
// of 'unsigned' type declaration in JavaScript (thanks to Karsten Kraus for this)
}
v[0] = y; v[1] = z;
}
function decode(v, k) {
var y = v[0], z = v[1];
var delta = 0x9E3779B9, sum = delta * 32;
while (sum != 0) {
z -= (y << 4 ^ y >>> 5) + y ^ sum + k[sum >>> 11 & 3];
sum -= delta;
y -= (z << 4 ^ z >>> 5) + z ^ sum + k[sum & 3];
}
v[0] = y; v[1] = z;
}
function Str4ToLong(s) { // convert 4 chars of s to a numeric long
var v = 0;
s = '' + s;
for (var i = 0; i < 4; i++) v |= s.charCodeAt(i) << i * 8;
return isNaN(v) ? 0 : v;
}
function LongToStr4(v) { // convert a numeric long to 4 char string
var s = String.fromCharCode(v & 0xFF, v >> 8 & 0xFF, v >> 16 & 0xFF, v >> 24 & 0xFF);
return s;
}
function LongToBase16(_0xad4470) {
let _0x4176bf = '';
for (let _0x3c7880 = 0x3; _0x3c7880 >= 0x0; _0x3c7880--) {
let _0x43811c = (_0xad4470 >> 0x8 * _0x3c7880 & 0xff)['toString'](0x10);
if (parseInt('0x' + _0x43811c) <= 0xf)
_0x43811c = '0' + _0x43811c;
_0x4176bf += _0x43811c;
}
return _0x4176bf;
}
function Base16ToLong(_0x203413) {
_0x203413 = '' + _0x203413
const _0x27c0c4 = _0x22517d;
let _0x48728d = 0x0;
for (let _0x239fca = 0x0; _0x239fca < 0x8; _0x239fca += 0x2) {
let _0x24e56c = parseInt('0x' + _0x203413[_0x27c0c4(0x1a6)](_0x239fca, _0x239fca + 0x2));
_0x48728d = (_0x48728d << 0x8) + _0x24e56c;
}
return _0x48728d;
}
function _0x381b() {
const _0x4af9ee = ['encrypt', '33MGcQht', '6fbde674819a59bfa12092565b4ca2a7a11dc670c678681daf4afb6704b82f0c', '14021KbbewD', 'charCodeAt', '808heYYJt', '5DlyrGX', '552oZzIQH', 'fromCharCode', '356IjESGA', '784713mdLTBv', '2529060PvKScd', '805548mjjthm', '844848vFCypf', '4bIkkcJ', '1356853149054377', 'length', 'slice', '1720848ZSQDkr'];
_0x381b = function () {
return _0x4af9ee;
}
;
return _0x381b();
}
function real_getflag() {
const f = _0x22517d;
console.log('password', f(0x1b7))
console.log('ciphertext', f(0x1aa))
console.log('plaintext', f(0x1aa).decrypt(f(0x1b7)))
}
real_getflag()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment