Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
Is this a good way to Encrypt and decrypt strings data

I have made this simple example below, and trying to encrypt/decrypt string.

But I cannot help wonder if it is the right way to do it.

Have a look below and see that if it will develops problems with different character/string.

const getKey = (key) => {
  let keyNum = 0;
  for (let char of key) {
    let cCode = char.charCodeAt(0) + key.length;
    keyNum += cCode;
  }
  return keyNum;
};

const Encrypt = (str, key) => {
  let text = '';
  
  let keyNum = getKey(key);
  for (let char of str) {
    let cCode = char.charCodeAt(0) + keyNum;
    // what happend if cCode dose not generate a valid string
    text += String.fromCharCode(cCode);
  }

  return text;
};

const Decrypt = (str, key) => {
  let text = '';
  let keyNum = getKey(key);
  for (let char of str) {
    let cCode = char.charCodeAt(0) - keyNum;
    text += String.fromCharCode(cCode);
  }
  return text;
};

const testText = "hahhaha this is a test - هههههه هذا اختبار";
const testKey = "test Key";
const eText = Encrypt(testText, testKey);
console.log("Encrypt:", eText)
console.log("Decrypt:", Decrypt(eText,testKey))

Please look at the comment above in Encrypt() and let me know if it can really happen

Why I am doing this.

I want to use a simple encryption that work with js(react-native) and C#. I cant find any. That is why I am trying to build a simple plugins. C# will encrypt a js files and upload it to someplace and js will download those js files decrypt them and using Function I will be able to use them

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First this is bad. If you want a simple test to check your encryption (basic test) just enter the same char as the text and see the repetition of your output, just by that i can discover your key.

If you wish to use good encryption then use libraries made by professionals.

If you really want to build encryption by your self then sit with books and learn the subject, it is a very interesting but also very hard subject to master, no shot cuts here.

Good book to start with - 'Cryptography in C and C++'

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!