Saturday, April 27, 2013
Public Key Encryption and Digital Signature: How do they work?
I recently had a task which involves Encryption and Digital Signature. This paper from CGI.com is one of the things that helped me understand how public key encryption and digital signatures work.
http://www.cgi.com/files/white-papers/cgi_whpr_35_pki_e.pdf
I hope this also will help you.
Monday, April 8, 2013
My solution to chapter 12 exercises of JavaScript Step by Step 2e
1. Create a webpage that sends a cookie to the browser. Set the expiration date ahead
one day. Verify that the JavaScript code sent the cookie to the browser by viewing it as
it gets set or after it’s been stored on the computer. You could accomplish this second
part of the exercise; by using JavaScript or by viewing the cookies on the computer.
2. Create a webpage that sends a cookie with the cookie’s expiration date set ahead one
week, and set the secure flag. This page can be the same one you created for Exercise
1, but be sure to give the cookie a different name so that you’ve created two separate
cookies, one for each exercise. Also, be sure to enable the secure flag for the cookie in
this exercise, not for the cookie in Exercise 1.
3. Create a webpage that attempts to read the cookie with the secure flag set. Did you
receive the cookie? If not, what would you need to do to receive it?
4. Create a webpage that reads the cookie you created in Exercise 1. Use a for loop and an
if conditional to display an alert() dialog box when the cookie with the correct name is
found within the loop. Don’t display an alert() dialog box for any other cookies.
one day. Verify that the JavaScript code sent the cookie to the browser by viewing it as
it gets set or after it’s been stored on the computer. You could accomplish this second
part of the exercise; by using JavaScript or by viewing the cookies on the computer.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script>
var cookieName = "mycookie-1";
var cookieValue = "mycookievalue-1";
var date = new Date();
date.setTime(date.getTime() + (24 * 60 * 60 * 1000));
var expireDate = date.toGMTString();
var myCookie = cookieName + "=" + cookieValue + ";expires=" + expireDate;
document.cookie = myCookie;
// the following code is not part of exercise 1
// another cookie
var cookieName2 = "mycookie-another";
var cookieValue2 = "mycookievalue-another";
var date2 = new Date();
date2.setTime(date2.getTime() + (24 * 60 * 60 * 1000));
var expireDate2 = date2.toGMTString();
var myCookie2 = cookieName2 + "=" + cookieValue2 + ";expires=" + expireDate2 + ";path=/;domain=localhost;";
document.cookie = myCookie2;
alert(document.cookie);
</script>
</body>
</html>
2. Create a webpage that sends a cookie with the cookie’s expiration date set ahead one
week, and set the secure flag. This page can be the same one you created for Exercise
1, but be sure to give the cookie a different name so that you’ve created two separate
cookies, one for each exercise. Also, be sure to enable the secure flag for the cookie in
this exercise, not for the cookie in Exercise 1.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <script> var cookieName = "mycookie-2"; var cookieValue = "mycookievalue-2"; var date = new Date(); date.setTime(date.getTime() + (7 * 24 * 60 * 60 * 1000)); var expireDate = date.toGMTString(); var myCookie = cookieName + "=" + cookieValue + ";expires=" + expireDate + ";secure"; document.cookie = myCookie; </script> </body> </html>
3. Create a webpage that attempts to read the cookie with the secure flag set. Did you
receive the cookie? If not, what would you need to do to receive it?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script>
var cookies = document.cookie.split(";");
var cookLength = cookies.length;
for (var c = 0; c < cookLength; c++) {
alert(cookies[c]);
}
</script>
</body>
</html>
4. Create a webpage that reads the cookie you created in Exercise 1. Use a for loop and an
if conditional to display an alert() dialog box when the cookie with the correct name is
found within the loop. Don’t display an alert() dialog box for any other cookies.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script>
var cookies = document.cookie.split(";");
var cookLength = cookies.length;
for (var c = 0; c < cookLength; c++) {
var pairs = cookies[c].split("=");
var cookieName = pairs[0];
var cookieValue = pairs[1];
// display only the cookie with name of "mycookie-1"
if (pairs[0] === "mycookie-1") {
alert("Name: " + cookieName + " -> " + "Value: " + cookieValue);
}
}
</script>
</body>
</html>
My solution to chapter 11 exercises of JavaScript Step by Step 2e
1. Create a webpage that contains an onclick event handler connected to a link using a
DOM 0 inline event. The event handler should display an alert stating “You Clicked
Here”.
shown in ehandler.js (in the companion content) and connect the same click/onclick
event to display the alert created in Exercise 1.
new tab.
DOM 0 inline event. The event handler should display an alert stating “You Clicked
Here”.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="#" onclick="alert('You Clicked Here');">This is a link</a>
</body>
</html>
2. Change the webpage created in Exercise 1 to use the newer style of event handlingshown in ehandler.js (in the companion content) and connect the same click/onclick
event to display the alert created in Exercise 1.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="../../Scripts/ehandler.js" type="text/javascript"></script>
</head>
<body>
<a id="link1" href="#">This is a link</a>
<script type="text/javascript">
function showAlert() {
alert("You Clicked Here");
};
var link1 = document.getElementById("link1");
EHandler.add(link1, "click", showAlert);
</script>
</body>
</html>
3. Create a webpage with a link to http://www.microsoft.com. Make that link open in anew tab.
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <a href="http://www.microsoft.com." target="_blank">http://www.microsoft.com</a> </body> </html>
Friday, March 22, 2013
My solution to chapter 10 exercises of JavaScript Step by Step 2e
This is my solution to Chapter 10 programming exercises of JavaScript Step by Step 2e.
1. Create a document containing a paragraph of text that you create and append using
the DOM. Create a link immediately after this paragraph that links to a site of your
choice, also using the DOM. Make sure that all the elements have id attributes.
JavaScript:
TypeScript:
2. Create a document with any elements you like, or use an existing HTML document that
contains id attributes in its elements. Retrieve two of those elements, make changes to
them, and put them back into the document. The type of change you make depends
on the type of element you choose. For example, if you choose an a element, you might
change the href; if you choose a p element, you might change the text.
JavaScript:
and two rows. Add some text in the table cells.
JavaScript:
1. Create a document containing a paragraph of text that you create and append using
the DOM. Create a link immediately after this paragraph that links to a site of your
choice, also using the DOM. Make sure that all the elements have id attributes.
JavaScript:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
// create <p> the append to body
var element = document.createElement("p");
element.setAttribute("id", "p1");
element.textContent = "I am a p";
document.body.appendChild(element);
// create <a> then append to body
element = document.createElement("a");
element.setAttribute("id", "a1");
element.setAttribute("href", "http://jeremiahflaga.blogspot.com");
element.textContent = "this is my blog";
document.body.appendChild(element);
</script>
</body>
</html>
TypeScript:
// create <p> the append to body
var element: HTMLParagraphElement = <HTMLParagraphElement>document.createElement("p");
element.setAttribute("id", "paragraph1");
element.textContent = "I am a paragraph";
document.body.appendChild(element);
// create <a> then append to body
var element2: HTMLAnchorElement= <HTMLAnchorElement>document.createElement("a");
element2.setAttribute("id", "anchor1");
element2.setAttribute("href", "http://jeremiahflaga.blogspot.com");
element2.textContent = "this is my blog";
document.body.appendChild(element2);
2. Create a document with any elements you like, or use an existing HTML document that
contains id attributes in its elements. Retrieve two of those elements, make changes to
them, and put them back into the document. The type of change you make depends
on the type of element you choose. For example, if you choose an a element, you might
change the href; if you choose a p element, you might change the text.
JavaScript:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<p id="p1">I am a p</p>
<a id="a1" href="http://jeremiahflaga.blogspot.com">this is my blog</a>
<script type="text/javascript">
// change text of <p>
var element = document.getElementById("p1");
element.textContent = "I am a p of exercise #2";
document.body.appendChild(element);
// change text of <a>
element = document.getElementById("a1");
element.setAttribute("href", "http://www.johnpapa.net/");
element.textContent = "Click here to go to John Papa's blog";
document.body.appendChild(element);
</script>
</body>
</html>
TypeScript: // change text of <p>
var element: HTMLParagraphElement = <HTMLParagraphElement>document.getElementById("p1");
element.textContent = "I am a p of exercise #2 - from typescript";
document.body.appendChild(element);
// change text of <a>
var element2: HTMLAnchorElement = <HTMLAnchorElement>document.getElementById("a1");
element2.setAttribute("href", "http://www.johnpapa.net/");
element2.textContent = "Click here to go to John Papa's blog - from typescript";
document.body.appendChild(element2);
3. Create a document by using the DOM that contains a table with at least two columns
and two rows. Add some text in the table cells.
JavaScript:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
// create <table> the append to <body>
var table = document.createElement("table");
document.body.appendChild(table);
table.setAttribute("border", 1);
// create <tr> (row) then append to <table>
var row = document.createElement("tr");
table.appendChild(row);
// create <td> (cell) then append to <tr>
var cell = document.createElement("td");
row.appendChild(cell);
cell.textContent = "Cell #1";
// create <tr> (row) then append to <table>
var row = document.createElement("tr");
table.appendChild(row);
// create <td> (cell) then append to <tr>
var cell = document.createElement("td");
row.appendChild(cell);
cell.textContent = "Cell #2";
</script>
</body>
</html>
TypeScript
// create <table> the append to <body>
var table: HTMLTableElement = <HTMLTableElement>document.createElement("table");
document.body.appendChild(table);
table.setAttribute("border", "1");
// create <tr> (row) then append to <table>
var row: HTMLTableRowElement = <HTMLTableRowElement>document.createElement("tr");
table.appendChild(row);
// create <td> (cell) then append to <tr>
var cell: HTMLTableCellElement = <HTMLTableCellElement>document.createElement("td");
row.appendChild(cell);
cell.textContent = "Cell #1 - from typescript";
// create <tr> (row) then append to <table>
row = <HTMLTableRowElement>document.createElement("tr");
table.appendChild(row);
// create <td> (cell) then append to <tr>
cell = <HTMLTableCellElement>document.createElement("td");
row.appendChild(cell);
cell.textContent = "Cell #2 - from typescript";
My solution to chapter 9 exercises of JavaScript Step by Step 2e
This is my solution to Chapter 9 programming exercises of JavaScript Step by Step 2e.
1. Use the availHeight and availWidth methods to determine whether a screen is at least 768 pixels high and 1024 pixels wide. If it’s not, display an alert() dialog box stating the size of the available screen.
JavaScript:
TypeScript: same as above
2. Alter the step-by-step exercise that used the location object to display an alert() dialog box based on the values of the query string. Specifically, display the word “Obrigado” if the country is specified as Brazil, and display “Thank you” if the country is Great Britain. Test these conditions.
JavaScript:
1. Use the availHeight and availWidth methods to determine whether a screen is at least 768 pixels high and 1024 pixels wide. If it’s not, display an alert() dialog box stating the size of the available screen.
JavaScript:
if (screen.availHeight < 768 && screen.availWidth < 1024) {
alert("Available height: " + screen.availHeight + "\n"
+ " Available width: " + screen.availWidth);
}
TypeScript: same as above
2. Alter the step-by-step exercise that used the location object to display an alert() dialog box based on the values of the query string. Specifically, display the word “Obrigado” if the country is specified as Brazil, and display “Thank you” if the country is Great Britain. Test these conditions.
JavaScript:
if (location.search) {
var querystring = decodeURI(location.search).substring(1);
var splits = querystring.split('&');
for (var i = 0; i < splits.length; i++) {
var splitpair = splits[i].split('=');
if (splitpair[0].toLowerCase() === 'country') {
if (splitpair[1].toLowerCase() === 'brazil') {
alert('Obrigado');
}
else if (splitpair[1].toLowerCase() === 'great britain') {
alert('Thanks you');
}
}
}
}
TypeScript:
if (location.search) {
var querystring: string = decodeURI(location.search).substring(1);
var splits: string[] = querystring.split('&');
for (var i = 0; i < splits.length; i++) {
var splitpair: string[] = splits[i].split('=');
if (splitpair[0].toLowerCase() === 'country') {
if (splitpair[1].toLowerCase() === 'brazil') {
alert('Obrigado');
}
else if (splitpair[1].toLowerCase() === 'great britain') {
alert('Thanks you');
}
}
}
}
Wednesday, March 13, 2013
My solutions to programming exercises in JavaScript Step by Step 2e - Chapters 4 to 8
Even though I have already studied JavaScript in the past, I have never really done programming exercises using it. So I solved the exercises of JavaScript Step by Step 2e.
Because I am also currently learning Typescript, I solved the exercises, starting on chapter four, using both JavaScript and TypeScript.
(You can learn about TypeScript in John Papa's Blog - http://www.johnpapa.net/typescriptpost/)
You can download my solutions to chapters 4 to 8 here.
Sample code (Chapter 8 Exercise #2)
2. Create an object to hold the names of three of your favorite songs. The objects should have properties containing the artist, the song length, and the title for each song.
JavaScript:
function Song(artist, length, title) {
this.artist = artist;
this.length = length;
this.title = title;
}
var songs = new Object;
songs.song1 = new Song("artist1", 101, "title1");
songs["song2"] = new Song("artist2", 102, "title2");
songs["song3"] = new Song("artist3", 103, "title3");
for (var i in songs) {
alert(i + "=" + songs[i].title);
}
TypeScript:
class Song {
private _title: string;
artist: string;
length: number;
constructor(artist: string, length: number, title: string) {
this.artist = artist;
this.length = length;
this._title = title;
}
get title(): string {
return this._title;
}
set title(value: string) {
if (value == undefined) throw 'value for title is undefined';
this._title = value;
}
}
var songs = new Object();
songs["song1"] = new Song("artist1", 101, "title1");
songs["song2"] = new Song("artist2", 102, "title2");
songs["song3"] = new Song("artist3", 103, "title3");
for (var i in songs) {
alert(i + "=" + songs[i].title);
}
Thursday, November 29, 2012
Simple Student Information System using ASP.NET MVC4 (w/ C#)
I created a practice project where I use my new knowledge on Entity Framework Code First, the Repository and Unit of Work patterns with ASP.NET MVC4 and Unit Testing including mocking with Moq.
I published it on GitHub.
(Not yet finished)(I think I am finished with the thing I wanted to practice on - using the Repository and Unit of Work patterns)
There are functionalities that are not yet implemented in this project:
1. Updating the list of Degrees
2. Updating the list of Subjects
3. Updating the list of Semesters, Periods and Levels
4. Roles and permissions - for now, anybody can register, login and update student records.
(also, Unit Testing is not yet completed)
I have to set aside this project for a while because there are other things I need to study.
If you are interested, you can view/download/fork it from here: https://github.com/jboyflaga/StudInfoSys.AspNetMvc4.git
I published it on GitHub.
There are functionalities that are not yet implemented in this project:
1. Updating the list of Degrees
2. Updating the list of Subjects
3. Updating the list of Semesters, Periods and Levels
4. Roles and permissions - for now, anybody can register, login and update student records.
(also, Unit Testing is not yet completed)
I have to set aside this project for a while because there are other things I need to study.
If you are interested, you can view/download/fork it from here: https://github.com/jboyflaga/StudInfoSys.AspNetMvc4.git
Subscribe to:
Posts (Atom)
