Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda