Archive

Archive for April, 2009

Programming Language C : Part 3

April 27, 2009 2 comments

Last day, I’d ended on the basic structure of the C Programming Language. Today, we shall start to do real programming. It is really fun.

Ok. Lets do a small program to print your name:

c1

This program will give you output like: c2

Now, we shall move to DATA Types.

As we know, there are many types of data in our real world. For example, the Integers, the Floating point numbers, Characters etc.

In case of C, there also exist all of them. In case, we want to use them, we need to “INITIALIZE” them to the Compiler. The method is like this:

c3Here we can see, “int a” declares an integer called ‘a’ without any value. But, “int b = 5” declares an integer called ‘b’ with a value 5 assigned in it. Similarly for floating point numbers, ‘float’ is used and for characters, “char” is used. All these ‘int’ or ‘float’ or ‘char’ are called “keywords” in C.

We shall look further more keywords in C:

c4

All these keywords have their own meanings and jobs to do. We shall look them further, while we will need them in future.

Now, there is a question. I know, I can use int as a keyword to mean the integers. But, how long that integer can be? Int x = 1234567891011121314151617…..??? There should be a limit of this.

char     => a single byte, capable of holding one character in the local character set

int        => an integer, typically reflecting the natural size of integers on the host machine

float     => single-precision floating point

double =>  double-precision floating point

In addition, there are a number of qualifiers that can be applied to these basic types. short

and long apply to integers:

short int sh;

long int counter;

The word int can be omitted in such declarations, and typically it is. The intent is that short and long should provide different lengths of integers where practical; int will normally be the natural size for a particular machine. short is often 16 bits long, and int either 16 or 32 bits. Each compiler is free to choose appropriate sizes for its own hardware, subject only to the the restriction that shorts and ints are at least 16 bits, longs are at least 32 bits, and short is no longer than int, which is no longer than long.  The qualifier signed or unsigned may be applied to char or any integer. unsigned numbers are always positive or zero, and obey the laws of arithmetic modulo 2n, where n is the number of bits in the type. So, for instance, if chars are 8 bits, unsigned char variables have values between 0 and 255, while  signed chars have values between -128 and 127 (in a two’s complement machine.) Whether plain  chars are signed or unsigned is machine-dependent, but printable characters are always positive.  The type long double specifies extended-precision floating point. As with integers, the sizes of floating-point objects are implementation-defined; float, double and long double could represent one, two or three distinct sizes.

Advertisements

Python: Bult-in Functions for Numeric types

April 24, 2009 2 comments

Python has some built-in functions for working with numeric types. Some of them are described below: ———–

Function Name

Descriptions

Code Example

abs

The abs(x) function takes the absolute value of any integer, long integer or floating point number.

When applied to a complex number, the function returns the magnitude of the number, which is distance from that point to the origin in the complex plane.

>>> abs(-5.0)

5.0

>>> abs(-2)

2

>>> abs(5+2j)

5.3851648071345037

coerce

The coerce(x,y) function applies numeric conversion rules(described below the table) to two numbers and return them as tuple.

>>coerce(5,2.5)

(5.0,2.5)

>>coerce(5.5,5+2j)

(5.5+0j,5+2j)

divmod

The functions divmod(a,b) performs long division on two numbers and returns the quotient and remainder.

>>> divmod(5,2)

(2, 1)

>>> divmod(5.5,2.5)

(2.0, 0.5)

pow

The functions pow(x,y[,z]) performs power operation.

As usual, Python coerces the two numbers to a common type if needed. If the resulting type can’t express the correct result then python will show an error message.

An optional third argument to pow specifies the modulo operation to perform on the result.

>>> pow(2,3)

8

>>> pow(2,-1)

0.5

>>> pow(2,5,10)

2

For all the built-in functions and there definitions, please visit this link:
http://docs.python.org/library/functions.html

Numeric Conversion Rule:

  1. If one of the numbers is a complex number then convert the other two a complex number too.
  2. If one of the numbers is floating point number then convert the other to floating point.
  3. If one of the numbers is a long integer then convert the other to a long integer. (Not applicable for Python 3.1)
  4. No previous rules applied, so both are integers, and Python leaves them unchanged.

OpenSSL Upgradation Procedure:

April 23, 2009 Leave a comment

Every linux operating system comes with a OpenSSL version. But if you want to upgrade it to the lates version then follow the following steps:–

[ steps described above is tested on CentOS 5 (Stable) ]

Steps for upgradation of OpenSSL:——

  • Remove the previous versions of OpenSSL using the following command:

#rpm -erase –nodeps openssl

  • Fetch the latest version of openssl from http://openssl.org/source. [Latest version is openssl-0.9.8k]
  • Unzip the tar file to /usr using the following command:

#tar -zxvf -C /usr openssl-0.9.8k.tar.gz

  • Move to the /usr/openssl-0.9.8k directory

#cd /usr/openssl-0.9.8k

  • Install the OpenSSL using the following commands:

<#./config shared

#make

#make test

#make install

  • Link the new files using the following commands:

#cd /lib

#ln -s /usr/openssl-0.9.8k/libssl.so.0.9.8 libssl.so.0.9.8b

#ln -s /usr/openssl-0.9.8k/libssl.so libssl.so.6

#ln -s /usr/openssl-0.9.8k/libcrypto.so.0.9.8 libcrypto.so.0.9.8b

#ln -s /usr/openssl-0.9.8k/libcrypto.so libcrypto.so.6

#cd /usr/lib

#rm /libssl.so

#rm /libcrypto.so

#ln -s /usr/openssl-0.9.8k/libssl.so libssl.so

#ln -s /usr/openssl-0.9.8k/libcrypto.so libcrypto.so

#ln -s /usr/local/ssl/include/ /usr/include/ssl

#cd /usr/include

#rm -rf openssl

#ln -s /usr/local/ssl/include/openssl openssl

  • Rerun ldconfig
  • Perform the following steps:

#cd /etc

#rm ld.so.cache

Open the ld.so.conf file in vi editor and add the following lines:

–         add /usr/local/ssl/lib

–         add /usr/local/lib

Run ldconfig.

  • Change the Environment Path Variable

Open .bash_profile file in vi editor

#vi /root/.bash_profile

Add the following line before export PATH

PATH=$PATH:/usr/openssl-0.9.8k/apps

Save the file end exit from vi editor.

  • Reboot.
  • Done

the symbolic file name may be different depending on the operating system and different version of OpenSSL.

NETWORK FILE SYSTEM

April 17, 2009 Leave a comment

Network File System Abbreviated NFS. A distributed file-sharing system developed well over a decade ago by Sun Microsystems, Inc.

NFS allows a computer on a network to use the files and peripheral devices of another networked computer as if they were local, subject to certain security restrictions. Using NFS, you can share files on your system with other computers running MS-DOS, MacOS, Unix, Novell NetWare, VMS, and many other operating systems, in both local
and global environments. NFS is platform-independent and runs on mainframes, minicomputers, RISC-based workstations, diskless workstations, and personal computers.

Categories: Networking & Related

C Programming: Part 2

April 16, 2009 1 comment

Hello friends! After a long time, I am back with the Programming Language C.

In regard of the last post and the comments posted by our readers, I must insist you trying all of these in Linux / UNIX also. In Linux / UNIX, you don’t need any 3rd party software line ‘Turbo C’ in Windows. In the OS itself, the ‘gcc’ (GNU’s C Compiler) compiler is preloaded. You just need to call the ‘gcc’ and then compile/run the program.

Now, we will go into the C programming!

Before everything, we will write a C program first.

Windows: Open Turbo C è write this code.

Linux / UNIX: Open terminal ècreate ‘hello.c’ in the VI editor è write this code.


#include <stdio.h>

#include <conio.h>

int main()

{

printf(“ Hello World.”);

getch();

return 0;

}

Now, we will look, what are these lines signify:

Line 1 and 2: These are called “Pre-Processor Directives”. We include these “.h” files rather “header files” in our program to use some of their properties. These properties are called “Functions”. Here, in line 5, 6 and 7, you will see some “printf”, “getch” and “return”…these are those Functions. The “printf” and “return” functions are from the header file “stdio.h” (the ‘stdio’ means STANDARD INPUT OUTPUT and ‘conio’ means CONSOLE INPUT OUTPUT) and the “getch” is from the header file “conio.h”. Remember, other than these Functions, we ourselves can also write Functions as we wish.

Line 3: This line indicates the ‘Return type’ and ‘Name’ of a user written function (as I’d said in last paragraph). Now, to know what is ‘return type’ needs some more knowledge in C. So, we will discuss that later. Now, ‘name’. Here as we can see, after the ‘return type’ called ‘int’, there is the name of this function “main”. Now, a question arises, why ‘main’? The reason is, in any C program, there may exist more than 1 function and all of them are controlled by 1 function. Now, to get rid of the question, among those functions, which one is the 1st one, that controls other functions? The answer is: the main function. It’s like the main door of a building. After traversing through it, you can go anywhere in the building. So, here no other function exists, hence, the main door is the ‘main’ function.

Line 4 and 8: You can see these are nothing but, an opening parenthesis and a closing parenthesis. This opening means the starting of any function and closing means the closing of the same.

Line 5, 6 and 7: “printf” is a function, whose job is to print something. Inside the two brackets, there are two upper commas. Inside those ‘upper commas’, if you write some thing, that will be shown to you in the monitor when that program will run. Similarly, “getch” and “return” has some jobs to do. These jobs will be cleared to us when we will have some more knowledges in C.

One more thing, if you have noticed, you can see there is a semicolon (;) after every line inside the main function. This semicolon indicates the ‘End of the Line’.

Now, to compile:

Windows: (in Turbo C) F2 (to save the program) è Alt + F9.

Linux / UNIX: (after saving the program in VI editor) gcc -c -a hello.c

Now, to Run:

Windows: (after compilation) Ctrl + F9.

Linux / UNIX: (after compilation) ./hello.c

OpenSSL: Introduction

April 9, 2009 Leave a comment

OpenSSL is an open source implementation of the SSL and TLS protocols. The core library (written in the C programming language) implements the basic cryptographic functions and provides various utility functions. Wrappers allowing the use of the OpenSSL library in a variety of computer languages are available.
OpenSSL is based on the excellent SSLeay library developed by Eric A. Young and Tim J. Hudson. The OpenSSL toolkit is licensed under an Apache-style licence, which basically means that you are free to get and use it for commercial and non-commercial purposes subject to some simple license conditions.

Versions are available for most Unix-like operating systems (including Solaris, Linux, Mac OS X and the four open source BSD operating systems), OpenVMS and Microsoft Windows.

FIPS 140-2 Complience:

OpenSSL is one of the few open source programs to be validated under the FIPS 140-2 computer security standard by the National Institute of Standards and Technology‘s Cryptographic Module Validation Program.
[Note: FIPS stands for Federal Information Processing Standard]

Present Version:

openssl-1.0.0-beta1 [ Works under FIPS mode as weel as NON-FIPS Mode (Beta Version) ]

openssl-0.9.8k [Works under FIPS mode as well as NON-FIPS mode (Stable Version)]

openssl-fips-1.2 [ Works Under FIPS Mode ]

The other version of the setup files, documentations and other informations can be obtained from http://www.openssl.org/

Python: Variables, Numeric Types and Operators

April 8, 2009 Leave a comment

Python offers four different kinds of numbers with which you can work:integers, long numbers (or longs), floating-point numbers (or floats), and imaginary/complex numbers.

We are familiar with Integer, Long or Floating point Numbers. The new type is Imaginary/Complex number. The imaginary number behaves very much like a float, except that it cannot be mixed with a float. When you see an imaginary number, it will have the letter j trailing it.

Note: Python 2 had separate int and long types for non-floating-point numbers. An int could not be any larger than sys.maxint, which varied by platform. Longs were defined by appending an L to the end of the number, and they could be, well, longer than ints. In Python 3, there is only one integer type, called int, which mostly behaves like the long type in Python 2. Since there are no longer two types, there is no need for special syntax to distinguish them.

To determine the type of a number, you can use a special function that is built into Python, called type. When you use type, Python will tell you what kind of data you’re looking at. Let’s try this with a few examples.

code5In the above examples, we use type() function to determine the type of 2 different numbers: integer, float and complex.

Format Specifiers:

Int: %d

Float: %f

Exponential (For large numbers): %E

Manipulating the Numeric Datatypes:

We can use most of the Python’s operators when working with Numeric data types. the following table lists the operators and how they behavewith numeric types:

code6

Next Post: Useful functions in Python