Monday, October 22, 2012

Digital Signature


A digital signature is created with asymmetric or public-key cryptography. In the same way as signing your name to a document legally binds the document to you, a digital signature proves that a document belongs to a user. In addition, a digital signature provides other benefits beyond simply proving that a particular person sent a message.
A digital signature is able to prove that a message has not been changed, which means that it ensures the integrity of a message. It is also provides for non-repudiation, meaning it’s able to prevent a sender from claiming they did not send the message.
For example, if you want to send a digitally signed message to your bank; first you would create a hash of the message using a hashing algorithm like Message Digest 5 (MD5) or Secure Hash Algorithm (SHA). This hashed message is called a message digest. You would then encrypt the digest using your private key and this encrypted hash would be the digital signature of your message.
Both the message and the digital signature are sent to your bank.
In order for the bank to make sure that your message is authentic, they would retrieve your public key and decrypt your digital signature, which reveals the hash. The bank would then hash your message and compare it to the newly uncovered hash.
If the hashes do not match then the message was not sent by you or was changed in transit.
Keep in mind that the original message that you sent to the bank with the digital signature could still be read by others. In order to encrypt the message you would need to retrieve the bank’s public key from their certificate authority (CA) and encode your message. After that, the bank will be able to decode your message with their private key.

Tuesday, October 16, 2012

Java Classes

Java Classes



C++ vs. Java


Java is similar to C++ in many ways. The first is the syntax of the language. Semicolons are required to end lines just like C++. There are also many similar structures such as arrays, classes and functions (or methods as they are called in java).

There are differences however. Most noticeably, java is strictly an Object Oriented Language, meaning it is made up entirely of classes (objects). There are no exceptions to this in this language.

Another big difference between the two is that there is no pointers in java! Everything is done "behind closed doors" when dealing with addressing and arrays.

Let's continue on and see how to define a simple program.

Classes


Since java is made up entirely of classes, all programs will be made up of classes. The overall rule is that whatever your class name is, the name MUST MATCH YOUR FILENAME. If not, when compiling it, there will be an error.

Here is the simplest program that can be made:
public class Hello{
public static void main(String args[]){
System.out.println("Hello!");
}
}

Wow! Short and sweet. It will print out a "Hello" message on screen. In this program of just 3 lines, so much has happened. Let's observe.

First, there are no include statements like C++. In java, a program can be written without anything in the head of the document.

Second, the "public class Hello" is of the following format:
keyword class name

where keyword is either public, private or protected, and name is the name of the class. The keyword public allows any java class to view the data (hence being public). There is a rule though; the class with the main method that will get the program running MUST be declared public. To declare a class private is a silly thing to do but not invalid either. Private is just the opposite of public in the sense that you cannot use it directly between classes. Variables or objects declared private can only be used within their own class.

Thirdly, the main method declaration is always of that heading. This is not something you can change in a program. The main method will take a single argument, a String array called args[] which will take, as it's elements in the array, any command-line argument you give it. The array is of the object type String (see tutorial 3).

Finally, the System.out.println() statement will be used for output. The println() means "print line", as this will print a string(s) and go to the next line. This is like the C++ "endl". To be more general, any output statement is contained in the System.out set of classes. There is also a System.out.print() that will not print a new line.

Compiling programs


Now that we have our first program in java, we need to know how to compile it. The first thing is to know that java is run on a virtual machine. A virtual machine is universal to a computer and can run code for a specific task. or programming language.

Here is how to compile the java program:
javac name.java

where javac is the java compiler itself, and name is the appropriate name of the program ( here Arguments). By pressing the enter key, the program will compile and will translate into virtual machine instructions.

Once successfully compiled, run the following command in the same directory where you compiled the program.

Command-line arguments


As mentioned before, java can take command line arguments. Each of the arguments will be separated by a single space when entered on the command line. There is another rule; each argument is treated AS A STRING. Say that you need a number as an argument. Then, the number must be parsed to that type. The example below will demonstrate command line arguments.

Example 1:
Command line arguments


The purpose of this program is to demonstrate the use of command line arguments. Here, the user will enter their full name (first and last) followed by their age.
public class Arguments{
public static void main(String args[]){

if(args.length < 3){
System.out.println("Too few arguments.");
System.out.println("Enter the first name,");
System.out.println("Then the last name,");
System.out.println("Then the age.");
System.exit(1);
}

//correct input so preform the operations:

String name = args[0] + " " + args[1];
int age = Integer.parseInt(args[2]);

System.out.println("Hello " + name + ". You are "
+ age + " years old!");

} //main
} //class

Again, a short program but a lot happening. Let's look at some new things introduced here.

First, the if statement will check if the amount of arguments in the array is less than the number required. If true, then the series of instructions will be printed out, then the program will terminate. The exit statement is again contained in the System class. If the statement is false, it is implied that there are the correct number of arguments so proceed with the program.

Next, there are two variables at work here, a string variable called name and an integer variable called age. Let's look at the name variable. Notice that it will concatenate both args[0] and args[1] in addition to a space, by the + operator. In java, the + operator functions as the String concatenator as well as the arithmetic operator.

Next, the age variable will need to be parsed to an integer type. The third argument args[2] will contain the number for the age. As mentioned earlier, the parse method of a class will convert the argument to that type. Most numeric classes have this (Double, Float, Integer etc...). Notice that the name of the class begins with an uppercase letter. Notice the same for the String class. That is a feature of java in the sense of class names. These are called wrapper classes.

Finally, the program will output a simple message to the screen displaying the full name and age of the user.

You can run the above program with the following command line:
java Arguments John Doe 22

The output from that action will be: Hello John Doe. You are 22 years old!



Example 2:
Command line arguments II


The purpose of this program is to demonstrate the use of command line arguments. Here, the user will enter their full name (first and last) followed by their age.
public class Arguments2{
public static void main(String args[]){

if(args.length < 3){
System.out.println("Too few arguments.");
System.out.println("Enter 3 numbers to see,");
System.out.println("Their average.");
System.exit(1);
}

//correct input so preform the operations:
int n1 = Integer.parseInt(args[0]);
int n2 = Integer.parseInt(args[1]);
int n3 = Integer.parseInt(args[2]);

double avg = ((double) (n1+n2+n3))/3.0;
System.out.println("The average is: " + avg);

}
}

You can run the above program with the following command line:
java Arguments 21 22 23

The output from that action will be: The average is: 22

Java Classes

Java Classes



C++ vs. Java


Java is similar to C++ in many ways. The first is the syntax of the language. Semicolons are required to end lines just like C++. There are also many similar structures such as arrays, classes and functions (or methods as they are called in java).

There are differences however. Most noticeably, java is strictly an Object Oriented Language, meaning it is made up entirely of classes (objects). There are no exceptions to this in this language.

Another big difference between the two is that there is no pointers in java! Everything is done "behind closed doors" when dealing with addressing and arrays.

Let's continue on and see how to define a simple program.

Classes


Since java is made up entirely of classes, all programs will be made up of classes. The overall rule is that whatever your class name is, the name MUST MATCH YOUR FILENAME. If not, when compiling it, there will be an error.

Here is the simplest program that can be made:
public class Hello{
public static void main(String args[]){
System.out.println("Hello!");
}
}

Wow! Short and sweet. It will print out a "Hello" message on screen. In this program of just 3 lines, so much has happened. Let's observe.

First, there are no include statements like C++. In java, a program can be written without anything in the head of the document.

Second, the "public class Hello" is of the following format:
keyword class name

where keyword is either public, private or protected, and name is the name of the class. The keyword public allows any java class to view the data (hence being public). There is a rule though; the class with the main method that will get the program running MUST be declared public. To declare a class private is a silly thing to do but not invalid either. Private is just the opposite of public in the sense that you cannot use it directly between classes. Variables or objects declared private can only be used within their own class.

Thirdly, the main method declaration is always of that heading. This is not something you can change in a program. The main method will take a single argument, a String array called args[] which will take, as it's elements in the array, any command-line argument you give it. The array is of the object type String (see tutorial 3).

Finally, the System.out.println() statement will be used for output. The println() means "print line", as this will print a string(s) and go to the next line. This is like the C++ "endl". To be more general, any output statement is contained in the System.out set of classes. There is also a System.out.print() that will not print a new line.

Compiling programs


Now that we have our first program in java, we need to know how to compile it. The first thing is to know that java is run on a virtual machine. A virtual machine is universal to a computer and can run code for a specific task. or programming language.

Here is how to compile the java program:
javac name.java

where javac is the java compiler itself, and name is the appropriate name of the program ( here Arguments). By pressing the enter key, the program will compile and will translate into virtual machine instructions.

Once successfully compiled, run the following command in the same directory where you compiled the program.

Command-line arguments


As mentioned before, java can take command line arguments. Each of the arguments will be separated by a single space when entered on the command line. There is another rule; each argument is treated AS A STRING. Say that you need a number as an argument. Then, the number must be parsed to that type. The example below will demonstrate command line arguments.

Example 1:
Command line arguments


The purpose of this program is to demonstrate the use of command line arguments. Here, the user will enter their full name (first and last) followed by their age.
public class Arguments{
public static void main(String args[]){

if(args.length < 3){
System.out.println("Too few arguments.");
System.out.println("Enter the first name,");
System.out.println("Then the last name,");
System.out.println("Then the age.");
System.exit(1);
}

//correct input so preform the operations:

String name = args[0] + " " + args[1];
int age = Integer.parseInt(args[2]);

System.out.println("Hello " + name + ". You are "
+ age + " years old!");

} //main
} //class

Again, a short program but a lot happening. Let's look at some new things introduced here.

First, the if statement will check if the amount of arguments in the array is less than the number required. If true, then the series of instructions will be printed out, then the program will terminate. The exit statement is again contained in the System class. If the statement is false, it is implied that there are the correct number of arguments so proceed with the program.

Next, there are two variables at work here, a string variable called name and an integer variable called age. Let's look at the name variable. Notice that it will concatenate both args[0] and args[1] in addition to a space, by the + operator. In java, the + operator functions as the String concatenator as well as the arithmetic operator.

Next, the age variable will need to be parsed to an integer type. The third argument args[2] will contain the number for the age. As mentioned earlier, the parse method of a class will convert the argument to that type. Most numeric classes have this (Double, Float, Integer etc...). Notice that the name of the class begins with an uppercase letter. Notice the same for the String class. That is a feature of java in the sense of class names. These are called wrapper classes.

Finally, the program will output a simple message to the screen displaying the full name and age of the user.

You can run the above program with the following command line:
java Arguments John Doe 22

The output from that action will be: Hello John Doe. You are 22 years old!



Example 2:
Command line arguments II


The purpose of this program is to demonstrate the use of command line arguments. Here, the user will enter their full name (first and last) followed by their age.
public class Arguments2{
public static void main(String args[]){

if(args.length < 3){
System.out.println("Too few arguments.");
System.out.println("Enter 3 numbers to see,");
System.out.println("Their average.");
System.exit(1);
}

//correct input so preform the operations:
int n1 = Integer.parseInt(args[0]);
int n2 = Integer.parseInt(args[1]);
int n3 = Integer.parseInt(args[2]);

double avg = ((double) (n1+n2+n3))/3.0;
System.out.println("The average is: " + avg);

}
}

You can run the above program with the following command line:
java Arguments 21 22 23

The output from that action will be: The average is: 22

Abstract methods & Interfaces

Abstract methods & Interfaces


Interfaces


When dealing with an abstract class, we sometimes see what's called an interface. An interface is a definition of all abstract methods however, unlike abstract methods within an abstract class, these methods defined in the interface can be used in any other class, regardless of being abstract or not.

Here is how to define an interface:

interface Name {
//methods here
}


The methods that are defined in the interface DO NOT need the abstract keyword with them.

In order for a class to use an interface, it must use the keyword implements in it's class header. Here is the definition:

public class Name implements interfaceName {
//code here
}


where Name is the name of the class and interfaceName is the name of the interface you will be implementing.

By default, all methods in an interface contain the keywords abstract public before each definition so these are not needed. You also cannot make the methods private or protected as this is not allowed in Java interfaces.

Let's look back at the previous chapter's example of the Food stores. Here is the full example using an interface:

Example 1:
Simple Interface example



public interface Slogan {
String slogan();
}

public abstract class FoodStore implements Slogan{
private String name;
private int opened;

public FoodStore(String n, int o){
if(n == null)
throw new IllegalArgumentException("No name given!");
else if(o < 0 || o > 2010)
throw new IllegalArgumentException("Bad opening!");
else{
name = n;
opened = o;
}
} //constructor

public String toString(){
return("Name: " + name + "nOpened: " + opened);
}
} //class

public class BestFoods extends FoodStore {
private String slogan = "The best food anywhere!";

public BestFoods(String n, int o){
super(n,o);
}

//implements the slogan() method from the interface:
public String slogan(){
return slogan;
}
} //class

public class OldFoods extends FoodStore{
private String slogan = "The oldest food store around!";

public OldFoods(String n, int o){
super(n,o);
}

//implements the slogan() method:
public String slogan(){
return slogan;
}
}

public class WholesomeFoods extends FoodStore {
private String slogan = "Mmmmmm, delicious!";

public WholesomeFoods(String n, int o){
super(n,o);
}

//implements the slogan() method:
public String slogan(){
return slogan;
}
}

public class Stores{
public static void main(String args[]){
FoodStore fs[] = new FoodStore[3];

fs[0] = new BestFoods("Best", 1956);
fs[1] = new OldFoods("Old", 1944);
fs[2] = new WholesomeFoods("Whole", 1987);

for(int i = 0; i < 3; i++)
System.out.println(fs[i] + "nSlogan: "
+ fs[i].slogan() + "n");

} //main
} //class


Since each subclass is inheriting all methods from the super class FoodStore, it is not necessary to place the implements Slogan in each subclass. If you did that, you would get an error citing that the method from the interface is undefined and the super class must implement the interface.

The output is also the same as the last chapter. All we did was change the abstract method in the class to an interface.


Interface constants


Constants can be placed in an interface. This is perfectly legal in Java.

Here is an interface example that uses a constant:

public interface Calendar {
int MONTHS = 12;
int DAYS = 365;
}

public class Year implements Calendar{
public static void main(String args[]){
int m = 12;
int d = 366;

	if(d == DAYS)
System.out.println("Equal days!");
if(m == MONTHS)
System.out.println("Equal months!");

} //main
} //class


The output would simply be "Equal months!"

Abstract methods & Interfaces

Abstract methods & Interfaces


Interfaces


When dealing with an abstract class, we sometimes see what's called an interface. An interface is a definition of all abstract methods however, unlike abstract methods within an abstract class, these methods defined in the interface can be used in any other class, regardless of being abstract or not.

Here is how to define an interface:

interface Name {
//methods here
}


The methods that are defined in the interface DO NOT need the abstract keyword with them.

In order for a class to use an interface, it must use the keyword implements in it's class header. Here is the definition:

public class Name implements interfaceName {
//code here
}


where Name is the name of the class and interfaceName is the name of the interface you will be implementing.

By default, all methods in an interface contain the keywords abstract public before each definition so these are not needed. You also cannot make the methods private or protected as this is not allowed in Java interfaces.

Let's look back at the previous chapter's example of the Food stores. Here is the full example using an interface:

Example 1:
Simple Interface example



public interface Slogan {
String slogan();
}

public abstract class FoodStore implements Slogan{
private String name;
private int opened;

public FoodStore(String n, int o){
if(n == null)
throw new IllegalArgumentException("No name given!");
else if(o < 0 || o > 2010)
throw new IllegalArgumentException("Bad opening!");
else{
name = n;
opened = o;
}
} //constructor

public String toString(){
return("Name: " + name + "nOpened: " + opened);
}
} //class

public class BestFoods extends FoodStore {
private String slogan = "The best food anywhere!";

public BestFoods(String n, int o){
super(n,o);
}

//implements the slogan() method from the interface:
public String slogan(){
return slogan;
}
} //class

public class OldFoods extends FoodStore{
private String slogan = "The oldest food store around!";

public OldFoods(String n, int o){
super(n,o);
}

//implements the slogan() method:
public String slogan(){
return slogan;
}
}

public class WholesomeFoods extends FoodStore {
private String slogan = "Mmmmmm, delicious!";

public WholesomeFoods(String n, int o){
super(n,o);
}

//implements the slogan() method:
public String slogan(){
return slogan;
}
}

public class Stores{
public static void main(String args[]){
FoodStore fs[] = new FoodStore[3];

fs[0] = new BestFoods("Best", 1956);
fs[1] = new OldFoods("Old", 1944);
fs[2] = new WholesomeFoods("Whole", 1987);

for(int i = 0; i < 3; i++)
System.out.println(fs[i] + "nSlogan: "
+ fs[i].slogan() + "n");

} //main
} //class


Since each subclass is inheriting all methods from the super class FoodStore, it is not necessary to place the implements Slogan in each subclass. If you did that, you would get an error citing that the method from the interface is undefined and the super class must implement the interface.

The output is also the same as the last chapter. All we did was change the abstract method in the class to an interface.


Interface constants


Constants can be placed in an interface. This is perfectly legal in Java.

Here is an interface example that uses a constant:

public interface Calendar {
int MONTHS = 12;
int DAYS = 365;
}

public class Year implements Calendar{
public static void main(String args[]){
int m = 12;
int d = 366;

	if(d == DAYS)
System.out.println("Equal days!");
if(m == MONTHS)
System.out.println("Equal months!");

} //main
} //class


The output would simply be "Equal months!"

Java Random numbers

Java Random numbers


In Java, as well as any other programming language, you can generate a random number or sequence of random numbers. Here, it involves the use of one library of Java; the util library.

You need to import the library in order to use the random number feature:

import java.util.Random;


Random Methods


Here is how to create a new Random object in Java:

Random name = new Random();


Where name is an appropriate name for the Random object. Once declared, you can begin to generate a random number by making use of an appropriate method. Here is a short list that you will make the most use of when dealing with random numbers:

int nextInt()


This method will return a pseudorandom integer. This will cover all 232 possibilities of integers (both positive and negative).

int nextInt(int range)


This method will return a pseudorandom integer in the range: 0 <= x < range. Notice that the range is not included and 0 is. So say that you wanted to go from 1 to 10. You need to avoid 0 in that mix and you need to include the topmost value range. This is a good way of doing that:

int num = r.nextInt(10) + 1;


So even if 9 is generated, it will add 1 and make it 10 and similarly with 0, it will make it 1.

double nextDouble()
float nextFloat()


This will generate numbers in the range 0.0 to 1.0 inclusive.

long nextLong()


This will generate random numbers in the range 2^64 based on the long type.

boolean nextBoolean()


This will generate either true or false respectively.

Here is an example program that will fill an array with random numbers:

Example 1:
Random Arrays



import java.util.Random;
public class ArrayRandom{
public static void main(String args[]){
Random r = new Random();
int arr[] = new int[20];

for(int i = 0; i < 20; i++){
//random numbers from 1 to 10:
arr[i] = r.nextInt(10) + 1;
}

for(int i = 0; i < 20; i++){
System.out.print(arr[i] + " ");
}
} //main
} //class


The program simply places random numbers from 1 to 10 inside the array called arr. It will output the values in the array in the second program. This is a simple program to see how random numbers work. Run the program multiple times to see the different numbers appear.



Example 2:
Random Array's 2



import java.util.Random;
public class ArrayRandom2{
public static void main(String args[]){
Random r = new Random();
int arr[] = new int[25];

for(int i = 0; i < 1000; i++){
//random numbers from 1 to 10:
arr[r.nextInt(25)] ++;
}

for(int i = 0; i < 25; i++){
System.out.println(i + " was generated " +
arr[i] + " times.");
}
} //main
} //class


This program will keep track of how many times a random number was drawn. This will increment the appropriate place in the array. The generated number itself will be the index of the array. One possible output can be:

0 was generated: 33 times.
1 was generated: 33 times.
2 was generated: 43 times.
3 was generated: 44 times.
4 was generated: 45 times.
5 was generated: 39 times.
6 was generated: 44 times.
7 was generated: 40 times.
8 was generated: 41 times.
9 was generated: 43 times.
10 was generated: 37 times.
11 was generated: 38 times.
12 was generated: 42 times.
13 was generated: 37 times.
14 was generated: 38 times.
15 was generated: 42 times.
16 was generated: 30 times.
17 was generated: 37 times.
18 was generated: 42 times.
19 was generated: 38 times.
20 was generated: 33 times.
21 was generated: 52 times.
22 was generated: 45 times.
23 was generated: 51 times.
24 was generated: 33 times.


The output will be different each time the program is run.



Example 3:
Random Stars



import java.util.Random;
public class RandomStars{
public static void main(String args[]){
Random r = new Random();
int num = 0;

for(int i = 0; i < 25; i++){
//random numbers from 0 to 15:
num = r.nextInt(16);
for(int j = 0; j < num; j++)
System.out.print("*");
System.out.println();
}
} //main
} //class


The program will simply output rows of stars to the screen 25 times. However, you may not see 25 rows since the inner loop will strictly be less than the generated number. If the random number is 0, the loop will not run and leave a blank row.

One possible output is this:

****
**

*
********
****
**
************
*******

***

*******
****

*********
*****
*****
***

********
*******
****
**

Another possible output is this:

*********
****
******
**
******
***
*********
********
********
****
***
************
**
*******
********
***
*************
*****
*********
***
******
**********
********
******
**


Java Random numbers

Java Random numbers


In Java, as well as any other programming language, you can generate a random number or sequence of random numbers. Here, it involves the use of one library of Java; the util library.

You need to import the library in order to use the random number feature:

import java.util.Random;


Random Methods


Here is how to create a new Random object in Java:

Random name = new Random();


Where name is an appropriate name for the Random object. Once declared, you can begin to generate a random number by making use of an appropriate method. Here is a short list that you will make the most use of when dealing with random numbers:

int nextInt()


This method will return a pseudorandom integer. This will cover all 232 possibilities of integers (both positive and negative).

int nextInt(int range)


This method will return a pseudorandom integer in the range: 0 <= x < range. Notice that the range is not included and 0 is. So say that you wanted to go from 1 to 10. You need to avoid 0 in that mix and you need to include the topmost value range. This is a good way of doing that:

int num = r.nextInt(10) + 1;


So even if 9 is generated, it will add 1 and make it 10 and similarly with 0, it will make it 1.

double nextDouble()
float nextFloat()


This will generate numbers in the range 0.0 to 1.0 inclusive.

long nextLong()


This will generate random numbers in the range 2^64 based on the long type.

boolean nextBoolean()


This will generate either true or false respectively.

Here is an example program that will fill an array with random numbers:

Example 1:
Random Arrays



import java.util.Random;
public class ArrayRandom{
public static void main(String args[]){
Random r = new Random();
int arr[] = new int[20];

for(int i = 0; i < 20; i++){
//random numbers from 1 to 10:
arr[i] = r.nextInt(10) + 1;
}

for(int i = 0; i < 20; i++){
System.out.print(arr[i] + " ");
}
} //main
} //class


The program simply places random numbers from 1 to 10 inside the array called arr. It will output the values in the array in the second program. This is a simple program to see how random numbers work. Run the program multiple times to see the different numbers appear.



Example 2:
Random Array's 2



import java.util.Random;
public class ArrayRandom2{
public static void main(String args[]){
Random r = new Random();
int arr[] = new int[25];

for(int i = 0; i < 1000; i++){
//random numbers from 1 to 10:
arr[r.nextInt(25)] ++;
}

for(int i = 0; i < 25; i++){
System.out.println(i + " was generated " +
arr[i] + " times.");
}
} //main
} //class


This program will keep track of how many times a random number was drawn. This will increment the appropriate place in the array. The generated number itself will be the index of the array. One possible output can be:

0 was generated: 33 times.
1 was generated: 33 times.
2 was generated: 43 times.
3 was generated: 44 times.
4 was generated: 45 times.
5 was generated: 39 times.
6 was generated: 44 times.
7 was generated: 40 times.
8 was generated: 41 times.
9 was generated: 43 times.
10 was generated: 37 times.
11 was generated: 38 times.
12 was generated: 42 times.
13 was generated: 37 times.
14 was generated: 38 times.
15 was generated: 42 times.
16 was generated: 30 times.
17 was generated: 37 times.
18 was generated: 42 times.
19 was generated: 38 times.
20 was generated: 33 times.
21 was generated: 52 times.
22 was generated: 45 times.
23 was generated: 51 times.
24 was generated: 33 times.


The output will be different each time the program is run.



Example 3:
Random Stars



import java.util.Random;
public class RandomStars{
public static void main(String args[]){
Random r = new Random();
int num = 0;

for(int i = 0; i < 25; i++){
//random numbers from 0 to 15:
num = r.nextInt(16);
for(int j = 0; j < num; j++)
System.out.print("*");
System.out.println();
}
} //main
} //class


The program will simply output rows of stars to the screen 25 times. However, you may not see 25 rows since the inner loop will strictly be less than the generated number. If the random number is 0, the loop will not run and leave a blank row.

One possible output is this:

****
**

*
********
****
**
************
*******

***

*******
****

*********
*****
*****
***

********
*******
****
**

Another possible output is this:

*********
****
******
**
******
***
*********
********
********
****
***
************
**
*******
********
***
*************
*****
*********
***
******
**********
********
******
**