Archive

Archive for September, 2010

My Presentation on Design Patterns


Today I presented a topic on the composition design pattern. I thank all those who praised my presentation. I really thank Biju R Mohan sir for his remark of  “Excellent presentation, he made concept clear and easy to understand”. Here is my Software Architecture Composite Talk

IPtables Revisited


Some basics of iptables  here

Command to view the contents of different chains

>iptables -L

Command to fush the rules from the chains

>iptables – F

Note:

1.root login is necessary for all the commands related to iptables.

2.Use “ man “ options to get details of the commands i.e “man iptables(in small letters)”

Some rules I practised:

1.      Don’t accept any packets other than ip =”xyz”.

Iptables -A INPUT  ! -s 172.16.17.43 -j DROP

2.      Accept packets only from ip =” xyz”

iptables -A INPUT ! -s 172.16.17.43 -j DROP

iptables -A INPUT -s “xyz” -j ACCEPT

3.      Don’t accept any packets other than mac address =”xyz”.

iptables -A INPUT -m mac ! –mac-source 12:43:32:23:43:23 -j DROP

4.      Accept packets only from mac address =” xyz”

iptables -A INPUT -m mac ! –mac-source 12:43:32:23:43:23 -j DROP

iptables -A INPUT -m mac –mac-source 12:43:32:23:43:23 -j ACCEPT

5.      Don’t accept any packets from  ip =”xyz” and mac address =” “.

iptables -A INPUT ! -s 172.16.23.1 -m mac ! –mac-source 12:32:43:56:21:23 -j DROP

6.      Accept packets only from  ip =”xyz” and mac address =” “

iptables -A INPUT ! -s 172.16.23.1 -m mac ! –mac-source 12:32:43:56:21:23 -j DROP

iptables -A INPUT -s 172.16.23.1 -m mac –mac-source 12:32:43:56:21:23 -j ACCEPT

7.      Accept only tcp connection

iptables -A INPUT ! -p tcp -j DROP

iptables -A INPUT -p tcp -j ACCEPT

8.      Don’t accept packets of udp

iptables -A INPUT  -p udp -j DROP

9.      Don’t Accept packets who’s tcp status is SYN

iptables -A INPUT -p tcp –syn -j DROP

10.      Limit number of tcp connection on the system

iptables -A INPUT -p tcp –syn –dport 23 -m connlimit –connlimit-above 2 -j DROP

11.      Create your own chain .

iptables -N MYCHAIN

12.      Delete our own chain

iptables -X MYCHAIN

13.      Add the some rules in your chain and try out

iptables -A MYCHAIN -s 124.12.67.4 -j DROP

14.      Delete specific rule in your chain.

iptables -D MYCHAIN -s 124.12.67.4 -j DROP

My Drawings!!


Can you figure out who is this?

My First Python Program


This is the fibonacci number program in python

def fibo(n) :

if n==0 :
return 0
elif n==1 :
return 1
else :
return fibo(n-1)+fibo(n-2)
print fibo(3)
print fibo(9)
print fibo(13)

This is my first ever Python program. Using IDLE(interactive python GUI). Python is really cool language and its easy too!!

 

Different types of data types


There actually different types of datatypes as the programming languages specify them. Here I’m going to specify four types of them, Almost all predominant languages should have datatypes belonging to the following four kinds of datatypes

1) Statically typed language

2) Dynamically typed language

3) Strongly typed language

4) Weakly typed language

Statically typed language:

In this kind of languages variables should be assigned types at the compile time itself( and fixed at compile time).  All the variables must be used before using them.

ex: Java, C, C++ ect.,

Dynamically typed language

It is exactly opposite to that of statically typed language. The type of the variable is decided at the runtime rather than at compile time.

ex:VBscript, Python

Strongly typed language

These kind of typed language don’t allow you to change the type of a variable once the type is decided(at runtime or at compile time). Once a variable is declared as String in Java during runtime you cannot convert the type of the variable without explicit type conversion.

ex: Python, Java

Weakly typed language

This type of languages are exactly opposite to that of Strongly typed languages, you can change the type of the variable at anytime during the execution of the program.

ex: VBScript

Exams Time!!


I’ve first mid exams from 20th. The first mid is very important because all the professors have given 35-45% weight-age to this exam, so I’ve to prepare well. I’ll be back once I’m done with my exams. I strictly took an oath not to open gmail, twitter, wordpress, facebook, linkedin, orkut(Even it is blocked in NITK surathkal) until exams are over. Bye I’ll meet you with another blog post once exams are over.

Categories: Uncategorized

What is the largest prime factor of the number 600851475143 ?


The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Here is the Java code using BigInteger to represent the given number.

package projecteuler;
import java.math.BigInteger;
/**
*
* @author Vasanth Raja Chittampally
*/
public class ProjectEuler {
public static void main(String[] args)
{
BigInteger bi=new BigInteger("600851475143");
int div=7;
while(bi.compareTo(new BigInteger("1"))!=0) {
while(bi.mod(new BigInteger(div+"")).compareTo(new BigInteger("0"))==0) {
bi=bi.divide(new BigInteger(div+""));
}
div+=2;
}
System.out.println(""+div);
}
}

I tested the above code using Java. The answer it gives is 6857. It does take less than 1sec of execution time.