It's okay. Using JS to write a string encryption method, the basic principle is to convert the string to the corresponding Unicode (using the method is charCodeAt ()), and then Unicode unified minus 100 (here plus minus how much you take), The resulting Unicode code is converted to the corresponding character (the method used is string.fromcharcode()), the code is as follows:
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "Utf-8">5 <title>String encryption</title>6 <Scripttype= "Text/javascript">7 window.onload=function(){8 varAipt=document.getElementsByTagName ('input');9 varOdiv=document.getElementById ('txt');Ten aipt[1].onclick= function(){ One varTxtval=aipt[0].value; A varStr= ""; - Console.log (txtval); - for(varI=0; I<Txtval.length;i++){ the Str+=String.fromCharCode (Txtval.charcodeat (i)- -); - } - odiv.innerhtml=str; - } + } - </Script> + </Head> A <Body> at <inputtype= "text"/> - <inputtype= "button"value= "Encrypted"> - <DivID= "txt">Encrypted text is displayed here ~</Div> - </Body> - </HTML>
Using JavaScript to encrypt strings