Automatically Sending An Encrypted EMail


This post extends the post on encrypting email messages to automatically sending them.

This is the interface:

Here is how a received message would look:

Here is the code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head profile=”http://gmpg.org/xfn/11″&gt;
<title>Encrypt</title>
<style>
body {margin-left:0;margin-right:0;font:normal normal normal 15px Arial;}
a{ text-decoration: }:link { color: rgb(0, 0, 255) }:visited {color :rgb(100, 0,100) }:hover { }:active { }

</style>
</head>
<body>
<center> <input type=”button” id=”b2″ name=”b2″ value=”compose” onclick=’test();’/> <input type=”button” id=”b1″ name=”b1″ value=”decode” onclick=’dcode();’/> <input type=”button” id=”b3″ name=”b3″ value=”abort” onclick=’abrt();’/> <select id=”s1″ name=”s1″>
<option >Send To</option>
<option >name1@email1.com</option>
<option >name2@email2.com</option>
</select><br /><br />
<textarea id=”ta” name=”ta” style=”width: 90%; height: 550px”></textarea>
</center>

var str = “”; var cnt = -1; var sign = []; var str2 = “”; var sign2 = []; var str3 = “”;var a = 0; var a2 = 0; var b = 0; var lngth; var stra = “”; var strb = “”; var si;

document.getElementById(“ta”).focus();

function abrt() {
window.location = “asciia.html”;
}

function test() {
lngth = document.getElementById(“ta”).value.length;
for (var i = 0; i -1) {
a2 = document.getElementById(“ta”).value.indexOf(“050”, a2 + 1) ;
if (a2 > -1) b = a2 + 3;
}
lngth = b/2;
str3 = document.getElementById(“ta”).value.substr(0,lngth);
str2 = document.getElementById(“ta”).value.substr(str3.length,lngth);
document.getElementById(“ta”).value = document.getElementById(“ta”).value.replace(str2, ”);
document.getElementById(“ta”).value = document.getElementById(“ta”).value.replace(str3, ”);
document.getElementById(“ta”).value = document.getElementById(“ta”).value.substr(22,document.getElementById(“ta”).value.length – 26);
str2 = str2.replace(new RegExp(‘050’, ‘g’),’,’);
sign = str2.split(“,”);
str3 = str3.replace(new RegExp(‘050’, ‘g’),’,’);
sign2 = str3.split(“,”);
for (var i = 0; i
</body></html>


The changes are the addition of an abort button, a timer and another function, sendit().

The abort button calls the function abrt(), which reloads the page:
function abrt() {
window.location = “asciia.html”;
}

the test() function has the additional statement to start a timer:
si = setInterval(“sendit()”, 5000);

The sendit() function opens with a five second delay, the default email client and fills the heading and body:
function sendit() {
var subject = “subject”;
var mailto = document.getElementById(“s1”).value;
var body2 = document.getElementById(“ta”).value;
window.open(‘mailto:’ + mailto + ‘?subject=’ + subject + ‘&body=’ + body2);
clearInterval(si);
}

If for some reason you decide not to send the message, you have five seconds to hit the abort button.

You can also abort by not hitting send in the email client.

The recipient is chosen from a list, so this can be used for a select group to whom you want to send confidential messages:
<select id=”s1″ name=”s1″>
<option >Send To</option>
<option >name1@email1.com</option>
<option >name2@email2.com</option>
</select>

Using Javascript to Add Elements to Head and Body


Elements can be added to a web page head and body using javascript. There are times when this may be useful.

Here is the code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head profile=”http://gmpg.org/xfn/11″&gt;
<title>HTML Editor</title>
<style>
body {margin-left:0;margin-right:0;font:normal normal normal 15px Arial;}
a{ text-decoration: }:link { color: rgb(0, 0, 255) }:visited {color :rgb(100, 0,100) }:hover { }:active { }

</style>
</head>
<body>

var imported = document.createElement(‘script’);
imported.src= “appendbody.js”;
document.head.appendChild(imported);
var imported = document.createElement(‘select’);
document.body.appendChild(imported);
imported.style = “position:absolute; left:20px; top:5px; width: 100px”;
imported.innerHTML += “Item1Item2”;
imported.onchange = chnge;
imported = document.createElement(‘textarea’);
document.body.appendChild(imported);
imported.style = “position:absolute; left:20px; top:30px; width: 800px; height: 500px”;
imported = document.createElement(‘input’);
document.body.appendChild(imported);
imported.type = “file”;
imported.style = “position:absolute; left:150px; top:5px”;
imported = document.createElement(‘input’);
document.body.appendChild(imported);
imported.type = “button”;
imported.id = “b1”;
imported.value = “Button”;
imported.style = “position:absolute; left:350px; top:5px”;
imported.onclick = go;

function go(e) {
alert(document.getElementById(“b1”).value);
alert(“Button Clicked”);
}

function chnge(e) {
alert(“Changed”);
}

</body></html>


Here is how it looks:

The js file placed in the head opens an alert:

Clicking the select expands it:
var imported = document.createElement(‘select’);
document.body.appendChild(imported);
imported.style = “position:absolute; left:20px; top:5px; width: 100px”;
imported.innerHTML += “<option>Item1</option><option>Item2</option>”;

Changing the selected option calls the function chnge(e), which displays an alert:
imported.onchange = chnge;

function chnge(e) {
alert(“Changed”);
}

The file input is imported as just an input and then given a type:
imported = document.createElement(‘input’);
document.body.appendChild(imported);
imported.type = “file”;
imported.style = “position:absolute; left:150px; top:5px”;

On clicking a file dialog is opened:

The button was given an id and a value:
imported = document.createElement(‘input’);
document.body.appendChild(imported);
imported.type = “button”;
imported.id = “b1”;
imported.value = “Button”;
imported.style = “position:absolute; left:350px; top:5px”;

An alert gives the value of the button.

Clicking the button calls the function go(e):
imported.onclick = go;

function go(e) {
alert(document.getElementById(“b1”).value);
alert(“Button Clicked”);
}

Which displays an two alerts, of which one is shown:

The function could also have been called from the element id, but it was not necessary.

Putting Text in an Automatically Sized Sunburst


This post expands the previous posts on automatically adjusting font size to fit a given screen percentage to automatically place it in a sunburst frame.

The only settings needed are the font and the screen percentage.

Here is one example of text at 90%:

Here is another example with a different font at 30%:

Here is the code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head profile=”http://gmpg.org/xfn/11″&gt;
<title>HTML Editor</title>
<style>
body {margin-left:0;margin-right:0;font:normal normal normal 15px Arial;}
a{ text-decoration: }:link { color: rgb(0, 0, 255) }:visited {color :rgb(100, 0,100) }:hover { }:active { }

</style>
</head>
<body>
<table id=”d1″style = “position: absolute; top: 10%; height: 300px”>
<tr><td><img id = “img1” src= “images/sunbrst.gif” style = “position: absolute; width: 100%; height: 300px; top: 0” />
</td></tr></table>
<table id = “d3” style = “position: absolute; top: 10%; height: 300px”><tr><td id = “d2”></td></tr></table>

var mul2 = 9.0; var mul; var pc; var a = -1; var ln;
document.getElementById(“d2″).style = ” font: inormal normal normal 15px Times New Roman”;
document.getElementById(“d2”).innerHTML = “this is also a test”;
ln = document.getElementById(“d2”).innerHTML.length;
for (var i = 1; i -1) ln –;
}
mul = mul2 / (document.getElementById(“d2”).clientWidth / ln);
var rsize = 30/1.2;
pc = 1.65*mul*Math.round((screen.width * (rsize / 100)) / ln);
document.getElementById(“d2”).style.fontSize = pc + “px”;
document.getElementById(“d1”).style.width = (document.getElementById(“d2”).clientWidth) * 1.2 + “px”;
document.getElementById(“d1”).style.left = (screen.width – document.getElementById(“d2”).clientWidth*1.2)/2 + “px”;
document.getElementById(“d3”).style.width = (document.getElementById(“d2”).clientWidth) * 1.02 + “px”;
document.getElementById(“d3”).style.left = (screen.width – document.getElementById(“d2”).clientWidth*1.02)/2 + “px”;
document.getElementById(“d1”).style.height = 100 + pc + “px”;
document.getElementById(“d3”).style.height = 100 + pc + “px”;
document.getElementById(“img1”).style.height = 100 + pc + “px”;

</body></html>


To keep everything centered vertically, I used two identical single cell tables, one containing an image of the sunburst and the other the text.

The procedure for generating the font size has been discussed before:
ln = document.getElementById(“d2”).innerHTML.length;
for (var i = 1; i <= 100; i ++) {
a = document.getElementById(“d2″).innerHTML.indexOf(” “, a + 1);
if ( a == -1) break;
if (a > -1) ln –;
}
mul = mul2 / (document.getElementById(“d2”).clientWidth / ln);
var rsize = 30/1.2;
pc = 1.65*mul*Math.round((screen.width * (rsize / 100)) / ln);
document.getElementById(“d2”).style.fontSize = pc + “px”;

The screen percentage was set with this variable, in this example at 30%:
var rsize = 30/1.2;

The table with the image was made slightly wider than the one with the text and both were centered:
document.getElementById(“d1”).style.width = (document.getElementById(“d2”).clientWidth) * 1.2 + “px”;
document.getElementById(“d1”).style.left = (screen.width – document.getElementById(“d2”).clientWidth*1.2)/2 + “px”;
document.getElementById(“d3”).style.width = (document.getElementById(“d2”).clientWidth) * 1.02 + “px”;
document.getElementById(“d3”).style.left = (screen.width – document.getElementById(“d2”).clientWidth*1.02)/2 + “px”;

Besides its width, the image height had to be adjusted for different font sizes:
document.getElementById(“d1”).style.height = 100 + pc + “px”;
document.getElementById(“d3”).style.height = 100 + pc + “px”;
document.getElementById(“img1”).style.height = 100 + pc + “px”;

HTML Sudoku Puzzle with Instantaneous Puzzle Creation


I had previously posted an app that sets sudoku boards from pre-determined solutions.

This app adds the creation of a new solution each time.

Clicking New Game creates a puzzle of the existing difficulty, while changing the difficulty creates one with the new value.

Here is how it might look:

To try it click here

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head profile=”http://gmpg.org/xfn/11″&gt;
<title>Sudoku</title>
<style>
body {margin-left:0;margin-right:0;font:normal normal normal 15px Arial;}
a{ text-decoration: }:link { color: rgb(0, 0, 255) }:visited {color :rgb(100, 0,100) }:hover { }:active { }

</style>
</head>
<body>
<center><input type=”button” id=”b2″ style=”position: relative; top: 5px” name=”b2″ value=”New Game” onclick=’rn();strt();’/> <select id=”s1″ name=”s1″ onchange=’rn();strt();’>
<option >Easy</option>
<option >Moderate</option>
<option >Hard</option>
</select> <input type=”checkbox” id=”ch1″ name=”ch1″ value=”” onchange=’notes();check();’/>notes <input type=”button” id=”b3″ style=”position: relative; top: 5px” name=”b3″ value=”check” onclick=’check();’/> </center>
<di id=”d1″ style=”position: absolute; left: 50%; margin-left: -225px; top: 100px; width: 450px; height: 486px”></di>
<table id = “frame” style=”position: absolute; left: 50%; margin-left: -225px; top: 100px; width: 450px; height: 450px; border-collapse: collapse; text-align: center”></table>
<di id=”congrats” style = “position: absolute; width: 50%; left: 25%; top:100px; padding: 50px 2px 50px 2px; font:italic normal 800 36px Georgia; border: 2px solid black; border-radius: 10px; background: blue; color: yellow; visibility: hidden; text-align: center”>Congratulations!! You Have Won</di>

var lft = -33; var tp = -32.7; var no; var hold; var cnt = 0; var choose; var diff; var tbl = “”; var brk = 0;

for (var i = 1; i ‘;
}
for (var i = 1; i ‘;
}

tbl = ‘

‘;
for (var i=1; i

‘;
if (i % 9 == 0) tbl += ‘ ‘;
}
tbl += ‘

‘;
tbl = tbl.replace(new RegExp(”, ‘g’),’>’);
document.getElementById(“frame”).innerHTML = tbl;
arr1 = new Array(); arr2 = new Array(); arr3 = new Array(); arr4 = new Array(); arr5 = new Array(); arr6 = new Array(); arr7 = new Array(); arr8 = new Array(); arr9 = new Array(); sol = new Array(); var si;
for (var i = 0; i 9) i = 1;
}
}
}
for (var i=1; i 9) {
arr2[i] = 1;
i = 1;
}
}
if (i 9) {
arr2[i] = 1;
i = 1;
}
}
}
if (i > 3 && i 9) {
arr2[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q 9) {
arr2[i] = 1;
i = 1;
}
}
}
}
}
for (var i=1; i 9) {
arr3[i] = 1;
i = 1;
}
for (var j = 1; j 9) {
arr3[i] = 1;
i = 1;
}
}
if (i 9) {
arr3[i] = 1;
i = 1;
}
}
}
if (i > 3 && i 9) {
arr3[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q 9) {
arr3[i] = 1;
i = 1;
}
}
}
}
}
for (var i=1; i 100000) {
brk = 0;
break;
}
arr4[i] = Math.floor(9*Math.random()) + 1;

for (var k = 0; k 9) {
arr4[i] = 1;
i = 1;
}
}
if (arr4[i] == arr1[i] || arr4[i] == arr2[i] || arr4[i] == arr3[i]) arr4[i] ++;
if (arr4[i] > 9) {
arr4[i] = 1;
i = 1;
}
}
}
for (var i=1; i 100000) {
brk = 0;
break;
}
arr5[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k 9) {
arr5[i] = 1;
i = 1;
}
for (var j = 1; j 9) {
arr5[i] = 1;
i = 1;
}
}
if (i 9) {
arr5[i] = 1;
i = 1;
}
}
}
if (i > 3 && i 9) {
arr5[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q 9) {
arr5[i] = 1;
i = 1;
}
}
}
}
}
for (var i=1; i 100000) {
brk = 0;
break;
}
arr6[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k 9) {
arr6[i] = 1;
i = 1;
}
for (var j = 1; j 9) {
arr6[i] = 1;
i = 1;
}
}

if (i 9) {
arr6[i] = 1;
i = 1;
}
}
}
if (i > 3 && i 9) {
arr6[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q 9) {
arr6[i] = 1;
i = 1;
}
}
}
}
}
for (var i=1; i 100000) {
brk = 0;
break;
}
arr7[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k 9) {
arr7[i] = 1;
i = 1;
}
}
if (arr7[i] == arr1[i] || arr7[i] == arr2[i] || arr7[i] == arr3[i] || arr7[i] == arr4[i] || arr7[i] == arr5[i] || arr7[i] == arr6[i] ) arr7[i] ++;
if (arr7[i] > 9) {
arr7[i] = 1;
i = 1;
}
}
}
for (var i=1; i 100000) {
brk = 0;
break;
}
arr8[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k 9) {
arr8[i] = 1;
i = 1;
}

for (var j = 1; j 9) {
arr8[i] = 1;
i = 1;
}
}
if (i 9) {
arr8[i] = 1;
i = 1;
}
}
}
if (i > 3 && i 9) {
arr8[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q 9) {
arr8[i] = 1;
i = 1;
}
}
}
}
}

for (var i=1; i 100000) {
brk = 0;
break;
}
arr9[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k 9) {
arr9[i] = 1;
i = 1;
}
for (var j = 1; j 9) {
arr9[i] = 1;
i = 1;
}
}

if (i 9) {
arr6[i] = 1;
i = 1;
}
}
}
if (i > 3 && i 9) {
arr9[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q 9) {
arr9[i] = 1;
i = 1;
}
}
}
}
}
for (var i=1; i
</body></html>


The Play part is basically the same as before; the main difference is in the creation which is done by the function rn().

Ten arrays are instantiated, one for each row and one for the solution:
arr1 = new Array(); arr2 = new Array(); arr3 = new Array(); arr4 = new Array(); arr5 = new Array(); arr6 = new Array(); arr7 = new Array(); arr8 = new Array(); arr9 = new Array(); sol = new Array();

Each row is initialized randomly, with exchanges for any repetitions by incrementing the number. If a number exceeds nine, it is set back to one and the process is recycled:
for (var i = 1; i <= 9; i ++) {
arr1[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k <= 5; k ++) {
for (var j = 1; j < i; j ++) {
if( arr1[i] == arr1[j]) arr1[i] ++;
if (arr1[i]> 9) i = 1;
}
}
}

The array sol is set equal to the created array:
for (var i=1; i <= 9; i ++) {
sol[i] = arr1[i];
}

Subsequent arrays are created by comparing to previous arrays as well as previous items of the array:
for (var i = 0; i <= 9; i ++) {
arr9[i] = 0;
}
for (var i = 1; i <= 9; i ++) {
brk ++;
if (brk > 100000) {
brk = 0;
break;
}
arr9[i] = Math.floor(9*Math.random()) + 1;
for (var k = 0; k <= 5; k ++) {
if (arr9[i] == arr1[i] || arr9[i] == arr2[i] || arr9[i] == arr3[i] || arr9[i] == arr4[i] || arr9[i] == arr5[i] || arr9[i] == arr6[i] || arr9[i] == arr7[i] || arr9[i] == arr8[i] ) arr9[i] ++;
if (arr9[i] > 9) {
arr9[i] = 1;
i = 1;
}
for (var j = 1; j < i; j ++) {
if( arr9[i] == arr9[j]) arr9[i] ++;
if (arr9[i] > 9) {
arr9[i] = 1;
i = 1;
}
}

if (i <= 3) {
for (var q = 1; q <= 3; q ++) {
if( arr9[i] == arr7[q] || arr9[i] == arr8[q] ) arr9[i] ++;
if (arr6[i] > 9) {
arr6[i] = 1;
i = 1;
}
}
}
if (i > 3 && i <=6) {
for (var q = 4; q <= 6; q ++) {
if( arr9[i] == arr7[q] || arr9[i] == arr8[q] ) arr9[i] ++;
if (arr9[i] > 9) {
arr9[i] = 1;
i = 1;
}
}
}
if (i > 6) {
for (var q = 7; q <= 9; q ++) {
if( arr9[i] == arr7[q] || arr9[i] == arr8[q] ) arr9[i] ++;
if (arr9[i] > 9) {
arr9[i] = 1;
i = 1;
}
}
}
}
}
for (var i=1; i <= 9; i ++) {
sol[i + 72] = arr9[i];
}

sol is used to fill the boxes:
document.getElementById(“td” + no).innerHTML = sol[no];

Occasionally if a solution could not be found, the code would get into an endless loop. The code below is used from the forth row on and breaks that loop:
brk ++;
if (brk > 100000) {
brk = 0;
break;
}

I have repeated the generator twenty times and have never failed to get a solution.