A Data Science Central Community
Here's some simple JavaScript code to encode numbers, such as credit card numbers, passwords made up of digits, phone numbers, social security numbers, dates such as 20131014 etc.
NSA Headquarters
How does it work?
This code is very simple, it is by no means strong encryption. It is indeed less sophisticated than uuencode. But uuencode is for geeks, while our app is easy to use by any mainstream people. The encoded value is also a text string, easy to copy and paste in any email client. The encoded value has some randomness, in the sense that encoding twice the same values will result in two different encoded values. Finally, it is more secure than it seems at first glance, if you don't tell anyone (except over the phone) where the decoder can be found. I will create a version that accepts parameters, to make it even more secure.
Related articles
Here's the JavaScript / HTML code for those interested (this is the source code of the web page where our application is hosted). You could save it as an HTML document on your local machine, with file name (say) encode.html in a folder (say) C://Webpages, and then open and run it from a browser on your local machine: the URL for this local webpage would be \\/C:/Webpages/encode.html if you use Chrome.
<html>
<script language="Javascript">
<!--
function encrypt2() {
var form=document.forms[0]
if (form.encrypt.checked) {
form.cardnumber.value=crypt(form.cardnumber.value)
} else {
form.cardnumber.value=decrypt(form.cardnumber.value)
}
}
function crypt(string) {
var len=string.length
var intCarlu
var carlu
var newString="e"
if ((string.charCodeAt(i)!=101)&&(len>0)) {
for (var i=0; i<len; i++) {
intCarlu=string.charCodeAt(i)
rnd=Math.floor(Math.random()*7)
newIntCarlu=30+10*rnd+intCarlu+i-48
if (newIntCarlu<48) { newIntCarlu+=50 }
if (newIntCarlu>=58 && newIntCarlu<=64) { newIntCarlu+=10 }
if (newIntCarlu>=90 && newIntCarlu<=96) { newIntCarlu+=10 }
carlu=String.fromCharCode(newIntCarlu)
newString=newString.concat(carlu)
}
return newString
} else {
return string
}
}
function decrypt(string) {
var len=string.length
var intCarlu
var carlu
var newString=""
if (string.charCodeAt(i)==101) {
for (var i=1; i<len; i++) {
intCarlu=string.charCodeAt(i)
carlu=String.fromCharCode(48+(intCarlu-i+1)%10)
newString=newString.concat(carlu)
}
return newString
} else {
return string
}
}
// -->
</script>
<form>
Enter Number <input type=text name=cardnumber size=19><p>
Encrypt / Decrypt <input type=checkbox name=encrypt onClick="encrypt2()">
</form>
</html>
Tags:
-1: ethics
This just begs people on the lower tail to use it for exactly the wrong thing.
© 2019 AnalyticBridge.com is a subsidiary and dedicated channel of Data Science Central LLC
Powered by
Badges | Report an Issue | Privacy Policy | Terms of Service