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
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
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++'