deobfuscate javascript with webpack 4 - javascript

Is there any way to deobfuscate some javascript code that produced with webpack 4 and is also splitChunked?
It's a little more than 1MB js code and I only need to understand a small portion of the code, which is this function :
function l(e) {
t.d(8, function(e) {
for (var n = e.length, r = t.b(n), f = a(), c = 0; c < n; c++) {
var i = e.charCodeAt(c);
if (i > 127)
break;
f[r + c] = i
}
if (c !== n) {
0 !== c && (e = e.slice(c)),
r = t.c(r, n, n = c + 3 * e.length);
var d = a().subarray(r + c, r + n);
c += o(e, d).written
}
return u = c,
r
}(e), u);
var n, r, f = (null !== i && i.buffer === t.e.buffer || (i = new Int32Array(t.e.buffer)),
i), c = (n = f[2],
r = f[3],
d.decode(a().subarray(n, n + r))).slice();
return t.a(f[2], 1 * f[3]),
c
}
I used chrome debugger and set some breakpoints and I was able to grasp what it's doing but I need to do the exact same thing in my project So I need a more readable code to do that.

As far as I know, there is no easy way to do so, but I want to share some tips with you:
Replace all ',' with ', '\n'
Review and correct the possible code breaks
Use a for loop to iterate between static value arrays and replace all the usages.
Change the encoding in case of language dependent breaks
Replace all ; with ; \n and correct possible code breaks
Know it is easier to rename functions and write comments for them.

Related

Wrong recursion when trying to find Range Sum of BST

I'm practicing algorithms and tackling this classic problem. There are many solutions and I'm trying to solve it using Javascript. I'll post the question and what I have below:
Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).
The binary search tree is guaranteed to have unique values.
Example 1:
Input: root = [10,5,15,3,7,null,18], L = 7, R = 15 Output: 32
var rangeSumBST = function(root, L, R) {
let result = 0;
if (root === null) return 0;
if (root.val >= L && root.val <= R) {
result += root.val
}
rangeSumBST(root.left, L, R)
rangeSumBST(root.right, L, R)
return result
};
// Output is 10 instead of 32
You are executing rangeSumBST(root.left, L, R) without using result from them. And finally get only first node value. Use instead:
var rangeSumBST = function(root, L, R) {
let result = 0;
if (root === null) return 0;
if (root.val >= L && root.val <= R) {
result += root.val
}
let left = rangeSumBST(root.left, L, R)
let right = rangeSumBST(root.right, L, R)
return result + left + right;
};

variable input becoming nullified and breaking .charAt[]

https://jsfiddle.net/2L4t9saq/180/ is my fiddle
most of the code is just useless, ill just post the stuff that matters
var baseConverter = function(r, e, n) {
var o = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (e <= 0 || e > o.length || n <= 0 || n > o.length) return console.log("Base unallowed"), null;
var l, t = 0;
if (10 != e) {
var a = r.length;
for (l = 0; l < a; l++) {
var u, f = -1;
for (u = 0; u < o.length; u++)
if (r[l] == o[u]) {
f = 1;
break
}
if (u >= e) return console.log("Symbol unallowed in baseform"), null;
if (-1 == f) return console.log("Symbol not found"), null;
var s = a - l - 1;
t += 0 == s ? u : u * Math.pow(e, s)
}
} else t = parseInt(r);
if (10 != n) {
for (var g = []; t > 0;) {
var i = t % n;
if (i < 0 || i >= o.length) return console.log("Out of bounds error"), null;
g.push(o[i]), t = parseInt(t / n)
}
return g.reverse().toString().replace(/,/g, "")
}
return t.toString()
}
var b36torgba = function(input) {
for (var i = 1; i < (input.length / 8) + 1; i++) {
var arr = input
var r = arr.charAt[0 + (i - 1) * 8] + "" + arr.charAt[1 + (i - 1) * 8]
var g = arr.charAt[2 + (i - 1) * 8] + "" + arr.charAt[3 + (i - 1) * 8]
console.log(g.charAt[2])
var b = arr.charAt[4 + (i - 1) * 8] + "" + arr.charAt[5 + (i - 1) * 8]
console.log(b)
var a = arr.charAt[6 + (i - 1) * 8] + "" + arr.charAt[7 + (i - 1) * 8]
console.log(a)
var rrgba = baseConverter(r, 36, 10)
var grgba = baseConverter(r, 36, 10)
var brgba = baseConverter(r, 36, 10)
var argba = baseConverter(r, 36, 10)
var bigMessOfAVariable = "rgba(" + rrgba + "," + grgba + "," + brgba + "," + argba + "),"
return bigMessOfAVariable;
}
}
you can ignore the top function, all it is is a base converter script, that takes in three inputs, an input, the base its in, and the base it should be converted to: eg baseConverter(73,36,10) will output 255.
now, the problem is with my b36torgba function.
it will take in a string, which is guaranteed to have a length that is either 0, 8, or a multiple of 8, this is just standardization to make sure everything runs smoothly, without having 700 indexOf[] functions.
it takes in the input, and divides it by 8, this tells the function how many bytes it has to go through, and how many it will spit out, so a string "[7300002S7300002S]" should (divided by 8) output 2, therefore the script runs 2 iterations.
currently, it should be taking in the string, and assigning each group of 2 characters (again standard) to a specific variable, this will allow it to all be put in the end and outputted as the same string but in base 10 rgba (hence 73 being use, 73 in base 36 is 255), but before it can do any of that, it breaks when it tries to find the characters in a string, saying this syntax error:
Uncaught TypeError: Cannot read property '0' of undefined
at b36torgba ((index):40)
at window.onload ((index):55)
why does it break as soon as it tries to feed the string into my charAt()'s?
ps: i do understand that the code in its current state, if it worked, it'd only output the rgba value of the last 8 characters
Easy mistake. You're using charAt (which is a function) by doing charAt[index] (using square brackets), rather than charAt(index) (using round brackets). Fixing that up should solve your issue.
Also - you're calling the function by doing b36torgba(["7300002S7300002S"]) in your JSFiddle, and trying to do string manipulation on it. Since ["7300002S7300002S"] is an array, not a string, .charAt() won't work on it. Try calling the function by doing b36torgba("7300002S7300002S") instead.

Executing JavaScript in C# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to execute the following JavaScript on the backend by recreating the logic with C# code. I'm trying to obtain the "sucuri_cloudproxy_js" cookie in order to access webcontent, but in order to obtain this cookie, you must execute this JavaScript. What is the most efficient way to execute javascript in C#? Thank you!
var s = {},
u, c, U, r, i, l = 0,
a, e = eval,
w = String.fromCharCode,
sucuri_cloudproxy_js = '',
S = 'dj0nd0U3Jy5jaGFyQXQoMikrU3RyaW5nLmZyb21DaGFyQ29kZSg5OSkgKyAiIiArIjZzdSIuc2xpY2UoMCwxKSArICI5c3UiLnNsaWNlKDAsMSkgKyAnNScgKyAgIjUiICsgImZzZWMiLnN1YnN0cigwLDEpICsgIjNzdWN1ciIuY2hhckF0KDApKyAnJyArIAoiMyIgKyAiIiArImQiLnNsaWNlKDAsMSkgKyAgJycgKyIwc3UiLnNsaWNlKDAsMSkgKyAgJycgKydlJyArICAiYyIgKyAiIiArImJzdWN1ciIuY2hhckF0KDApK1N0cmluZy5mcm9tQ2hhckNvZGUoMHgzMikgKyAgJycgKycnKydlJyArICAiOCIuc2xpY2UoMCwxKSArICAnJyArJ2ZLNycuY2hhckF0KDIpKydANCcuc2xpY2UoMSwyKSsiIiArImQiICsgICcnICsgCiJiIiArICI5IiArICAnJyArJycrU3RyaW5nLmZyb21DaGFyQ29kZSg1NCkgKyAiYiIgKyAgJycgKyAKIjYiICsgJzAnICsgICIiICsiNyIgKyAnb01kJy5jaGFyQXQoMikrImFzZWMiLnN1YnN0cigwLDEpICsgU3RyaW5nLmZyb21DaGFyQ29kZSg0OSkgKyAgJycgKycnKyc4JyArICAiZHNlYyIuc3Vic3RyKDAsMSkgKyAnJztkb2N1bWVudC5jb29raWU9J3NzdWMnLmNoYXJBdCgwKSsgJ3VzdWMnLmNoYXJBdCgwKSsgJ2MnKyd1JysncicrJ2knKydfJysnYycuY2hhckF0KDApKydsc3UnLmNoYXJBdCgwKSArJ3N1Y3VybycuY2hhckF0KDUpICsgJ3UnKydzdWN1cmQnLmNoYXJBdCg1KSArICdwc3VjdXInLmNoYXJBdCgwKSsgJ3InKydvJysneHN1Y3VyJy5jaGFyQXQoMCkrICd5Jy5jaGFyQXQoMCkrJ18nKycnKyd1c3VjdXInLmNoYXJBdCgwKSsgJ3N1Jy5jaGFyQXQoMSkrJ2knKycnKydkJysnX3MnLmNoYXJBdCgwKSsnM3N1Y3UnLmNoYXJBdCgwKSAgKycwJysnZCcrJzEnLmNoYXJBdCgwKSsnOXN1Y3UnLmNoYXJBdCgwKSAgKydzdTknLmNoYXJBdCgyKSsnc3VjdXIzJy5jaGFyQXQoNSkgKyAnYXN1Y3VyaScuY2hhckF0KDApICsgJ2YnKyI9IiArIHY7IGxvY2F0aW9uLnJlbG9hZCgpOw==';
L = S.length;
U = 0;
r = '';
var A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for (u = 0; u < 64; u++) {
s[A.charAt(u)] = u;
}
for (i = 0; i < L; i++) {
c = s[S.charAt(i)];
U = (U << 6) + c;
l += 6;
while (l >= 8) {
((a = (U >>> (l -= 8)) & 0xff) || (i < (L - 2))) && (r += w(a));
}
}
e(r);
This looks like some sort of base 64 decoding algorithm. There are built in base64 decoders in C# you could try. Alternatively, if 'S' never changes, you could just execute this in javascript and put the result in to your C# program.
executing this in javascript console:
var s = {},
u, c, U, r, i, l = 0,
a, e = eval,
w = String.fromCharCode,
sucuri_cloudproxy_js = '',
S = 'dj0nd0U3Jy5jaGFyQXQoMikrU3RyaW5nLmZyb21DaGFyQ29kZSg5OSkgKyAiIiArIjZzdSIuc2xpY2UoMCwxKSArICI5c3UiLnNsaWNlKDAsMSkgKyAnNScgKyAgIjUiICsgImZzZWMiLnN1YnN0cigwLDEpICsgIjNzdWN1ciIuY2hhckF0KDApKyAnJyArIAoiMyIgKyAiIiArImQiLnNsaWNlKDAsMSkgKyAgJycgKyIwc3UiLnNsaWNlKDAsMSkgKyAgJycgKydlJyArICAiYyIgKyAiIiArImJzdWN1ciIuY2hhckF0KDApK1N0cmluZy5mcm9tQ2hhckNvZGUoMHgzMikgKyAgJycgKycnKydlJyArICAiOCIuc2xpY2UoMCwxKSArICAnJyArJ2ZLNycuY2hhckF0KDIpKydANCcuc2xpY2UoMSwyKSsiIiArImQiICsgICcnICsgCiJiIiArICI5IiArICAnJyArJycrU3RyaW5nLmZyb21DaGFyQ29kZSg1NCkgKyAiYiIgKyAgJycgKyAKIjYiICsgJzAnICsgICIiICsiNyIgKyAnb01kJy5jaGFyQXQoMikrImFzZWMiLnN1YnN0cigwLDEpICsgU3RyaW5nLmZyb21DaGFyQ29kZSg0OSkgKyAgJycgKycnKyc4JyArICAiZHNlYyIuc3Vic3RyKDAsMSkgKyAnJztkb2N1bWVudC5jb29raWU9J3NzdWMnLmNoYXJBdCgwKSsgJ3VzdWMnLmNoYXJBdCgwKSsgJ2MnKyd1JysncicrJ2knKydfJysnYycuY2hhckF0KDApKydsc3UnLmNoYXJBdCgwKSArJ3N1Y3VybycuY2hhckF0KDUpICsgJ3UnKydzdWN1cmQnLmNoYXJBdCg1KSArICdwc3VjdXInLmNoYXJBdCgwKSsgJ3InKydvJysneHN1Y3VyJy5jaGFyQXQoMCkrICd5Jy5jaGFyQXQoMCkrJ18nKycnKyd1c3VjdXInLmNoYXJBdCgwKSsgJ3N1Jy5jaGFyQXQoMSkrJ2knKycnKydkJysnX3MnLmNoYXJBdCgwKSsnM3N1Y3UnLmNoYXJBdCgwKSAgKycwJysnZCcrJzEnLmNoYXJBdCgwKSsnOXN1Y3UnLmNoYXJBdCgwKSAgKydzdTknLmNoYXJBdCgyKSsnc3VjdXIzJy5jaGFyQXQoNSkgKyAnYXN1Y3VyaScuY2hhckF0KDApICsgJ2YnKyI9IiArIHY7IGxvY2F0aW9uLnJlbG9hZCgpOw==';
L = S.length;
U = 0;
r = '';
var A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
for (u = 0; u < 64; u++) {
s[A.charAt(u)] = u;
}
for (i = 0; i < L; i++) {
c = s[S.charAt(i)];
U = (U << 6) + c;
l += 6;
while (l >= 8) {
((a = (U >>> (l -= 8)) & 0xff) || (i < (L - 2))) && (r += w(a));
}
}
r;
gives this:
v='wE7'.charAt(2)+String.fromCharCode(99) + "" +"6su".slice(0,1) + "9su".slice(0,1) + '5' + "5" + "fsec".substr(0,1) + "3sucur".charAt(0)+ '' +
"3" + "" +"d".slice(0,1) + '' +"0su".slice(0,1) + '' +'e' + "c" + "" +"bsucur".charAt(0)+String.fromCharCode(0x32) + '' +''+'e' + "8".slice(0,1) + '' +'fK7'.charAt(2)+'#4'.slice(1,2)+"" +"d" + '' +
"b" + "9" + '' +''+String.fromCharCode(54) + "b" + '' +
"6" + '0' + "" +"7" + 'oMd'.charAt(2)+"asec".substr(0,1) + String.fromCharCode(49) + '' +''+'8' + "dsec".substr(0,1) + '';document.cookie='ssuc'.charAt(0)+ 'usuc'.charAt(0)+ 'c'+'u'+'r'+'i'+'_'+'c'.charAt(0)+'lsu'.charAt(0) +'sucuro'.charAt(5) + 'u'+'sucurd'.charAt(5) + 'psucur'.charAt(0)+ 'r'+'o'+'xsucur'.charAt(0)+ 'y'.charAt(0)+'_'+''+'usucur'.charAt(0)+ 'su'.charAt(1)+'i'+''+'d'+'_s'.charAt(0)+'3sucu'.charAt(0) +'0'+'d'+'1'.charAt(0)+'9sucu'.charAt(0) +'su9'.charAt(2)+'sucur3'.charAt(5) + 'asucuri'.charAt(0) + 'f'+"=" + v; location.reload();
take off the location.reload and execute that and it results in a string:
"sucuri_cloudproxy_uuid_30d1993af=7c6955f33d0ecb2e874db96b607da18d"
all of that was originally passed through the eval function, so in the end, I'm guessing you want the 7c...18d, or maybe something to do with the uuid variable.
if S changes, then you'll need to reverse engineer this whole thing, or find a way to leverage a server side tool to execute javascript. You could use something like phantomjs perhaps.
Adding to the answer from Mark Evaul, the cookie content should be available in your controller code by referencing:
Request.Cookies["sucuri_cloudproxy_js"].Value
You can run the replacement algorithm on the value to decode the value of the cookie.

Project Euler Solution 9 Code Not Working

function getAnswer(){
var answer, c = 334;
while (c < 999){
var a = Math.round(((1000 - c) / 2) - 0.5), b = Math.round((1000 - c) / 2);
while (a > 0 && b < c){
if (Math.pow(a, 2) + Math.pow(b, 2) != Math.pow(c, 2)){
a -= 1;
b += 1;
}else{
answer = a * b * c;
}
}
c += 1;
}
document.getElementById("a").innerHTML = answer;
}
Hi! I am a beginner programmer in javascript, and I have been trying to solve problem 9 in Project Euler. That problem goes like this:
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
I don't know why no answer appears, and my script crashes/program stops running, whenever I run this script. Please explain and tell me what's wrong with my script.
When you have found the answer, you don't stop with the iteration. Even worse, you don't change the values of a and b any more, so they never reach the end of the iteration, and you're stuck in an infinite loop.
You'll need to break out of the loop when you've found the answer. Or even break out of both your nested loops, using a label:
function getAnswer() {
var answer,
c = 334;
find: while (c < 999) {
var a = Math.round(((1000 - c) / 2) - 0.5),
b = Math.round((1000 - c) / 2);
while (a > 0 && b < c) {
if (Math.pow(a, 2) + Math.pow(b, 2) == Math.pow(c, 2)) {
answer = a * b * c;
break find;
}
a -= 1;
b += 1;
}
c += 1;
}
document.getElementById("a").innerHTML = answer;
}
Notice that it would be easier if your function just returned the answer, instead of populating #a with it. You'd call it like
document.getElementById("a").innerHTML = getAnswer();
and can just return a * b * c; to break out of the whole function.

elgamal decryption in javascript

i need a way to calculate:
m = a. b ^(p-1-x) mod p
in javascript.
i have found this algorithm for calculating base^exp%mod:
function expmod(base, exp, mod){
if (exp == 0) return 1;
if (exp % 2 == 0){
return Math.pow((this.expmod(base, (exp / 2), mod)), 2) % mod;
}
else {
return (base * (this.expmod(base, (exp - 1), mod))) % mod;
}
}
and it's works great. but I can't seem to find a way to do this for
m = a. b ^(p-1-x) mod p
i'm sorry if this question not perfect. this is my first question here. thank you.
I have no experience with cryptography, but, since no one else is answering, I'll give it a shot.
Your question didn't quite make sense to me the way it was phrased, so I decided to implement a complete Elgamal in JavaScript so that I could understand your problem in context. Here's what I came up with:
// Abstract:
var Alphabet = "!\"#$%&'()*+,-./0123456789:;<=>?#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ \n𮃩∆";
Alphabet = Alphabet.split("");
var Crypto = function (alpha, gen, C) {
var p, B, encrypt, decrypt, f, g, modInv, modPow, toAlpha, to10;
toAlpha = function (x) {
var y, p, l, n;
if (x === 0) {
return "!!!!";
}
y = [];
n = 4;
n = Math.ceil(n);
while (n--) {
p = Math.pow(alpha.length, n);
l = Math.floor(x / p);
y.push(alpha[l]);
x -= l * p;
}
y = y.join("");
return y;
};
to10 = function (x) {
var y, p, n;
y = 0;
p = 1;
x = x.split("");
n = x.length;
while (n--) {
y += alpha.indexOf(x[n]) * p;
p *= alpha.length;
}
return y;
};
modInv = function (gen, mod) {
var v, d, u, t, c, q;
v = 1;
d = gen;
t = 1;
c = mod % gen;
u = Math.floor(mod / gen);
while (d > 1) {
q = Math.floor(d / c);
d = d % c;
v = v + q * u;
if (d) {
q = Math.floor(c / d);
c = c % d;
u = u + q * v;
}
}
return d ? v : mod - u;
};
modPow = function (base, exp, mod) {
var c, x;
if (exp === 0) {
return 1;
} else if (exp < 0) {
exp = -exp;
base = modInv(base, mod);
}
c = 1;
while (exp > 0) {
if (exp % 2 === 0) {
base = (base * base) % mod;
exp /= 2;
} else {
c = (c * base) % mod;
exp--;
}
}
return c;
};
p = 91744613;
C = parseInt(C, 10);
if (isNaN(C)) {
C = Math.round(Math.sqrt(Math.random() * Math.random()) * (p - 2) + 2);
}
B = modPow(gen, C, p);
decrypt = function (a) {
var d, x, y;
x = a[1];
y = modPow(a[0], -C, p);
d = (x * y) % p;
d = Math.round(d) % p;
return alpha[d - 2];
};
encrypt = function (key, d) {
var k, a;
k = Math.ceil(Math.sqrt(Math.random() * Math.random()) * 1E10);
d = alpha.indexOf(d) + 2;
a = [];
a[0] = modPow(key[1], k, key[0]);
a[1] = (d * modPow(key[2], k, key[0])) % key[0];
return a;
};
f = function (message, key) {
var n, x, y, w;
y = [];
message = message.split("");
n = message.length;
while (n--) {
x = encrypt(key, message[n]);
y.push(toAlpha(x[0]));
y.push(toAlpha(x[1]));
}
y = y.join("");
return y;
};
g = function (message) {
var n, m, d, x;
m = [];
n = message.length / 8;
while (n--) {
x = message[8 * n + 4];
x += message[8 * n + 5];
x += message[8 * n + 6];
x += message[8 * n + 7];
m.unshift(x);
x = message[8 * n];
x += message[8 * n + 1];
x += message[8 * n + 2];
x += message[8 * n + 3];
m.unshift(x);
}
x = [];
d = [];
n = m.length / 2;
while (n--) {
x[0] = m[2 * n];
x[1] = m[2 * n + 1];
x[0] = to10(x[0]);
x[1] = to10(x[1]);
d.push(decrypt(x));
}
message = d.join("");
return message;
};
return {
pubKey: [p, gen, B],
priKey: C,
decrypt: g,
encrypt: f
};
};
// Usage:
var Alice = Crypto(Alphabet, 69);
var Bob = Crypto(Alphabet, 69);
var message = "Hello!";
console.log(message);
// "Hello!"
message = Alice.encrypt(message, Bob.pubKey);
print(message);
// "Pl)7t&rfGueuL#|)H'P,*<K\.hxw+∆d*`?Io)lg~Adz-6xrR" or something like it.
message = Bob.decrypt(message);
console.log(message);
// "Hello!"
So, basically, Crypto handles all of the Elgamal algorithms, using modPow when it needs to. I think that the modPow function was what you were originally after, wasn't it? The version that you originally posted uses repeated squaring instead of ordinary exponentiation, presumably for purposes of performance, but they're both reasonably speedy.
It still isn't clear to me, though, why you needed a different algorithm for doing "m = a. b ^(p-1-x) mod p". I never needed anything like that in implementing my Elgamal, so I'm not sure what this corresponds to. I did need to implement a function that calculates the modular multiplicative inverse, which I called modInv. Is that what you wanted? I used a stripped-down version of the Extended Euclidean Algorithm to make it.
If it helps, feel free to copy part or all of my code for your project.
And, if you have any more questions about this, please ask me!
EDIT: Note, this code is not intended for actual production-grade encryption. It is really just a proof of concept for the algorithm. With a little work, however, it could be made more secure. Let me know.
EDIT: To encrypt and decrypt text, do the following:
Create a new Crypto object to encrypt the text, and then save it:
var Alice=Crypto(Alphabet, 69);
Here, Alice is just some variable, Alphabet is the 29-symbol alphabet that I defined at the top of the code, and 69 is a primitive root mod 91744613.
Then, create another Crypto object to decrypt the text, and then save it:
var Bob=Crypto(Alphabet, 69);
Although Bob was created in the same way as Alice, they are different objects. Bob cannot decrypt text intended for Alice, and Alice cannot decrypt text intended for Bob.
Now, use Alice's encrypt method to encrypt some text, and save the result:
var codedMessage=Alice.encrypt("HELLO, WORLD.", Bob.pubKey);
Here, message is an empty variable, "HELLO, WORLD." is the text to be encrypted (or the contents of a text file). Bob.key is Bob's public key. We must use Bob's key in the encryption so that Bob (and only Bob) can decrypt the text. The resulting encrypted text will look something like this: "Pl)7t&rfGueuL#|)H'P,*<K\.hxw+∆d*?Io)lg~Adz-6xrR"`. Note that even with the same message, different output will be generated each time. It will still always decrypt to the same value.
Now, in theory, we can send this encrypted text over whatever un-secure channel we want, and no one will be able to decode it. When Bob receives the encrypted text, however, he can decode it. To do this:
var plainMessage=Bob.decrypt(codedMessage);
Now, plainMessage will contain the text "HELLO, WORLD.", which you can read or do whatever you want with.
So, all together, just these four lines will do it:
var Alice=Crypto(Alphabet, 69);
var Bob=Crypto(Alphabet, 69);
var codedMessage=Alice.encrypt("HELLO, WORLD.", Bob.pubKey);
var plainMessage=Bob.decrypt(codedMessage);
// Now, plainMessage contains "HELLO, WORLD."
If you specifically want to do this with text files, then you can either copy-and-paste the contents into the javascript, or you can look into loading the contents of a text file into javascript. To get started, see this SO, and this HG.

Categories

Resources