Thursday, January 22

C code implementing a simple DFA



Hello freinds, 

Here I am posting my C implementation of DFA shown below. This DFA will accept any string containing 'a's and 'b' and last symbol should be 'a'.


#include <stdio.h>

#define TOTAL_STATES 2
#define FINAL_STATES 1
#define ALPHABET_CHARCTERS 2

#define UNKNOWN_SYMBOL_ERR 0
#define NOT_REACHED_FINAL_STATE 1
#define REACHED_FINAL_STATE 2


enum DFA_STATES{q0,q1};
enum input{a,b};
int Accepted_states[FINAL_STATES]={q1};
char alphabet[ALPHABET_CHARCTERS]={'a','b'};
int Transition_Table[TOTAL_STATES][ALPHABET_CHARCTERS];

int Current_state=q0;
void DefineDFA()
{

    Transition_Table[q0][a] = q1;
    Transition_Table[q0][b] = q0;
    Transition_Table[q1][a] = q1;
    Transition_Table[q1][b] = q0;
}

int DFA(char current_symbol)
{
int i,pos;
    for(pos=0;pos<ALPHABET_CHARCTERS; pos++)
        if(current_symbol==alphabet[pos])   
            break;//stops if any character other than a or b
    if(pos==ALPHABET_CHARCTERS)
         return UNKNOWN_SYMBOL_ERR;
    for(i=0;i<FINAL_STATES;i++)
 if((Current_state=Transition_Table[Current_state][pos])
==Accepted_states[i])
            return REACHED_FINAL_STATE;
    return NOT_REACHED_FINAL_STATE;

}


int main(void)
{

    char current_symbol;
    int result;
 
    DefineDFA();    //Fill transition table
 
    printf("Enter a string with 'a' s and 'b's:\n
                Press Enter Key to stop\n");
 
 
    while((current_symbol=getchar())!= '\n')
        if((result= DFA(current_symbol))==UNKNOWN_SYMBOL_ERR)
            break;
    switch (result) {
    case UNKNOWN_SYMBOL_ERR:printf("Unknown Symbol %c",
  current_symbol); 
 break;
    case NOT_REACHED_FINAL_STATE:printf("Not accepted"); break;
    case REACHED_FINAL_STATE:printf("Accepted");break;
    default: printf("Unknown Error");
    }

    printf("\n\n\n");

    return 0;
}


Sunday, January 11

INTERNET SECURITY : Networking Lecture Notes

TOPIC: INTERNET SECURITY



What is IPSec?
IPSecurity (IPSec) is a collection of protocols designed to provide security at the network layer.

Transport mode:  The IPSec header and trailer are added to the information  corning from the transport layer. The IP header is added later.

Tunnel mode: It takes an IP packet, including the header, applies IPSec security methods to the entire packet, and then adds a new IP header .


What are the protocols associated with IPSec?

Authentication Header (AH): provides source authentication and data integrity. The protocol uses a hash function and a symmetric key to create a message digest;


Encapsulating Security Payload (ESP) :source authentication ,data integrity and privacy


What are the reserved Addresses for private networks?
Prefix Range Total
10/8 10.0.0.0 to 10.255.255.255 2^24
172.16/12 172.16.0.0 to 172.31.255.255 2^20
192.168/16 192.168.0.0 to 192.168.255.255 2^16

What is Virtual private Network?

Virtual private network (VPN) is a technology that is  used by large organizations that use the global Internet for both intra- and inter organization communication, but require privacy in their internal communications.

VPN technology uses IPSec in the tunnel mode to provide authentication, integrity, and privacy.
All messages for internal communication will travel through Internet after encapsulated inside another packet using IPSec Tunneling.

The public network (Internet) is responsible for carrying the packet from Source side router  to destination side router. Outsiders cannot decipher the contents of the packet or the
source and destination addresses. Deciphering takes place at destination router, which finds the destination address of the packet and delivers it.

Explain Secure Socket layer (SSL)?

Secure Socket Layer (SSL) is designed to provide security and compression to data generated from the application layer.

1. SSL divides the data into blocks of 214 bytes or less.
2. Each fragment of data is compressed by using one of the lossless compression methods
3. To preserve the integrity of data, SSL uses a keyed-hash function to create a MAC.
4. To provide confidentiality, the original data is encrypted using symmetric key
5. A header is added to the encrypted payload. The payload is then passed to a reliable transport layer protocol.

Transport Layer Security (TLS) is the IETF standard version of SSL.

What is the use of Pretty Good Privacy (PGP)?
 PGP is designed to create authenticated and confidential e-mails.

What is Firewall?

A firewall is a device (usually a router) installed between the internal network of an organization and the rest of the Internet. It is designed to filter some packets.

Packet Filter: It can forward or block packets based on the IP addresses , Transport layer protocol or port addresses. It uses a filtering table to decide which packets must be discarded (not forwarded).

Proxy firewall: The server opens the packet at the application level and finds out if the request is legitimate.