Subscribe by Email


Showing posts with label Characters. Show all posts
Showing posts with label Characters. Show all posts

Saturday, October 5, 2013

What is a transposition cipher method?

- The transposition cipher method is one of the cryptography methods used for securing the communication from eavesdroppers. 
- This method of encryption shifts the positions of the units or letters of the plain text based up on some regular system so that a permutation of the plain text is generated. 
- This permuted plain text is termed as the cipher text. 
- Thus, the cipher text is generated by changing the order of the units. 
Mathematically the following functions are used:
Ø  Bijective function: For encryption of the character’s position and
Ø  Inverse function: For decrypting the message

Now we shall see about some of the implementations of the transposition cipher:

1. Rail fence cipher: 
- This form of the transposition cipher has been named so because of the way that it follows for encoding.
- Here, the characters of the plain text are written on the successive rails in a downwards manner of some imagined fence.
- Then, we move upwards once getting to the bottom. 
- For reading the message, it is taken in rows.

2. Route cipher: 
- In this form of transposition cipher, a grid of given dimensions is taken on which the characters of the plain text are written out. 
- Then, the message is read based up on the pattern mentioned in the key. 
- For example, the pattern might be inwards spiral in clockwise direction starting from topmost right.
- The route ciphers may use many keys unlike the rail fence cipher. 
- In fact, the number of keys used for enumerating the messages of reasonable length by modern machinery might be too great. 
- Also, it is not necessary that all the keys might be good in equal terms. 
Excessive chunks of the plain text might be left if bad routes are chosen. 
- Also, the plain text might be simply reversed, thus giving a clue to the crypt analysts about the routes. 
- The union route cipher is a variation of the traditional route cipher. 
- The difference between the two is that this one transposed the whole words unlike route cipher which transposed individual letters.
- But since transposing the whole words could expose them, they were first hidden by a code.
- The entire null words might be added for adding humor to the cipher text.

3. Columnar transposition: 
- In this form of transposition cipher, a fixed length is determined for the rows in which the message is written. 
- But for reading the message a column by column approach is followed where some scrambled order if followed for choosing the columns. 
- A keyword is chosen which is used for defining the permutation of the columns as well as the width of the rows. 
- The spare spaces might be filled with the null characters in case of the regular columnar transposition. 
- On the other hand, in these spaces are left as such in the irregular columnar transposition cipher. 
- The keyword specifies some order following which the message is read column - wise. 
- The column lengths have to be worked out by the recipient for deciphering the message. 
- This is done based up on division of the length of the message specified by the key length.

4. Double transposition: 
- A single columnar transposition is vulnerable to attacks since the possible lengths of the column and anagrams can be guessed. 
- Therefore, a stronger version of it i.e., the double transposition is followed. 
- This is a two-time application of the columnar transposition. 
- For both the transpositions, either the same key might be used or different keys.
- This was the most complicated cipher before the coming of the VIC cipher. 
- It offered reliable operation under difficult conditions. 


Sunday, June 30, 2013

Explain the single and two level directory structures

About Directory Structure
- Directory structure is referred to the way that the operating system follows for displaying the files and file system to the user in the field of computing. 
- A hierarchical tree structure is used for displaying the files in a typical way. 
- The special kind of string the file name uses or the unique identification of a particular file that is stored in the computer’s file system. 
- Before the 32 bit operating systems actually came in to the scenario; short names of about 6 to 14 characters in size were used for the file names. 
However, the modern operating systems give permission for file names of longer length i.e., of 250 character and that too per path name element. 
- The drive:\ is the root directory in the operating systems such as the OS/2, windows and DOS for example, “C:\”. 
- The “\” is the directory separator but the forward slash “/” is also internally recognized by the operating system.
- A drive letter is use for naming the drives either physically or virtually. 
- This also implies there does not exist a root directory that is formal. 
- Rather, we have root directories in each drive that are independent of each other. 
- However, one virtual drive letter can be formed by combining in to one. 
- This is done by keeping a RAID setting of 0 for the hard drive. 
- The file system hierarchy standard is used by the operating systems such as the UNIX and other UNIX like systems. 
- This is the most common form for the directory structures used by the UNIX operating systems. 
- It is under the root directory “/” that all the files and the directories are stored even if they are actually present on a number of different physical devices.

About Single – level Directory
- This is the simplest of the directory structures. 
- All files are stored in the same directory itself because it is quite easy to understand as well as support. 
- The first computer of the world i.e., the CDC 6600 also operated on just one directory and it could be used by a number of users at the same time. 
- There are significant limitations of the single-level directory. 
- These limitations come in to play when there are more than one users using the system or when the system has to deal with a large number of files. 
- All the files have to be assigned unique names since they are all stored under the same directory. 
- No two files can have the same file name. 
- It may become difficult to keep the names of the files in mind if they are large in number.


About Two–level Directory
- The limitations of the single level directory structure can be overcome by creating an individual directory for every user. 
- This is the most standard solution for the problems of the single level directories. 
- In this two-level directory structure, a UFD or user file directory is made for every user. 
- The structure of all the user file directories is almost the same, but the difference is that only the files of the individual user are stored in one.
- When a user tries to log in or when he starts a task, the system searches for the MFD or master file directory. 
- The name of the user or his/ her account number is used for indexing the MFDs in the operating system. 
- Each of those entries points to the UFD belonging to that user. 
- When a reference is made to some file, the system only searches for the user file directory for example, when a file has to be deleted or created. 


Wednesday, May 30, 2012

Explain the concepts of URL manipulation?


Today in this internet savvy world, I guess almost everybody is familiar with what is an URL or uniform resource locator. 
If you see an URL, you can make out that it is nothing but a string of characters. These characters add up to mark up a reference string which points to a source from internet. A uniform resource locator was previously known as uniform resource identifier.
The URLs came in to existence in the year of 1994 along with the introduction of the World Wide Web by Sir Tim Berners – Lee along with the contributions from the internet engineering task force. 
The format of a typical URL consists of the domain names along with the file paths and the forward slashes are used to distinguish between the different file names and folders. Name of the servers are preceded by a double slash. 

Components of URL


Let us now list the components of a typical URL in the order in which they are lined up in the URL:
  1. The scheme name which is usually a protocol.
  2. The scheme is followed by a colon
  3. Two slashes
  4. Name of the domain (if any depending on the scheme).
  5. A port number
  6. CGI (common gateway scripts) scripts
  7. Query string
  8. Fragment identifier (optional)

Categories of URL


- The URLs are categorized under two categories namely relative URLs and absolute URLs. 
- The relative URLs are used whenever the references contained in the resources refer to another resource. 
- These relative URLs are often conceived from the absolute URLs. 
- The URLs locate a resource based on their primary access mechanism. 
- There are various issues related to URLs like URL normalization, URL manipulation etc. 

What is meant by URL Manipulation?


- URL manipulation is just another name for URL rewriting.
- As the term itself suggests it is all about altering the parameters of the URL.
- The URL manipulation is used for good purposes also and for bad ones also. 
- It is a technique that is usually employed by the web server administrator for convenience and is often used by the hackers for nefarious purposes. 
- The original URLs of the resources are quite complicated and complex. 
- Therefore, a purpose of this technique is also to make it easy for the user to access a web resource by providing a simple URL. 
- URL manipulation technique is used so that the user does not require cutting, copying or pasting long and arcane string of characters. 
- This technique is also employed since remembering complex URLs is a difficult task and they are quite lengthy which makes it quite a tedious task for the users to remember or store it and use. 
- Therefore, using the technique of URL manipulation they are modified in to simple and short URLs which are comparatively easy for the users to remember. 

Wrong Use of URL Manipulation
- A nefarious use of URL manipulation is to use the URL of a legitimate site or web resource without the prior permission or knowledge of the site owner or administrator to redirect the users to an illegitimate web site or web resource. 
- Such illegitimate sites then may install malicious code on the hard drive of the user’s system.
- This may also have an intended purpose of increase the traffic on the attacker’s illegitimate web site or application.
- There is a term similar to the term URL manipulation called URL poisoning. These two terms may sound similar in meaning, though they are not. 

What is URL Poisoning?


- URL poisoning is a technique that is employed to track the activities of the user on the web. 
- This technique involves the addition of an identification number to the current URL of the web browser when that particular web site is visited by the user. 
- This URL with the ID number is then used for tracking the visits of that user on the sites.


Monday, October 10, 2011

Some details about Multi dimensional arrays in C...

An array can be defined as the collection of variables of the same type that are referenced by a common name. Arrays are of two types namely one dimensional arrays and multi dimensional arrays. One dimensional array consists of finite homogenous elements whereas a multi dimensional array is composed of elements each of which is itself an array. Arrays refer to a named list of a finite number n of similar data elements. Each of the data elements can be referenced respectively by a set of consecutive numbers, usually 0, 1, 2, 3, 4,….., n. the simplest form of a multi dimensional array is the two dimensional array.

You can declare a two dimensional array as follows:
Type array name [ rows ] [ columns ];

Where type is the base data type of the array having name name, rows, the first index, refers to the number of rows in the array and columns, the second index refers to the number of columns in t5he array. For example:

Int sales [ 5 ] [ 10 ] ;

The general form of array initialization is shown below:

Type array name [ size N ] = { value list } ;

The value list is a comma separated list of array elements values. The element’s values in the value list must have the same data type as that of the base type of the array.
Int days [ 5 ] = { 1, 2, 3, 4, 5 } ;

Character arrays can also be initialized as shown below:
Char string [ 10 ] = { ‘c’ , ‘a’ , ‘t’ ‘\0’ } ;

Multi-dimensional arrays can also be initialized in the same way as simple dimensions one. For example:
Int abc [ 3 ] [ 2 ] = { 1, 1,
2, 2,
3, 3 } ;

This can be done it the other way also :
Int abc [ 3 ] [ 2 ] = { 1, 1, 2, 2, 3, 3 } ;

A multi dimensional array of strings can be initialized as shown below:

Type array name [ size N ] = { value list } ;

Here type declares the base type of the array, the array name specifies the name with which the array will be referenced and size defines how many elements the array will hold. The size must be an integer value or integer constant without any sign. The value list is a comma separated list of array’s elements values. The element values in the value list must have the same data type as that of the base type of the array.

Int days [ 5 ] = { 1, 2, 3, 4, 5 } ;

Character arrays can also be initialized as shown below:
Char string [ 10 ] = { ‘c’ , ‘a’ , ‘t’ , ‘s’ , ‘\0’ } ;

Multi dimensional arrays are also initialized in the same as the single dimensional one. For example:
Int cube [ 3 ] [ 2 ] = { 1, 1,
2, 2,
3, 3 } ;

This can be done in the other way also:
Int abc [ 3 ] [ 2 ] = { 1, 1, 2, 2, 3, 3 } ;

A multi dimensional array of strings can be initialized as shown below:
Char abc [ 3 ] [ 2 ] = { “Sunday” , “Monday” } ;

C allows you to skip the size of the array in an array initialization statement. This is called unsized array initialization. C allows arrays of more than 2 dimensions. The exact limit of dimensions is determined by the compiler we are using.


Saturday, October 8, 2011

Some details about Strings and Arrays of Strings in C

Multiple character constants can be dealt with in 2 ways in C. if enclosed in single quotes, these are treated as character constants and if enclosed in double quotes, these are treated as string literals. A string literal is a sequence of characters surrounded by double quotes. Each string literal is automatically added with a terminating character ‘\0’. Thus, the string “abc” will actually be represented as follows:

“ abc \0” in the memory and its size is not 3 but 4 characters ( inclusive of terminator character ).

Arrays refer to a named list of a finite number n of similar data structure elements. Each of the data elements can be referenced respectively by a set of consecutive numbers, usually 0, 1, 2, 3, ……., n. if the name of an array of 10 elements is ARR, then its elements will be referred as shown below:

ARR [ 0 ], ARR [ 1 ], ARR [ 2 ], ARR [3], …… ARR [9]

Arrays can be one dimensional, two dimensional or multi dimensional. The functions gets() and puts () are string functions. The gets() function accepts a string of characters entered at the keyboard and places them in the string variable mentioned with it. for example :

Char name[ 21 ];

The above code declares a string namely name which can store 20 valid characters ( width 21 specifies one extra character ‘\0’ with which a string is always terminated ). The function gets() reads a string of maximum 20 characters and stores it in a memory address pointed to by name. As soon as the carriage return is pressed, a null terminator ‘\0’ is automatically placed at the end of the string. The function puts () writes a string on the screen and advances the cursor to the newline. Any subsequent output will appear on the next line of the current output by puts ().

Arrays are a way to group a number of items into a larger unit. Arrays can have data items of simple types like int or float, or even of user defined types like structures and objects. An array can be of strings also. Strings are multi dimensional arrays comprised of elements, each of which is itself an array.

A string is nothing but an array of characters only. In actual C does not have a string data type rather it implements string as single dimension character arrays. Character arrays are terminated by a null character ‘\0’. So, for this reason the character arrays or strings are declared one character larger than the largest string they can hold.

Individual strings of the string array can be accessed easily using the index. The end of a string is determined by checking for null character. The size of the first index ( rows ) determines the number of strings and the size of the second index ( columns ) determines maximum length of each string. By just specifying the first index, an individual string can be accessed. You can declare and handle an array of strings just like a two dimensional array. See an example below:

Char name [10] [20] ;

Here the first dimension declares how many strings will be there in the array and the second dimension declares what will be the maximum length of a string. Unlike C++, C has some different functions for adding or concatenating strings, checking string length and to see the similarity of two strings. The functions are namely strlen, strcmp, strcat, strrev etc and are included in header file string.h. Strings are used for holding long inputs.


Wednesday, September 14, 2011

Some details about pointers and strings in C...

There doesn’t exist anything in C like real strings. A string is an array. It can be defined as an array of characters. A string is terminated by a nul character “\0”. A string can be initialized normally as follows:

Char string[10];
String[0] = ‘c’;
String[1] = ‘a’;
String[2] = ‘t’;
String[3] = ‘s’;

Another way of initializing and declaring a string is as follows:
Char string[10] = “cats”;

The following statement asks compiler to allocate 10 bytes of memory for the string entered by the user. The string can store only 9 characters and the tenth one being used for “nul” character.

We can easily access strings and their constituent characters using character pointers. The string arrays are mostly used for storing char data type elements in the memory. The array of string pointers is preferred over two dimensional arrays of characters mainly for two reasons. The first reason is by implementing array of pointers, you can make more efficient use of available memory since it consumes lesser number of bytes for storing arrays of strings. The second main reason is that an array of string pointers makes the manipulation of strings easier. You can easily exchange the positions of strings in the array using pointers without touching their memory locations. This makes managing strings very convenient. Another way of initializing a string is by using pointers like

for example:
Char string[ ] = “cats”;
Char *a;

Here is a pointer pointing to the string “string”. Pointers are another suitable way to access string arrays and modify them as we want. Since strings are composed of characters, we should use pointers to characters. The types of the variable and the pointers must match otherwise an error will be generated. Be careful that you don’t use “&” (address of) operator to assign the address of a variable to the desired pointer. If you used it, the name of the array will be used as the address of that particular array. For this reason only we do not use “&” (address of) while passing a string to the function scanf(). For example see the following code:

Int a;
Char name[10];
Scanf(“%d%s”, &a, name);

The pointer allows us to access the required character in the string because we made it to point to that string. Functions can be passed to print labels and to call the function. Below is an example:

Void printlbl(char lbl[ ])
{
Printf (“the label: %s\n”, lbl);
}
int main()
{
char lbl2[] = "abc";

Printlbl(lbl2);

}

Now if we want to pass a pointer to the string array lbl2, we will use the following code:
Char *lblptr = lbl2;

The above declared pointer can be used in the function also like shown below:
Printlbl (lblptr) ;

After execution you will observe that both the statements give the same output. Now you will ask me why so? The answer for this is that when we pass an array as a parameter or an argument to a function, a pointer is automatically created without we knowing it and the arrays are passed by reference method automatically the way a pointer is passed. So the above written code can also be written the other way as follows:

void Printlbl(char *lbl)
{
printf("the Label: %s\n",lbl);
}
a code for dynamically allocated string is given below:
string = (char *)malloc(sizeof(char) * (len+1));

Some stings can be allocated dynamically. This is done when we don’t know how much long a string will go until the program is executed or when we don’t what size of string the user will enter.


Friday, September 9, 2011

Understanding the Structure of a C Program

The best way to get started with any programming language is to study a program, so in order to make you understand C program structure, we will take into consideration an example program whose code is:

1. /* this is a simple c program
2. Written to explain basic program structure */ -------------------------multiple line comment
3. #include //header file. ---------------------- single line comment
4. int main()
5. {
6. return 0;
7. }

This is the simplest C program and this program unfortunately doesn’t do anything. “#include” is called a preprocessor command. It tells the compiler to do processing before the compilation. This command tells the compiler to include the header file “stdio.h” in the program.

Functions are the basic building blocks of any program. The function “main()” is the most important function in any C program. You can say that this is the point of execution of a program. This function should exist as an entry point. Following the main is a pair of parentheses. These two parentheses indicate that the main is a function. Now coming to the opening and closing pair of braces in lines 5 and 7, are used to define the limits of a function or the program. Usually these braces contain executable statements of a function. The main() is preceded by word int. it means that this function returns an integer value. This value is returned using the “return” statement.

Now let’s take a program “abc.C” that does something. It’s same as the previous except that it has an executable statement between the braces in addition to the obligatory return statement. The executable statement calls a function which is already included in the header files as a part of the C library. The function is namely “printf()” and in order to make it print text the desired text is written with quotation marks within the parentheses of the function. The text will be displayed on the monitor when program is run. Notice the semicolon at the end of the executable statements. A semi colon in C is used as a statement terminator.

Consider the following statement:
printf("Hello World!\n");

Notice the “\n” character. The back slash is used to indicate to the compiler that a special character is being inserted. Here “n” indicates a new line. This is used whenever you want to print something in a new line. The function “printf()” prints the text and returns the carriage. Consider the following statements:

int index;

the key word int stands for integer and is used to declare a variable of type integer called index. Always keep in mind that the number of field descriptors and the number of variable definitions must be the same or else the runtime system will generate something we are not expecting. Another common and important part of C program structure is “comments”.Comments are optional but it’s good to include because they make the program more readable although they don’t mean anything to the compiler. Comments are of two types: single line comments and multiple line comments. Single line comments are used to give only one line description of a function or any other statement. A multiple line comment spans through several lines and is used to give a detailed description of a program or function.Look at the above program code for an example of comments. Another important part of a program are statements and expressions which combine variables and constants and can be assignments, function calls etc.Coming to the line breaks they are necessary to for good style formatting of your programs. This makes it easy for you to understand how your program flows when you want to maintain or modify it.You can also use “blank lines” after pre compiler declarations and declaration of new variables.Indentation should also be used in order to make your program more readable and to define the body of functions.


Wednesday, September 7, 2011

How are strings and arrays defined in C?

A string can be defined as a group of characters, usually letters of the alphabet. When C is either to compare a string with another string, output it, copy it to another string, or whatever, the functions are intended to do what they are called to do until a null, which is a zero, is detected. Such strings are often called an ASCII-Z string. C treats a string as an array termination with a NULL character. C does not have a separate data type for strings and so strings exist as the arrays of characters. An extra byte must be left to store the NULL “\0”. Strings are declared as the arrays of characters. For example:

char name[25];

Strings can be fully or partially initialized depending on the requirements of the user. For example:
char fill[10] = { ‘a’, ‘ ‘, ‘r’,’o’,’p’,’l’,’a’,’n’,’e’,’\0’ };

There exist certain predefined functions for modifying strings. The library cstring.h houses all these functions. Strcpy() is used to copy one string into another string. Strlen() is used to determine the length of the string. Strcmp() is function for comparing two strings i.e., which one is bigger in terms of length. Strcat() is used to concatenate two strings. The second string is appended to the end of the first string. Strrev() is used to reverse a string alphabetically.

An array is a C derived data type and can be defined as a collection of variables of the same data type that are referenced by a common name. All arrays consist of contiguous memory locations where the lowest address corresponds to the first element and highest address corresponds to the last element. Arrays are useful when quite many elements of the same data type are needed to be stored and processed. The numbers in [ ] are called indices or subscripts. A string itself is an array of characters. Arrays are of two types namely one- dimensional arrays and multi dimensional arrays. Multi dimensional array comprises of elements which themselves are arrays. The general form of an array declaration is as follows:

Type array-name [size];

Here type states the data type of the array elements. The array name declares the name of the array, and finally the size defines how many elements will be there in the array. The data type of the array is called the base type.

A multidimensional array consists of M*N elements where M is the number of rows and N is the number of columns. It can be declared as follows:

Type array-name [rows][columns];

Where single dimensional arras can be read using a single loop, it takes nested loops to read and access the elements of a multi dimensional array. One loop is used to process the rows and the other one is used to process the columns. The arrays can be initialized during the run time as follows:

Type array-name [size 1]……….[size N]= {value list};

The value list consists of the array elements. C allows you to skip the size of arrays in an initialization statement. These types of arrays are called unsized arrays. For example:
Int abc[ ] = {1,2,3,5,7};

The best way to assign values to an array is using a "for" or "while" loop because it’s not affordable to write a separate initialization for every element. Arrays can be passed s parameters to the functions to maintain a structured design. Always keep in mind that in C subscripts start from 0. A string from an array of strings can be accessed by using pointers. But keep in mind that pointers hold only address of the strings. From there it is able to obtain the whole chunk of the contiguous memory.


Facebook activity