Programming Challenge 3/99 Encryption/decryption algorithm

I decided to make most of my code in Javascript, so you can test it on my blog directly.

Encrypt:

Decrypt:

I created this encryption for the challenge purpose, so it’s not safe to use it.

Code:

<script>
function enc() {
    let text = document.getElementById("enctxt").value;
    let res = document.getElementById("encRes");
    let encBuf = null;
    let i = 0;
    for(l of text){
        encBuf += l.charCodeAt(0) + 123 + i;
        encBuf += ":";
        i += 33;
    }
    res.innerText = "Result:\n" + encBuf;
}
function dec() {
    let text = document.getElementById("dectxt").value;
    let res = document.getElementById("decRes");
    let decBuf = "";
    let i = 0;
    let nums = text.split(":");
    console.log(text[text.length - 1]);
    if (text[text.length - 1] === ':'){
        nums.pop();
    }
    for (num of nums){
        num = parseInt(num);
        num = num - 123 - i;
        num = num.toString();
        decBuf += String.fromCharCode(num);
        i += 33
    }
    res.innerText = "Result:\n" + decBuf;
}
</script>
<div id="enc">
    <b><p>Encrypt:</p></b>
    <input type="text" id="enctxt"/>
    <input type="button" value="enter" onclick="enc()"/>
    <p id="encRes"></p>
</div>
<div id="dec">
    <b><p>Decrypt:</p></b>
    <input type="text" id="dectxt"/>
    <input type="button" value="enter" onclick="dec()"/>
    <p id="decRes"></p>
</div>

This code take ASCII character number and add always 123 plus 33 every letter.

Leave a Comment