Showing posts from January, 2015

PHP script for fetching 4GB file from URL to your Server

       Below is the php script for fetching 4GB file from URL to your Server. The ini_set(‘upload_max_filesize’, ‘5000M’), ini_set(‘post_max_size’, ‘5000M’) statements specifies the maximum size of the data to fetch/upload by the script, if we want to fetch file of size 10GB then we can easily do so simply by changing the 2nd parameter(size in megabytes) of this calls. Next important setting is set_time_limit (24 * 60 * 60) which specifies the maximum time in seconds for running this script  ( as downloading file size is more it takes more time). Note that this time totally depends on the size of the file you want to fetch and the network speed of your server.          If you are thinking of running this script on general hosting service (where network speed is less) then it requires more time to execute (may be in Hrs) so, accordingly  you should set execution time limit. I had tested it on my local machine as well as on hosting service although it takes more CPU resource but works f

Creating multithreaded web server in Java

      Web server is a application which runs on server machine and listens request from various clients on specific port and gives some specific response for each request. Web servers and client machines uses sockets for transferring data between each other. In general if we construct simple web server using single execution instance then it will be able to serve only one client at time, so if multiple clients wants connect to the server then other clients may need to wait. To resolve this problem we can construct multithreaded server, which will create and execute a single thread  for each individual request (may be from same client machine or different client machines). Coding this in Java is very easy as compared to other languages.   Java Code of a multithreaded web server available here is able to accept requests from other computers (clients) by using their browser to point towards the server host and, in return displays a web pages or images. Following are steps to create mul

Video Encryption using Caesar Cipher - Matlab Tutorial

  In this matlab tutorial we are going to see video encryption using Caesar cipher . In  cryptography , a  Caesar cipher , also known as  Caesar’s cipher , the  shift cipher ,  Caesar’s code  or  Caesar shift , is one of the simplest and most widely known  encryption  techniques. It is a type of  substitution cipher  in which each letter in the  plaintext  is replaced by a letter some fixed number of positions down the  alphabet . For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after  Julius Caesar , who used it in his private correspondence. Example:- The transformation can be represented by aligning two alphabets; the cipher alphabet is the plain alphabet rotated left or right by some number of positions. For instance, here is a Caesar cipher using a left rotation of three places, equivalent to a right shift of 23 (the shift parameter is used as the  key ): Plain:   ABCDEFGHIJKLMNOPQRSTUVWXYZ Cipher:   XYZABCDEFGHIJKLMN

Difference between IP Fragmentation and TCP Segmentation

     IP fragmentation occurs at Layer 3 (IP) and that TCP segmentation occurs at Layer 4 ( TCP ) . IP Fragmentation takes place when packets that are larger than the Maximum Transmission Unit ( MTU ) of an interface  are sent out this interface. These packets will have to be either fragmented, or discarded when they are sent out the interface. If the Don’t Fragment (DF) bit is not set in the IP header of the packet, the packet will be fragmented. If the DF bit is set in the IP header of the packet, the packet is dropped and an ICMP error message indicating the next-hop MTU value will be returned to the sender. All the fragments of an IP packet carry the same Ident in the IP  header, this allows the final receiver to reassemble the fragments into the original IP packet. Please see Resolve IP Fragmentation, MTU, MSS, and PMTUD Issues with GRE and IPSEC for more information.   TCP Segmentation takes place when when an application on an end station is sending data. The application dat

Matrix chain multiplication dynamic programming (C++ code)

#include<iostream>#include<cstdlib>#define SZ 10using namespace std;int table[SZ][SZ];int P[] = {1, 2, 3, 4, 3};int MCM(int i, int j){ if(i==j) return 0; else { int min = INT_MAX; for(int k=i;k<j;k++) // bug was here: for(int k=i;k<=j;k++) { if(table[i][k]==0) table[i][k] = MCM(i,k); if(table[k+1][j]==0) table[k+1][j] = MCM(k+1,j); int sum = table[i][k] + table[k+1][j] + P[i-1]*P[j]*P[k]; if(sum<min) min = sum; } return min; }}int main(){ int size = sizeof(P)/sizeof(P[0]); printf("Minimum number of mutiplications is %d",MCM(1,size-1)); return 0;}