Encrypted/Encoded TinyDB

Spurred on by a post on the forum about using tinydb for personal data, I had a go, just for fun, to make use of an encoding system I found a while ago, Encode/Encrypt – using Javascript and WebViewString, The trick to this is that neither the username or the pin code are stored in the app, so yes, the user WILL have to remember these, the two are then combined to created an encoding key. All tags and values are encrypted/encoded into the tinydb, and can be decrypted/decoded while the user is correctly logged in. The encryption/encoding is not seen by the logged in user. Anyone else can login but will not be able to view or use another user's data, unless they are lucky enough to use exactly the same username and PIN code (9000 possible combinations). I have not set this example up for multi-user, but if you login as another user, you should see how it works when you call the tags.

Here is some example data: tags and content, once it is encrypted/encoded:


["ひしぐざ", "ひすさそか", "ひすざそ", "ひすせこ", "ぶけせこ", "ぺしず"]


"っ〚ひしぐざ〚〔〘〚《「〚〔〘〚べえおけご〘《〉かが〚づ"

"っ〚ひすさそか〚〔〘〚〉、〚〔〘〚ぶしぎそさずそお〘〉「がぐ〚づ"

"っ〚ひすざそ〚〔〘〚《』〚〔〘〚ひきざそ〘」がぐ〚づ"

"っ〚ひすせこ〚〔〘〚》〈〚〔〘〚ひきごぁ〘〉 がぐ〚づ"

"っ〚ぶけせこ〚〔〘〚〉」〚〔〘〚ひすざきすおぁ〘》おぜ〚づ"

"っ〚ぺしず〚〔〘〚」《〚〔〘〚べきたきかが〘〉」がぐ〚づ"

BLOCKS

JAVASCRIPT


var str = window.AppInventor.getWebViewString().split("||")[0]; 
var encoded = ""; var numberCode = window.AppInventor.getWebViewString().split("||")[1]; 
for (i=0; i<str.length;i++) { 
var a = str.charCodeAt(i); 
var b = a ^ numberCode; 
encoded = encoded+String.fromCharCode(b);
 } 
window.AppInventor.setWebViewString(encoded)