Message from JavaScript discussions

January 2019

— Programmer

— 

Hello everyone,

can help me? how to create function decryption.
I have been create function for encryption, but I'm confusion to create next function decryption.

var words = "hello how are you";
var letter = 'abcdefghijklmnopqrstuvwxyz';

function Encryption(words) {
var lowerWords = words.toLowerCase();
console.log(lowerWords, ": process lowercase");
var result = "";

for (let index = 0; index < lowerWords.length; index++) {
var wordsData = lowerWords[index];
console.log(wordsData, ": words data");
var indexWords = letter.indexOf(wordsData);`
console.log(indexWords, ": index words data");
// if condition meet whitespace
if (indexWords == -1) {
// add number 32 on whitespace
result += 32 + "-";
} else {
result += ((indexWords + 1) + "0").toString();
}
}
console.log(result, ": result words data");
return result;
}
Encryption(words);
Output Ecnryption
805012012015032-8015023032-101805032-250150210

Expectation Output Decryption
hello how are you

— How do you know if it's encryption? maybe it generates a hash.. describe the algorithm maybe

— Oh, ive got it. you wont decrypt it because numbers are not distingushable, no separation

— Hmm.. wait, it puts "0" at the end🤤

— Behold:

THREAD = (chain) -> # {{{
return new Promise (complete) !->
index = 0
step = (i) !->
switch i
# next
| true =>
if not i = chain[++index]
complete!
return
# repeat
| false =>
i = chain[index]
# finish
| -1 =>
complete!
return
# jump
| otherwise =>
index := i
i = chain[i]
# run
new Promise i .then step
###
step false
# }}}

Message permanent page

— 😅

— 

decrypt = (s) ->
###
words = s.split '32-'
###
for a,i in words
# decrypt word
b = ''
while (j = a.indexOf '0') != -1
# bite chunk
k = parseInt a.substring 0, j
a = a.substring j
# decrypt char
b += letter[k]
# replace
words[i] = b
###
return words.join ' '

Message permanent page

— Not tested

— Just stop

— It can stop if you say resolve(-1);🤤

— Encoding flow control as numbers and booleans is insane