encrypting / shortening a long string in JS [duplicate] - javascript

This question already has answers here:
String compression in JavaScript
(8 answers)
Closed 6 years ago.
I need to shorten a long string with a variable length and "decode" it back later on.
The string will be built up like this 0011010011 ........ etc.
My problem right now is that the string will be over a thousand characters long which is far far too long to easily copy and paste around.
Any ideas on how to do this?
read more

Javascript doesn't support binary data by default. I would either use an exisiting package such as binstring or write your own encoding function

Related

How to pass a string which contain UTF-8 characters from javascript to PHP? [duplicate]

This question already has answers here:
UTF-8 all the way through
(13 answers)
How to store other languages (unicode) in cookies and get it back again
(1 answer)
Closed 5 years ago.
I'm building a references generator and I need to keep track of the generated references. To achieve this, I'm currently using Javascript to store a cookie containing the raw data, then a PHP page embedded on the result page takes the cookie and logs it into an HTML page, however, some characters appears like this : �. I really don't know which way to go to solve this (base64 encoding, unicode encoded characters...)
Here's the link to the website : http://louisfelixberthiaume.000webhostapp.com/source_siteweb.php
[It's in french]
I can't give you the link to the HTML page for obvious confidentiality reasons, however I'll provide a screenshot :
Generated references screenshot

Issue working with numbers in Javascript [duplicate]

This question already has answers here:
Large numbers erroneously rounded in JavaScript
(6 answers)
Closed 5 years ago.
I'm new in developing javascript apps, i have a doubt about a behaviour that i'm going to try to explain.
If i execute:
Number(5555555555555555);
Result: 5555555555555555
But if i execute:
Number(55555555555555555);
Result: 55555555555555550
Anybody can explain to me what is the reason of this? Thanks!!
If you need to work with such big numbers I would suggest you use some of the big integer libraries such as this. The reason this happens as far as I know is the way processors and memory work. It's no related to some "bug" in JS.
Integers (numbers without a period or exponent notation) are accurate up to 15 digits. Javacript simply adds zeros to keep the number accurate in terms of its digit length.
Documentation

Encrypt javascript file [duplicate]

This question already has answers here:
How can I hide or encrypt JavaScript code? [duplicate]
(7 answers)
Closed 4 years ago.
I don't find any info about that,so asking here.
Is somebody ever used some tool to protect javascript files? And totaly encrypt them?
Because I found this tool that seems like can totaly encrypt JS?
What do you think?
http://webtools.securitygeeks.net/p/blog-page_26.html?
That tool is useless. It declares a global variable called teksasli which contains your original script in a plain string. just look at the value of that variable in any console to see the original source.
There is no point in trying to encrypt Javascript, because the user/browser needs to decrypt it in order to run it.
If you want to obfuscate the source code, You could try GWT http://mojo.codehaus.org/gwt-maven-plugin/ (The Google Web Toolkit ).

JavaScript parse variable in quote [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
JavaScript Variable inside string without concatenation - like PHP
In PHP, double quotes has the ability to read variable, e.g.
"$foo"
But in JavaScript, you have to always use a + to read a variable so that the variable won't be inside the quote when it is read, e.g.
var foo='bar';
alert("The name's "+foo);
So, is there any workaround or method to do this? Using + all the time is quite troublesome.
Nope, that's not possible in JavaScript.
In JavaScript, variables are turned into string when put in single quotes or doubles quotes and can't be parsed. In JavaScript everything inside quotes is treated as string.
Even if you write custom parser, you will have no way to figure out if something in quotes is really a variable or an string because a variable named name can also appear in string somewhere which will create naming collisions.
No, there's no workaround, that's just how it is.
Javascript doesn't offer "string interpolation".
Personally I favour Ildar Shaimordanov's String.js module which adds a sprintf method to the string object.

Get exact syntax of javascript base functions [duplicate]

This question already has answers here:
Where can I find javascript native functions source code? [duplicate]
(3 answers)
Javascript native sort method code
(3 answers)
Closed 8 years ago.
Is there a way to know how test (for regex) or cos (for math) or substring (for string) or splice (for array) have been coded in the exact syntax either by a way in Javascript (like alert(function)) or by seeking in the files that come with Firefox?
Well, the source code of javascript likely isn't written in javascript itself, so you would be unable to just print it to the browser console or alert.
You can browse the source code of google's V8 engine, and see if it helps you ;)
http://code.google.com/p/v8/
These functions are actually implemented differently by browsers in one of the OS native languages.
So these algorithms are written in c, c++, c#, java etc. but not in JavaScript.

Categories

Resources