HTML Logic Form Obfuscating Password - javascript

I'm attempting to troubleshoot a login issue on an old system that noone here is very familiar with. We have what we believe to be the admin password, but it isn't working. I'm just grasping, but I thought maybe a browser issue, considering how old the system is, so I tried using Postman to see what kind of response I get, which resulted in a failure.
However, I'm noticing now that they seem to be using some method to obfuscate the password, and I don't really understand what it's doing.
The login form method is this.
<form method="post" name='login' action="/?language=en" onsubmit="document.getElementById('submit').disabled = true; document.getElementById('pass').value = CJMaker.makeString(document.getElementById('pass').value);" >
and the CJMaker file contains this.
function CJMaker(e)
{}function _CJMaker_makeString(val)
{if (val == null)
{return val;}var size = val.length;var retVal = new String();var conVal = new String();for (var i = 0; i < size; i++)
{var current = val.charCodeAt(i);current = current^4;conVal += String.fromCharCode(current);}for (var i = size - 1; i >= 0; i--)
{retVal += conVal.charAt(i);}return retVal;}CJMaker.makeString = _CJMaker_makeString;
So it looks like it's just using char codes, and I suspect that the password in the database isn't the actual password, but instead is whatever this would create.
I'm afraid I just do not understand this well enough to reverse it. I'm sure it's simple to some of you javascript guys though.
Can anyone tell me more about what this is doing?

The function XORs the character code of each character with 4, and then reverses the result.
This function is its own inverse, so if you have an encoded password on the server, run the function on that to get what you need to type.
function CJMaker(e) {}
function _CJMaker_makeString(val) {
if (val == null) {
return val;
}
var size = val.length;
var retVal = new String();
var conVal = new String();
for (var i = 0; i < size; i++) {
var current = val.charCodeAt(i);
current = current ^ 4;
conVal += String.fromCharCode(current);
}
for (var i = size - 1; i >= 0; i--) {
retVal += conVal.charAt(i);
}
return retVal;
}
CJMaker.makeString = _CJMaker_makeString;
let instring = "abcdefgh";
let obfusc = CJMaker.makeString(instring);
let outstring = CJMaker.makeString(obfusc);
console.log(instring, obfusc, outstring);

Related

How to make google sheet script Ignore fields with formulas

I have built a script which works perfectly fine, however for usability I want to populate the fields queried to build the payload, via formulas.
Issue: if I have fields without values but formulas, the script sends empty values to the api resulting in an error stopping follow up functions.
If I manually set the array of fields including formulas it works.
Solution I am looking for: a code line for my script, to break upon meeting a field with a formula instead of a value.
I hope this question/issue is clear.
I tried this code but it did not work:
for (var i = 1; i < data_statistics.length; i++) {
if (data_statistics[i] === undefined) {
break;
}
else if (data_statistics[i][0].includes("=")) {
break;
}
This is the working function:
function Mean(){
var sheet_statistics = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Mean")
var data_statistics = sheet_statistics.getDataRange().getValues();
var token = _requestToken();
var col_start = 2
for (var i = 1; i < data_statistics.length; i++) {
if (data_statistics[i] === undefined) {
break;
}
// Build payloads and apply small sanity checks payload specific
// Payload same typo
var payload = Object();
for (var j = col_start; j < data_statistics[0].length; j++) {
_buildPayload(payload, data_statistics[0][j].split('.'), data_statistics[i][j]);
}
payload.filters.divisionLevel100 = String(payload.filters.divisionLevel100);
// Get statistics
var statistics = _getOfferStatistics(token, payload)
// Set statistics values in cells
sheet_statistics.getRange(i+1, 1).setValue(statistics.metric)
sheet_statistics.getRange(i+1, 2).setValue(statistics.value)
Use getFormulas(), which returns
empty strings for no formulas
const data_statistics_rg = sheet_statistics.getDataRange(),
data_statistics = data_statistics_rg.getValues(),
data_statistics_formulas = data_statistics_rg.getFormulas();
for (var i = 1; i < data_statistics.length; i++) {
if (data_statistics[i] === undefined) {
break;
}
else if (!data_statistics_formulas[i][0].includes("")) {
break;
}

JavaScript - What is wrong with my Hash Table?

I am doing the first problem on LeetCode, Two Sum. I am trying to do the problem using a hash table. This is what I came up with:
var twoSum = function(nums, target) {
var hash = [];
for(var i = 0; i < nums.length; i++) {
var need = target - nums[i];
if (!hash[need]) {
hash[need] = i;
} else {
return [hash[nums[i]], i];
}
}
};
When I run my code, I am getting undefined as an answer. Let's say I have an array [2,3,1,6,4] and my target is 8. When I iterated through the array, I will get 8-2=6, 8-3=5, 8-1=7, 8-6=2, and 8-4=4. So, my hash table should look like this according to my code:
6:0
5:1
7:2
2:3
4:4
If something is not in the hash table, I want to throw it into the hash. When I run into the number in the hash, then I return hash[nums[i]] and i since I am ready at the index and hash[nums[i]] has the value of the index that I need. I am unsure why I am getting an undefined. Any advice to make this better?
Please see the code. I have removed the else part and returned the hash at end. Please let me know if this is what you were looking.
var twoSum = function(nums, target) {
var hash = [];
for(var i = 0; i < nums.length; i++) {
var need = target - nums[i];
if (!hash[need]) {
hash[need] = i;
}
}
return hash;
};
console.log(twoSum([2,3,1,6,4],8))

Unpredictable behaviour when setting a boolean variable in JavaScript [Deep copying in strict mode]

function computerSetManapool(cost) {
var splittedCost = cost.split(',');
for (var i = 0; i < splittedCost.length; i++) {
if (splittedCost[i] === "CL") {
for (var j = 0; j < computerLands.length; j++) {
if (!computerLands[j].tapped) {
computerLands[j].tapped = true;
console.log(computerLands[j].name + " gets tapped");
break;
}
}
}
}
}
I'm having a bit of trouble with this little piece of code, it's a Windows Store App, though I'm not using anything like the WinJS library or jQuery or what not.
Especially this line worries me:
computerLands[j].tapped = true;
I was debugging this in Visual Studio, while j had the value of 1. Therefore computerLands[1].tapped was supposed to be set to true.
Instead it set computerLands[1].tapped = true AND computerLands[3].tapped = true.
It does not happen every time, but many times and therefore I can't see what the problem is.
computerLands is an initially empty array, which then gets dynamically pushed objects into it.
If someone even has a remote idea what problem this could be, I would be really grateful.
Edit: This is the code where computerLands gets populated:
function computerTurn() {
untapAll("computer");
drawCards(1, "computer");
for (var i = 0; i < computerHand.length; i++) {
if (computerHand[i].type === "land") {
var container = document.getElementById("computerLandsContainer");
var newItem = document.createElement("div");
newItem.id = computerLandsID;
computerLandsID++;
newItem.style.backgroundImage = "url("+computerHand[i].image+")";
newItem.style.backgroundSize = "100%";
var btn1 = document.createElement("button");
btn1.id = "tapButtonComputer";
btn1.innerText = "˜";
newItem.appendChild(createEnlargeButton(newItem,"computer"));
newItem.appendChild(btn1);
container.appendChild(newItem);
computerLands.push(computerHand[i]);
console.log("Computer plays: " + computerHand[i].name);
computerLands[computerLands.length - 1].id = newItem.id;
var index = computerHand.indexOf(computerHand[i]);
computerHand.splice(index,1);
break;
}
}
}
The actual line is just this:
computerLands.push(computerHand[i]);
After pushing it into computerLands it gets removed from computerHand via splice().
var index = computerHand.indexOf(computerHand[i]);
computerHand.splice(index,1);
Finally I found a solution, I got it from this page: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/f79b2e68-15a9-4d5e-8aad-e15f78d94840/how-do-i-clone-an-object?forum=winappswithhtml5
It describes how to deep copy in Javascript in Windows Store Apps (this other solution I found http://james.padolsey.com/javascript/deep-copying-of-objects-and-arrays/ is not allowed in Windows Store Apps strict mode), basically you create a new object and copy every property into it. Now here's my new working code:
function populateComputerLands() {
for (var i = 0; i < 4; i++) {
//computerLands.push(availableComputerCards[0]); <--- old code
var objectToCopy = availableComputerCards[0]; // new code
var newObject = Object.create(Object.getPrototypeOf(objectToCopy));
var newObjectProperties = Object.getOwnPropertyNames(objectToCopy);
var propertyName;
for (var p in newObjectProperties) {
propertyName = newObjectProperties[p];
Object.defineProperty(newObject, propertyName, Object.getOwnPropertyDescriptor(objectToCopy, propertyName));
};
computerLands.push(newObject);
}
}

Javascript: matching a dynamic string against an array

I'm attempting to teach myself javascript. I chose something I assumed was simple, but ran into problems relatively quickly.
I'm attempting to search a string for another string given by the user.
My code so far is:
var source = "XREs2qqAQfjr6NZs6H5wkZdOES5mikexRkOPsj6grQiYNZfFoqXI4Nnc1iONKVrA";
var searchString = []; //the users input
searchString = prompt("Enter search string");
var hits = [];
var one = 0;
var two = 0;
var k = 0;
var sourceSearch = function(text) {
for(i = 0; i < source.length; i++) { //for each character in the source
if(source[i] === searchString[0]) { //if a character in source matches the first element in the users input
one = source.indexOf(i); //confused from here on
for(p = searchString.length; p > 0; p--) {
}
}
}
};
sourceSearch(searchString);
My idea was:
check to see if the first loop finds a character that matches the first character in the user input
if it matches, check to see if the next X characters after the first match the next X characters in the source string
if they all match, push them to the hits array
My problem: I have no idea how to iterate along the arrays without nesting quite a few if statements, and even then, that wouldn't be sufficient, considering I want the program to work with any input.
Any ideas would be helpful. Thanks very much in advance.
Note: There are a few un-used variables from ideas I was testing, but I couldn't make them work.
You can try:
if (source.indexOf(searchString) !== -1) {
// Match!
}
else
{
//No Match!
}
As the other answers so far point out, JavaScript strings have an indexOf function that does what you want. If you want to see how it's done "by hand", you can modify your function like this:
var sourceSearch = function(text) {
var i, j, ok; // always declare your local variables. globals are evil!
// for each start position
for(i = 0; i < source.length; i++) {
ok = true;
// check for a match
for (j = searchString.length - 1; ok && j >= 0; --j) {
ok = source[i + j] === searchString[j];
}
if (ok) {
// searchString found starting at index i in source
}
}
};
This function will find all positions in source at which searchString was found. (Of course, you could break out of the loop on the first success.) The logic is to use the outer loop to advance to each candidate start position in source and use the inner loop to test whether that position actually is the position of a match to searchString.
This is not the best algorithm for searching strings. The built-in algorithm is much faster (both because it is a better algorithm and because it is native code).
to follow your approach, you can just play with 2 indexes:
var sourceSearch = function(text) {
j = 0;
for(i = 0; i < source.length; i++) {
if(source[i] === text[j]) {
j++;
} else {
j = 0;
}
if (j == text.length) {
console.log(i - j); //this prints the starting index of the matching substring
}
}
};
These answers are all pretty good, but I'd probably opt for something like this:
var source = "XREs2qqAQfjr6NZs6H5wkZdOES5mikexRkOPsj6grQiYNZfFoqXI4Nnc1iONKVrA";
var searchString = []; //the users input
searchString = prompt("Enter search string");
var hits = source.split(searchString);
var hitsCount = hits.length - 1;
This way you have all of the data you need to figure out where each hit occurred in he source, if that's important to you.

JavaScript variable not is undefined in IE9

Hello I have next JS code (this code not my own)
function somename(f)
var procName = "";
var procParams = new Array();
var parseEl = "";
var parseEls = new Array();
var parseInd = 0;
var procParamsInd = 0;
var IsValRead = false;
for (i = 0; i < f.length; i++) {
if (f[i] == "(")
break;
else
procName = procName + f[i];
}
}
I will redo it to much better way to find data before "(", but i wounder why procName variable is always undefined in IE9 in all browsers all working well.
I have a vague recollection that at least some versions of IE do not support indexing to access string characters. Try using charAt instead; or a better algorithm. It is almost certainly the f[x] which is causing your undefined's.
A better way to get the substring before ( is this:
var f = "name(2,4,5)",
procName = f.slice(0, f.indexOf('(')); //slice from start until before "("
console.log(procName)​; //name

Categories