Introduction to Network Security – Part 3

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

Socket Programming

In networks applications, communications are almost always done using a client-server model.

A client will perform request for a service to the server, and receive a service from the server (which should be usually on). The only thing that the client needs to know is the address of the server and which port to use. Once the connection between the client and the server is establish, then the client and the server can send and receive information back and forwards. Eg. FTP client to a FTP server

Share

DNX: C#: Extension Methods

As you may know, Microsoft is getting into the open source community with the ASP.NET and DNX with the mono project.
The .NET Execution Environment (DNX) is a software development kit which allows you to run .NET applications on Windows, Mac, and Linux using different frameworks such as .NET framework, .NET Core, and Mono. However, everything are not roses. There are many incomplete libraries, incompatibilities, lack of documentation, and most of the examples such as doing SQL or SOAP do not work depending on which the library targets you are planning to code for. Therefore, I decided to test the basics on all the library targets. I am starting with DNX451.

Extension methods seems to be working fine in DNX451 with C#. Below is a code example for those who wish to play with it.

Program.cs

using System;

namespace ConsoleApp1 {
	
	public class Program {
		
		public void Main(string[] args){			
			Console.WriteLine("Main()");
			
			displayWhichDnxIsCompilingOn();
			
			new ExtensionMethodsExample.ExtensionMethodsExample();
						
		}
		
		private void displayWhichDnxIsCompilingOn(){
			#if DNX451
			Console.WriteLine("Compiled on DNX451: .NET Framework");
			#endif
			
			#if DNXCORE50
			Console.WriteLine("Compiled on DNXCORE50: .NET Core 5");
			#endif						
		}
		
	}
	
}
ExtensionMethodsExamples.cs

Share

Example of Coding on haXe (Heapsort, Binary Search) – Part 5

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

In this example you will see: Binary search by using heapsort for sorting.

example_5.hx:

/**
 * @author: Alejandro G. Carlstein R. M.
 */

class HeapSort{

	private var data : Array<Int>;
	private var heap_size : Int;
	private inline function leftChild(index : Int) : Int{ return (index << 1) + 1;	}
	private inline function rightChild(index : Int) : Int{ return (index << 1) + 2; }

	// Constructor ( ? means that items is optional)
	public function new(?data : Array<Int>){
		this.data = (data == null) ? new Array() : data;
	}

	public function getData() : Array<Int> {
		return data;
	}

	public function setData(data : Array<Int>) : Void {
		this.data = data;
	}

	public function sort() : Void{
		if(data.iterator().hasNext()){
			heap_size = data.length;
			buildMaxHeap();
			var index : Int = data.length - 1;
			while (index > -1){
				exchange(0, index);
				maxHeapify(0, --heap_size);
				--index;
			}
		}else{
			trace('There is no data to sort');
		}
	}

	private function buildMaxHeap() : Void{
		var index : Int = data.length >> 1;
		while (index > -1){
			maxHeapify(index, heap_size);
			--index;
		}
	}

	private function maxHeapify(index : Int, heapSize : Int) : Void{
		var largest : Int = index;
		var left : Int = leftChild(index);
		var right : Int = rightChild(index);	

		if (left < heapSize && data[left] > data[index])
			largest = left;

		if (right < heapSize && data[right] > data[largest])
			largest = right;

		if (largest != index){
			exchange(index, largest);
			maxHeapify(largest, heapSize);
		}
	}

	private function exchange(index_a : Int, index_b : Int) : Void{
		var temp_value : Int = data[index_a];
		data[index_a] = data[index_b];
		data[index_b] = temp_value;
	}

}

class BinarySearch{
	private var heapsort : HeapSort;
	private var data : Array<Int>;
	private function search(value : Int, start_index : Int, end_index : Int){
		var middle_index : Int = (start_index + end_index) >> 1;
		var was_found : Bool = false;
		if(start_index < end_index){
			if(data[middle_index] == value){
				return true;
			}else{
				if(data[middle_index] > value){
					was_found = search(value, start_index, middle_index);
				}else{
					was_found = search(value, middle_index + 1, end_index);
				}
			}
		}
		return was_found;
	}

	// Constructor ( ? means that items is optional)
	public function new(?data : Array<Int>){
		this.data = (data == null) ? new Array() : data;
		if (data != null) setData(data);
	}

	public function getData() : Array<Int> {
		return data;
	}

	public function setData(data : Array<Int>) : Void {
		if (data != null){
			heapsort = new HeapSort();
			heapsort.setData(data);
			heapsort.sort();
			data = heapsort.getData();
		}
	}

	public function doExist(value : Int) : Bool{
		return search(value, 0, data.length);
	}

}

class Example_5 {

	static function main(){

		var data : Array<Int> = [3, 7, 5, -1, 6, 1, -3];
		printData(data);

		trace('Binary Search:');
		var binarySearch = new BinarySearch(data);
		trace ('Do 3 exist? ' + binarySearch.doExist(3));
		trace ('Do 4 exist? ' + binarySearch.doExist(4));
		trace ('Do 7 exist? ' + binarySearch.doExist(7));

		data = binarySearch.getData();
		printData(data);		

	}

	private static function printData(data : Array<Int>){
		var iter = data.iterator();
		var index : Int = 0;
		trace('[DATA]');
		while (iter.hasNext()){
			trace('data[' + index++ + ']: ' + iter.next());
		}
	}

}

If you encounter any problems or errors, please let me know by providing an example of the code, input, output, and an explanation. Thanks.

Share

Cupid-4-Stupid, My First Android Application in the Android Market

Me and my friend, David Corrigan, spent more than three months working on our first Android application, Cupid-4-Stupid.

The idea of this project came from David and we both work together to make it true.

Our project allowed us to learn how application are build in Android plus how the android behaves.

We encounter many problems which allow us to learn a lot in a very short period of time.

Share

Notes: Operative Systems – Part 8

< Previous (Operative Systems – Part 7) | (Operative Systems – Part 9) Next >

NOTIFICATION: These notes are published for educational purposes. Using these notes is under your own responsibility and risk. These notes are given ‘as is’. I do not take responsibilities for how you use them.

PDF Content:

  • Memory management
  • Memory reference
  • Mapping
  • Physical address
  • Page directory
  • Page table
  • Page frame
  • Directory field, page field, offset
  • Segment table
  • Dead lock
  • File System (FS)
  • Common file attributes and operations
  • Mapped files
  • Hierarchical directory systems
  • File system layout
  • Implementing files

Operative_Systems_8

Share