Saturday, December 5, 2020

Greedy Vs Dynamic Programming

 Have a look

What's a priority queue?

 'Ladies first' is an instance of 'min priority queue', where as a queue free from any such bias is a normal queue.

Difference between creating a heap and heapify

 Creating a Heap is inserting all the elements of a given array into an existing heap assuming the first element of the given array as the initial heap, where as Heapify is simply creating a CBT ( complete binary tree) with all the elements of the given array and then converting that CBT into a heap, by moving up from the last non-leaf node up to the root.

Why time complexity of Heapify is O(n)?

 Look at this first  then you may Have a look here also.

Harmonic progression this is needed to understand the above. 

Wednesday, November 4, 2020

Structured programming Vs object-oriented programming

 There is no formal definition of structured programming, but most agree that it must have a top-down design and use only the three types of logical structures :

1. Sequence (top-down): Statements are executed one after the other.

2. Decisoins (if-else): One of the several blocks of the program is executed based on a test or condition.

3. Iterations (loops ): One or more statements are executed repeatedly as long as a specified condition is met.

Object-Oriented programming:

Can be viewed as a collection of cooperating objects. We use a blend of traditional structured programming along with OOPs. 

An object is an encapsulation of data and code that operates on that data. It is the most effective style of programming for solving complex problems and implementing complex systems in computer softwares.

Tuesday, October 27, 2020

Drawing a circle using OpenGL

 // C program to demonstrate

// drawing a circle using

// OpenGL


#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color black as first

// 3 arguments all are 0.0

glClearColor(0.0, 0.0, 0.0, 1.0);


// making picture color green (in RGB mode), as middle argument is 1.0

glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 1 pixel

glPointSize(2.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(-780, 780, -420, 420);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POINTS);

float x, y, i;


// iterate y up to 2*pi, i.e., 360 degree

// with small increment in angle as

// glVertex2i just draws a point on specified co-ordinate

for ( i = 0; i < (2 * pi); i += 0.001)

{

// let 200 is radius of circle and as,

// circle is defined as x=r*cos(i) and y=r*sin(i)

x = 200 * cos(i);

y = 200 * sin(i);


glVertex2i(x, y);

}

glEnd();

glFlush();

}


int main (int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(1366, 768);

glutInitWindowPosition(0, 0);


// Giving name to window

glutCreateWindow("Circle Drawing");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}

Output:



Scanline Polygon Fill Algorithm

 


#include<GL/glut.h>

#include<stdio.h>

float x1,x2,x3,x4,y1,y2,y3,y4;


void draw_pixel(int x,int y)

{

    glColor3f(0.0,1.0,1.0);

    glPointSize(1.0);

    glBegin(GL_POINTS);

    glVertex2i(x,y);

    glEnd();

}


void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)

{

    float temp,x,mx;

    int i;


    if(y1>y2)

    {

        temp=x1,x1=x2,x2=temp;

        temp=y1,y1=y2,y2=temp;

    }


    if(y1==y2)

        mx=x2-x1;

    else

        mx=(x2-x1)/(y2-y1);


    x=x1;


    for(i=y1;i<=y2;i++)

    {

        if(x<(float)le[i]) le[i]=(int)x;

        if(x>(float)re[i]) re[i]=(int)x;

        x+=mx;

    }

}


void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)

{

    int le[500],re[500],i,j;


    for(i=0;i<500;i++)

        le[i]=500,re[i]=0;


    edgedetect(x1,y1,x2,y2,le,re);

    edgedetect(x2,y2,x3,y3,le,re);

    edgedetect(x3,y3,x4,y4,le,re);

    edgedetect(x4,y4,x1,y1,le,re);


    for(j=0;j<500;j++)

    {

        if(le[j]<=re[j])

            for(i=le[j];i<re[j];i++)

                draw_pixel(i,j);

    }

}



void display()

{

    //x1=250.0;y1=200.0;x2=150.0;y2=300.0;x3=250.0;

    //y3=400.0;x4=350.0;y4=300.0;

    x1=50.0;y1=300.0;x2=300.0;y2=250.0;x3=250.0;

    y3=70.0;x4=70.0;y4=90.0;

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINE_LOOP);

    glVertex2f(x1,y1);

    glVertex2f(x2,y2);

    glVertex2f(x3,y3);

    glVertex2f(x4,y4);

    glEnd();


    scanfill(x1,y1,x2,y2,x3,y3,x4,y4);


    glFlush();

}



void init()

{

    glClearColor(1.0,1.0,1.0,1.0);

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    gluOrtho2D(0.0,499.0,0.0,499.0);

}


int main(int argc,char **argv)

{

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

    glutInitWindowSize(500,500);


    glutCreateWindow("Scanline polgon fill algorithm");

    glutDisplayFunc(display);


    init();

    glutMainLoop();

    return 0;

}

Output:



Drawing a Wireframe using OpenGL

 


// C program to demonstrate

// drawing a hard wire house

// OpenGL

#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color grey as first

// 3 arguments all are 0.4

glClearColor(0.4, 0.4, 0.4, 0.4);


// making picture color green (in RGB mode), as middle argument is 1.0

    glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 2 pixel

glPointSize(2.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(0.0,200.0, 0.0,150.0);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_LINES);

//horizontal base of the house

glVertex2i(50,0);

glVertex2i(100,0);

//horizontal ceiling of the house

glVertex2i(50,50);

glVertex2i(100,50);

//left roof top

glVertex2i(50,50);

glVertex2i(75,100);

//right roof

glVertex2i(75,100);

glVertex2i(100,50);

//left wall

glVertex2i(50,0);

glVertex2i(50,50);

//right wall

glVertex2i(100,0);

glVertex2i(100,50);


//Door top

glVertex2i(65,40);

glVertex2i(85,40);

//Door left side

glVertex2i(65,40);

glVertex2i(65,0);

//Door right side

glVertex2i(85,40);

glVertex2i(85,0);

    //Roof Box top

    glVertex2i(65,65);

glVertex2i(85,65);

    //Roof Box bottom

    glVertex2i(65,55);

glVertex2i(85,55);

    //Roof Box left side

    glVertex2i(65,65);

glVertex2i(65,55);

    //Roof Box right side

    glVertex2i(85,65);

glVertex2i(85,55);

//Out Box bottom left

    glVertex2i(0,25);

glVertex2i(25,0);

//Out Box bottom right

    glVertex2i(50,25);

glVertex2i(25,0);

    //Out Box top left

    glVertex2i(25,50);

glVertex2i(0,25);

//Out Box top right

    glVertex2i(25,50);

glVertex2i(50,25);



glEnd();

glFlush();

}


int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(800,600);

glutInitWindowPosition(0,0);


// Giving name to window

glutCreateWindow("Drawing a Hard wire House");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}

Output:








Draw a circle inside a triangle using OpenGJ




// C program to demonstrate

// drawing a circle using

// OpenGL

#include<stdio.h>

#include<GL/glut.h>

#include<math.h>

#define pi 3.142857


// function to initialize

void myInit (void)

{

// making background color black as first

// 3 arguments all are 0.4

glClearColor(0.4, 0.4, 0.4, 1.0);


// making picture color green (in RGB mode), as middle argument is 1.0

//glColor3f(0.0, 1.0, 0.0);


// breadth of picture boundary is 1 pixel

glPointSize(1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


// setting window dimension in X- and Y- direction

gluOrtho2D(0.0,800.0, 0.0,600.0);

}


void display (void)

{

glClear(GL_COLOR_BUFFER_BIT);


glBegin(GL_LINES);

//set color to draw the triangle

glColor3f(1.0,0.5,0.0);

//first horizontal side of the triangle

glVertex2i(100,50);

glVertex2i(700,50);

//left side of the triangle

glVertex2i(100,50);

glVertex2i(400,500);

//third vertex

glVertex2i(400,500);

glVertex2i(700,50);


glEnd();


glBegin(GL_POINTS);

glColor3f(0.0, 1.0, 0.0);

float x, y, i;


// iterate y up to 2*pi, i.e., 360 degree

// with small increment in angle as

// glVertex2i just draws a point on specified co-ordinate

for ( i = 0; i < (2 * pi); i += 0.001)

{

// let 200 is radius of circle and as,

// circle is defined as x=r*cos(i) and y=r*sin(i)

x = 400+ 100 * cos(i);

y = 200+ 100 * sin(i);


glVertex2i(x, y);

}

glEnd();


glFlush();

}


int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(800,600);

glutInitWindowPosition(0, 0);


// Giving name to window

glutCreateWindow("Drawing Green Circle inside Orange Triangle");

myInit();


glutDisplayFunc(display);

glutMainLoop();

}



Output:



 

Cohen Line clipping algorithm

 



// C++ program to implement Cohen Sutherland algorithm

// for line clipping.

#include <iostream>

#include <GL/glut.h>

using namespace std;



// Defining region codes

const int INSIDE = 0; // 0000

const int LEFT = 1; // 0001

const int RIGHT = 2; // 0010

const int BOTTOM = 4; // 0100

const int TOP = 8; // 1000


// Defining x_max, y_max and x_min, y_min for

// clipping rectangle. Since diagonal points are

// enough to define a rectangle

const int x_max = 100;

const int y_max = 100;

const int x_min = 40;

const int y_min = 40;

int x1,x2,y1,y2;

// Function to compute region code for a point(x, y)

int computeCode(double x, double y)

{

// initialized as being inside

int code = INSIDE;


if (x < x_min) // to the left of rectangle

code |= LEFT;

else if (x > x_max) // to the right of rectangle

code |= RIGHT;

if (y < y_min) // below the rectangle

code |= BOTTOM;

else if (y > y_max) // above the rectangle

code |= TOP;


return code;

}


// Implementing Cohen-Sutherland algorithm

// Clipping a line from P1 = (x2, y2) to P2 = (x2, y2)

void cohenSutherlandClip(double x1, double y1,double x2, double y2)

{

// Compute region codes for P1, P2

int code1 = computeCode(x1, y1);

int code2 = computeCode(x2, y2);


// Initialize line as outside the rectangular window

bool accept = false;


while (true)

{

if ((code1 == 0) && (code2 == 0))

{

// If both endpoints lie within rectangle

accept = true;

break;

}

else if (code1 & code2)

{

// If both endpoints are outside rectangle,

// in same region

break;

}


}

if (accept)

{

cout <<"Line accepted from (" << x1 << ", "

<< y1 << " to "<< x2 << ", " << y2 << ") because its completely VISIBLE" << endl;

// Here the user can add code to display the rectangle

// along with the accepted (portion of) lines

}

else

        cout <<"Line rejected from (" << x1 << ", "

<< y1 << " to "<< x2 << ", " << y2 << ") because its completely INVISIBLE" << endl;

}


 void display()

 {

        glClear(GL_COLOR_BUFFER_BIT);

        glColor3f(0.0,1.0,0.0);

        glBegin(GL_LINES);

        glVertex2i(40,100);

        glVertex2i(40,10);

        glVertex2i(100,100);

        glVertex2i(100,10);


        glVertex2i(40,100);

        glVertex2i(100,100);

        glVertex2i(40,10);

        glVertex2i(100,10);


        glColor3f(1.0,0.0,0.0);

        //Visible line

        glVertex2i(50,60);

        glVertex2i(70,40);

        //Invisible line

        glVertex2i(150,100);

        glVertex2i(180,50);

        glEnd();

        glFlush();


 }

 void myInit(void)

        {


            glClearColor(0.0,0.0,0.0,1.0);


            glPointSize(2.0);

            glMatrixMode(GL_PROJECTION);


            glLoadIdentity();

            gluOrtho2D(0,200,0,200);


        }



// Driver code

int main(int argc, char**argv)

{

    cout<<" The coordinates of the clipping window are (40,100), (100,100), (100,10) and (40,40)"<<endl;

    // First Line segment

// P11 = (5, 5), P12 = (7, 7) completely VISIBLE(inside)

cohenSutherlandClip(50, 60, 70, 40);


// P11 = (5, 5), P12 = (7, 7) completely INVISIBLE(outside)

cohenSutherlandClip(150, 100, 180, 150);




    glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);


// giving window size in X- and Y- direction

glutInitWindowSize(400,400);

glutInitWindowPosition(0,0);


// Giving name to window

    glutCreateWindow("Cohen-Sutherland line clipping algorithm");

    myInit();


glutDisplayFunc(display);


glutMainLoop();


return 0;

}


output:



Thursday, October 8, 2020

Python String methods

Python methods for strings
  1.   title()
  2. capitalize()
  3. swapcase()
  4. find()
  5. count()
  6. replace()
  7. isalnum()
  8. format()

print(dir(variable_name)) gives all the functions that can be applied on the variable. If its a string variable, it will list all the functions applicable on strings. 

You can also use print(help(str)) go get all information about strings.

print(help.(str.find)) will give the details on how to use the find() function.

Python methods for objects:
  1. reverse()
  2. clear()
  3. add
  4. append()
  5. update()

Monday, October 5, 2020

MCA subject Video classes

  1. MCS  31 (Design and Analysis of Algorithms) 
    1. Introduction to Data Structures & Algorithms - IIT Delhi
    2. Introduction to Data Structures & Algorithms
    3. Sorting Algorithms & Asymptotic Analysis II - IGNOU
    4. Algorithmic Techniques for problem solving 2
    5. Stack Applications
    6. Queue Data Structure
    7. An introduction to trees
    8. DAA  - Abdul Bari
    9. DAA - Javatpoint
    10. Merge sort, how multiple recursion works under the hood  - Jenny's Lectures
    11. Shell sort - Jenny's Lectures
    12. Bubble sort - Jenny's Lectures
    13. TutorialsPoints - Analysis of  Algorithms
    14. Average case analysis - Abdul Bari
    15. Amortized analysis of Algorithms 
    16. Best First Search algorithm an example.
    17. Topological Sort or Ordering of a Graph  - Jenny's Lectures
    18. Probabilistic (randomized) Algorithms
    19. Genetic Algorithms - Nature inspired Algorithms IIT KGH
    20. TC - IITKGP 
    21. PDA Introduction - Neso Academy.
    22. Theory of Computation - Neso Academy
    23. Compiler Design IIT KGP
  2. MCS 33 (Advanced Discrete Mathematics - Recurrence Relations & Graph Theory
    1. Recurrence Relations
    2. Graph Theory - IIT KGP (Kharagpur)
    3. Tower of Hanoi
  3. MCS 34 (Software Engineerig)
    1. Software Engineering - IIT KGP
    2. Fact Finding Techniques 1
    3. Software Engineering Process An Overview - IGNOU
    4. Advanced Software Engineering Projects - IGNOU
    5. Spiral Life Cycles Models 
    6. Life cycle models 2 Win Win Spiral Model - IGNOU
  4. MCS 42 (Computer Networks & Distributed Systems)
    1. Cloud Computing & Distributed Systems IIT Patna
    2. Demystifying Networks IIT Bombay
  5. MCS 43 (Advanced Database Management Systems) 
    1. Advanced DBMS - limits of RDBMS
    2. Introduction to database systems IIT Madras
    3. Introduction to Relational Model/2 DBMS IIT Khg - Relational Algebra & its operations.
  6. MCS 51 (Advanced Java & Internet)
    1. Websites -1 - IGNOU
    2. Websites - 2 - IGNOU
    3. Servlets Basics - IGNOU
    4. Writing Servlets - IGNOU
    5. Session Tracking in Servlet programming - IGNOU
    6. Website management 1
    7. Website management 2
    8. Network Technology & Devices
    9. Basics of Internet
    10. Introduction to Computer & Networking
    11. Introduction to distributed systems - IGNOU
    12. Java Security
  7. MCS 52 (Management Information System)
    1. MIS - IIT Kharagpur
  8. MCS 53 (Computer Graphics)
    1. IIT - Guwahati
    2. Computer Graphics - Projections
    3. Computer Graphics - Transformation - IGNOU
    4. Multimedia Tutorials
  9. MCSE 003 (Artificial Intelligence)
    1. Fundamentals of AI - IIT Guwahati
    2. Introduction to Artificial Intelligence 2
    3. Knowledge Representation Part 1
    4. Symbolic Logic Knowledge Representation - IGNOU
    5. Fuzzy Logic why and what 1 - IGNOU
    6. Fuzzy Logic why and what 2 - IGNOU
    7. AI programming languages 1 Part 1 LISP 4- IGNOU
    8. AI languages LISP Artificial Intelligence
    9. AI programming languages 1 Part 2 - IGNOU
    10. AI programming LISP 1
    11. LISP part - 3 Artificial Intelligence 1 - IGNOU
    12. LISP Part - 3 Artificial Intelligence 2 - IGNOU
    13. LISP Part 5 - IGNOU
    14. Uncertain Knowledge & Reasoning 1
    15. Uncertain Knowledge & Reasoning 2
    16. AI programming language LISP 3 - IGNOU
    17. AI programming language LISP - 4 - IGNOU
    18. Introduction to PROLOG
    19. A Start informed search algorithm
    20. AO Star informed search algorithm also called as the AND-OR graphs.
    21. AI Education 4u series.
  10. MCSE 004 (Numerical & Statistical Computing)
    1. Scientific Computing using MATLAB - IIT Delhi
    2. Numerical & Statistical Techniques - IGNOU
    3. Numerical & Statistical Computing 2
    4. Random Variables and Probability 3
    5. Normal Distribution
    6. Random variables & Probability distributions 4
    7. Numerical and Statistical Techniques 6
  11. MCSE 011 ( Parallel Computing a.k.a. Super Computing)
    1. Parallel Algorithms - IIT Guwahati
    2. Introduction to Parallel Programming in Open MP - IIT Delhi
    3. Parallel Algorithms


Thursday, October 1, 2020

Top 10 online courses for learning DSA

 Top10 online courses for DSA

Retaining the color code in Notepad++

 When you open a supported file format in Notepad++, it performs syntax highlighting where it formats the text with various colors to make reading easier.

However, when you save the file or copy text from it to an external program, all of the syntax highlighting and formatting is lost, and the text will take on formatting of the program you’re pasting into. This shouldn’t be surprising as the program is basically a plain-text editor. The syntax highlighting you see is just a visual enhancement. Although, there is a way to retain this formatting, i.e. if you have NppExport plugin installed. Latest builds of Notepad++ ships with this plugin. If you don’t have NppExport installed, you can download it through the inbuilt plugin manager.

When you have it ready, highlight the code that you want to copy, then go to 

Plugins (on the menu bar) > Select NppExport > Copy all formats to clipboard

Now when you paste the code into a program that supports rich text formatting, for example Microsoft Word or Evernote, all of the formatting should be retained.

Tuesday, September 29, 2020

Competitive Programming

 In CP there are two types of topics - general techniques (like DP, greedy, brute force) and particular algorithms (like graph, math, data structures).

Friday, September 25, 2020

How to become a great programmer

Find how to become a great programmer https://qr.ae/pNo38T 

Default Route in a Routing device

Understanding the default route: 

A default route is the route that takes effect when no other route is available for an IP destination address.

If a packet is received on a routing device, the device first checks to see if the IP destination address is on one of the device’s local subnets. If the destination address is not local, the device checks its routing table. If the remote destination subnet is not listed in the routing table, the packet is forwarded to the next hop toward the destination using the default route. The default route generally has a next-hop address of another routing device, which performs the same process. The process repeats until a packet is delivered to the destination.

The route evaluation process in each router uses the longest prefix match method to obtain the most specific route. The network with the longest subnet mask that matches the destination IP address is the next-hop network gateway.

The default route in IPv4 is designated as 0.0.0.0/0 or simply 0/0. Similarly, in IPv6, the default route is specified as ::/0. The subnet mask /0 specifies all networks, and is the shortest match possible. A route lookup that does not match any other route uses this route if it is configured and active in the routing table. To be active, the configured next-hop address must be reachable.

Administrators generally point the default route toward the routing device that has a connection to a network service provider. Therefore, packets with destinations outside the organization's local area network, typically destinations on the Internet or a wide area network, are forwarded to the routing device with the connection to that provider. The device to which the default route points is often called the default gateway.

Sources:

https://www.juniper.net/documentation/en_US/junos/topics/concept/default-route-understanding.html

https://www.computernetworkingnotes.com/ccna-study-guide/default-routes-in-cisco-routers-explained.html

Monday, September 14, 2020

Open source PHP projects

 Complete list of good 50-most-popular-php-projects-on-github.

Genesis of the word 'CAPCHA'

 CAPCHA - "Completely Automatic Public turing test to tell Computers and Humans Apart".

You can also think of it as 

CAPCHA = CAPTURE + GOTCHA

'gotcha' means - I have got you (used to express satisfaction at having captured or defeated someone or uncovered their faults).

This word was coined by Manuel Blum (born 1938) is a professor of computer science at Carnegie Mellon University, Pittsburgh, Pennsylvania.

Machine Learning: Image recognition

 An-image-recognition-classifier-using-cnn-keras-and-tensorflow-backend-31fda7856906

Saturday, September 12, 2020

Web Services

 What are web services? How it works?

Common Architecture flaws is a computer security

 Types of security attacks

Asynchronous Attack in Computer Security

 video on Asynchronous attack

Trap-doors or Back-doors or Maintenance Hook in computer security

 Trap door concept.


What is a 'Internet Covert Channel'?

 covert channel is an evasion or attack technique that is used to transfer information in a secretive, unauthorized or illicit manner. A covert channel can be used to extract information from or implant information into an organization. An Internet covert channel is the digital equivalent of a briefcase with a secret compartment that a spy might use to slip sensitive documents past security guards into or out of a secure facility. An attacker can use Internet covert channels to transmit sensitive documents unobserved – in this case, bypassing network security measures rather than bypassing security guards. And just as a spy can use that same secret compartment to conceal a weapon from security guards when entering a secure facility, an attacker can use an Internet covert channels to conceal a cyberweapon, for example, a download of malware from an external server onto a host within an organization’s private network.

Internet covert channels can use conventional Internet protocols in unconventional ways. The channel endpoints – an infected computer and the attacker’s command and control computer – must use this evasion or attack software that recognizes and processes these unconventional techniques. Either a user or malware can install this software, or an attacker can install the software using a remote administration tool (RAT). Internet covert channels are different from encrypted tunnels. They can and do transfer information in plain text, but they’re unobserved. While they do not require encryption methods or keys, certain covert channels employ encryption or other means to obfuscate data.

source https://www.icann.org/news/blog/what-is-an-internet-covert-channel

In computer security, a covert channel is a type of attack that creates a capability to transfer information objects between processes that are not supposed to be allowed to communicate by the computer security policy

A covert channel is so called because it is hidden from the access control mechanisms of secure operating systems since it does not use the legitimate data transfer mechanisms of the computer system (typically, read and write), and therefore cannot be detected or controlled by the security mechanisms that underlie secure operating systems.

 Covert channels are exceedingly hard to install in real systems, and can often be detected by monitoring system performance.

Covert channels can tunnel through secure operating systems and require special measures to control. Covert channel analysis is the only proven way to control covert channels.

 There are two kinds of covert channels:

  • Storage channels - Communicate by modifying a "storage location", such as a hard drive.
  • Timing channels - Perform operations that affect the "real response time observed" by the receiver.

Link to Excellent explanation of covert-channels

Covert Channels are not efficient in terms of throughput. But they are quite good at hiding their presence, hence providing security by obscurity. If a covert channel is detected, it’s very likely to be entirely compromised unless the content is further protected by encryption.

A network protocol is basically a contract between a sender and a receiver, where the sender sends structured information in a format that can be interpreted by the receiver. This ‘structure’ of the information is defined as the ‘network packet’ structure. A packet mainly consists of 3 parts which are called the and an optional Firewalls and Intrusion Detection Systems (IDS) are particularly interested in the data section of a packet as it carries the actual payload of the transmission.

Video links on Covert channels

Thursday, August 20, 2020

Global variables in Python

 https://www.programiz.com/python-programming/global-keyword

Recursive problems: Example solutions

Problem 1:

'n' number of people are standing in a queue. People standing on even positions are selected. Of the selected people a queue is formed and again out of these only people on even position are selected. This continues until we are left with one person. Find out the position of that person in the original queue.

Solution:

#Python code

#declare a Global variable to store the last base case value of the recursion in it.

h = []

# The recursive function definition

def rec(l):

    global h

    m = []

    #see the list after each recursive call

    print(l)

    #see the size of the new list after each recursive call

    print(len(l))

    

    #base case

    if len(l) == 1:

        h = l

         

        

    if len(l)>1:

        #Getting the even indexed elements of the list

        for i in range(0,len(l)):

            if (i+1) %2 == 0:

                m = m + [l [i]]

# The above three lines can be replaced by following single line

# m = l[1::2] , this puts all the even indexed elements of list l in m. This also significantly improve #performance. Similarly, we can get odd indexed element with m = l[::2]

        rec(m)

    

    return h

# end of the recursive function

    

n=19

k = list(range(1,n+1))

#Call the recursive function

a = rec(k)

#Convert the only element in the list returned by the recursive function into a string

s = str(a[0])

print("Answer is " + s)


-------------------------------------------------------------------------

Output:



Problem 2

Print a sequence of numbers starting with a positive number N, recursively, such that  A[i+1] = A[i] - 5, as long as  A[i]>0. Once A[i] becomes negative, then  A[i+1]=A[i] + 5,  repeat it until A[i]=N.

Solution:

#Python code

def rec(n):


    print(n,end=" " )


    if n>0:

        n = n - 5

        rec(n)

        n = n + 5

        print(n,end=" ")


# end of recursive function definition

  

n = int(input("Enter the value of n :"))

rec(n)

--------------------------------------------------------------------------
Sample output:


Wednesday, August 19, 2020

Saturday, August 1, 2020

Program Execution (control flow) in a double recursive call


If a function calls itself twice recursively, its tracing tree (program execution/control flow) will be a binary tree




//Understanding double recursion part 1
#include<stdio.h>
//Global variable
int level = 0;
/*
split a list in two equal halves recursively,
and print the level of the binary tree for each node(function call) value pair.

This is the same function used in the DIVIDE & CONQUER technique (splitting
a list from mid recursive ) of  Merge Sort.
*/
void split(int low, int high)
{
    level++; //increment the level each step downwards journey of program execution
    int mid;
    //printf("low = %d High = %d Level = %d\n",low,high,level);
    printf("%d %d Level = %d\n",low,high,level);
    if(low<high)
    {
        mid = (low + high)/2;
        split(low,mid);               //split the left half recursively
        split(mid + 1,high);       //split the right half recursively
    }
    level--; //decrement level as retrace each step upwards the tree, of program execution.
}
int main(void)
{
    printf("For input 1 and 8\n"); // A list of 8 elements, index starting from 1
    split(1,8);
    printf("For input 1 and 16\n"); // A list of 16 elements, index starting from 1
    split(1,16);
    return 0;
}

Output:




/*
Understanding double recursion part 2
Making both the recursive calls in the
SAME line (return statement) also produces
the same result.
The only difference now is that you need to pass
the level as the third argument to the function.
*/
#include<stdio.h>
//Global variable
int level = 0;
/*
split a list in two equal halves recursively,
and print the level of the binary tree for each node(function call) value pair.
*/
int split(int low, int high, int height)
{
    height++; //increment the level each step down
    int mid;
    printf("%d %d Level = %d\n",low,high,height);
    //base condition
    if(low == high)
    {
        return 1;
    }
    if(low<high)
    {
        mid = (low + high)/2;
        return split(low,mid,height) + split(mid + 1,high,height);// The recursive calls in the SAME line
    }
    height--; //decrement level as retrace each step upward
}
int main(void)
{
    printf("For input 1 and 8\n");
    printf("%d \n",split(1,8,level));
    printf("For input 1 and 16\n");
    printf("%d \n",split(1,16,level));
    return 0;
}

Ouput:


Wednesday, July 1, 2020

Simple Python program to calculate profit percentage

Filename: Profit.py  // written in Notepad

***********File begins here****************

// function definition
def findProfit():
    x = 'a'
    while x != 'n' or x != 'N':
        c = float(input("Enter current market price : "))
        s = float(input("Enter expected sell price : "))
        a = float((s - c)/c)*100
        formatted_a = "{:.2f}".format(a)
        print("% Profit for buy at " + str(c) + " and expected sell at " + str(s) + " would be : " + str(formatted_a) +"%") 
        print()   
        x= input("Want to continue (y/n) :") 
        if x == 'n':
            exit()

//call the function to execute it
findProfit()

***************File ends here**************

Outputs % profit upto 2 decimal points.

Sunday, June 28, 2020

Limits of recursive functions

The biggest drawback of recursive functions is that it has a limit to the maximum number of recursive calls it can have( also called the maximum possible depth of recursion).


This is best explained by a simple recursive function shown below which prints the sum of two numbers.


As you can see, we cannot add a number greater than 994 to 5 using recursion because in doing so the maximum recursion depth, which is only 1000 in case of Python gets exceeded. 

The number of recursions( iterations) cannot be greater than 1000 in Python.

Thursday, June 18, 2020

A simple Prolog program: facts.pl

Following are some screenshots of a simple Prolog program, that has its knowledge base file, named ' facts.pl ' and the various questions asked to it; and the  answers given by the Prolog engine based on the facts mentioned in the KB (using the SWI Prolog compiler software):




Following is how to compile the file


Following is Error because file was not re-compiled after edit


Following is after re-compilation after edit



How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows