Skip to content

Instantly share code, notes, and snippets.

@AzureFlow
Created March 24, 2025 03:58
Show Gist options
  • Save AzureFlow/c2d2135c1dacefdd1611c55a48ebacc0 to your computer and use it in GitHub Desktop.
Save AzureFlow/c2d2135c1dacefdd1611c55a48ebacc0 to your computer and use it in GitHub Desktop.
Akamai BMP native (`libakamaibmp.so`) string concealment
const RotateDirection = Object.freeze({
Left: -1,
Right: 1,
});
// Init the ASCII character mapping table (equivalent to the large local_* arrays)
// /** @type {string[]} */
// const charMap = [];
// for(let i = 32; i < 127; i++) {
// // Skip " ' \ \x7F
// // if (i === 0x22 || i === 0x27 || i === 0x5C || i === 0x7F)
// if(i === 34 || i === 39 || i === 92 || i === 127) {
// continue;
// }
//
// charMap.push(String.fromCharCode(i));
// }
// Same as Akamai web
const charMap = " !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
/**
* Rotates a string by substituting characters according to a mapping table.
* @param {string} inputString String to rotate.
* @param {number} seed Rotation seed.
* @param {-1|0|1} direction Direction of rotation.
* @returns {string} The rotated string.
*/
export function rotateString(inputString, seed, direction) {
// If direction is 0 or string is empty, return the input string unchanged
if(direction === 0 || inputString.length === 0) {
return inputString;
}
let result = "";
let currentSeed = seed;
for(let i = 0; i < inputString.length; i++) {
const char = inputString.charAt(i);
const charIndex = charMap.indexOf(char);
if(charIndex >= 0) {
const offset = (currentSeed >> 8 & 0xFFFF) % charMap.length;
if(direction < 1) {
// Rotate left
result += charMap[(charIndex - offset + charMap.length) % charMap.length];
}
else {
// Rotate right
result += charMap[(offset + charIndex) % charMap.length];
}
}
else {
// If character not in map, keep it unchanged
result += char;
}
// Update the seed for the next character
currentSeed = (currentSeed * 0x10101 + 0x415927) & 0x7FFFFF;
}
return result;
}
// const encrypted = rotateString("Hello World!", 12345, RotateDirection.Right);
// console.log("encrypted:", encrypted);
// const decrypted = rotateString(encrypted, 12345, RotateDirection.Left);
// console.log("decrypted:", decrypted);
// Found in Java_com_cyberfend_cyfsecurity_SensorDataBuilder_buildN → SensorDataBuilder::initializeKeys
const publicKeyString = rotateString("-j0ZOfGt%xoJ$.p%U<#~.Bnx#M\nk?-%PwI&Yg+>#|;0W1F{?0@WVJE+#8d 6]Jy2V2_<uqM:HbEfN8j/fy,L^(Prg}yLPi^Xp&ot43flfpXu`h AmT).TJ;*fdo^f;G@J84LcY!U-QKo[:]Be5)h>v6HN*rjS,^|*<K+(6||yxRxH:S#4>FSYVwK=z<_SH&*L+qWor+.fNpo_Q@o_8@t{KAqQxc#Z(%X,r^[q)~*;+b8Plb<Mrc\n8(&U++!|Z8HPGT5oa/BqAbX6", 63, RotateDirection.Left);
console.log(publicKeyString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment