You are on page 1of 102

www.Vidyarthiplus.

com CSE Lab-II

DATA WAREHOUSING AND DATA MINING


Data mining :

Data mining is the task of discovery interesting patterns from large amounts of data,
where the data can be stored in databases , data warehouses , or other information repositories .It
is a young interdisciplinary field ,drawing from areas such as database systems, data
warehousing, statistics ,machine learning ,data visualization, information retrieval and high-
performance computing. other contributing areas include neural networks ,pattern recognition,
spatial data analysis ,image databases ,signal processing and many application fields such as
business, economics and bioinformatics

Data mining refers to extracting or mining knowledge from large amounts of data
.The term is actually a misnomer .remember that the mining of gold from rocks or sand is
referred to as gold mining rather than rock or sand mining .thus ,data mining should have been
more appropriately named knowledge mining from data, simply knowledge mining .

Figure : data mining searching for knowledge (interesting patterns) in the data

Dept of CSE, Page 1


www.Vidyarthiplus.com CSE Lab-II

Many people treat data mining as a synonym for another popularly used term,
knowledge discovery from data or KDD. Alternatively ,others view data mining as simply an
essential step in the process of knowledge discovery .knowledge discovery as a process is
depicted in the following figure.

Figure : data mining as a step in process of knowledge discovery

It consists of an iterative sequence of the following steps.


1.Data Cleaning (to remove noise and inconsistent data).
2.Data Integration(where multiple data sources may be combined ).
3.Data Selection (where data relevant to the analysis task are retrieved from the database)
4.Data Transformation(where data transformed or consolidated into forms. appropriate for
mining by performing summary or aggregation operations, for instance).
5.Data Mining (an essential process where intelligent methods are applied in order to extract
data patterns)
6.Pattern Evaluation(to identify the truly interesting patterns representing knowledge based on
some interestingness measures)

Dept of CSE, Page 2


www.Vidyarthiplus.com CSE Lab-II

7.Knowledge Presentation(where visualization and knowledge representation techniques are


used to present the mining knowledge to the user)
Getting started :
As a data mining tool that combines advance modeling technology with ease of use,
Clementine helps you discover and predict interesting and valuable relationships within your
data. You can use Clementine for decision-support activities, such as:
Creating customer profiles and determining customer life value.
Detecting and predicting fraud in your organization .
Determining and predicting valuable sequences in web-site data
Predicting future trends in sales and growth.
Profiling for direct mailing response and credit risk.
Performing churn prediction , classification, and segmentation.
Shifting through vast quantities of data from automation and discovering useful patterns
These are just a sampling of the many ways that you can use Clementine to extract valuable
information from your data. Essentially, if you have the data and your data contain the right
information.

Data processing :
Real world databases are highly suspectable to noise, missing, inconsistent data thus it is very
essential to clean the data. cleaning of data involves different methods. These methods help to
remove the noise detection and correction of inconsistency ,integration and transformation of
data from different sources and reducing the size of the data .data preprocessing in Clementine
involves 4 stages.
Reading data from different sources
Maintaining the data quality
Data manipulation
Obtaining the relationships of the data

Dept of CSE, Page 3


www.Vidyarthiplus.com CSE Lab-II

1.) To Extract the data from various sources


Var File
Oracle Database
Microsoft Excel
Microsoft Access Database

AIM:

To Implement Extraction of data from various sources


a). var File:
A variable file node, which you set up to read the data from the data source.
STEPS :
1. Select variable file node and a table onto the canvas from the palette
2. Establish the connection from var file to the table
3. Browse the CST or SST file to the var file
4. Then execute the table/matrix.
STREAM :

Dept of CSE, Page 4


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 5


www.Vidyarthiplus.com CSE Lab-II

b). MICROSOFT EXCEL FILE :


STEPS :
1. create excel file and save it.
2. Select the Excel node and table/matrix from sources of palette onto the canvas.
3. Then double click onto the Excel and connect the excel book and then apply.
4. Then execute the table/matrix.
EXCEL FILE :

STREAM:

Dept of CSE, Page 6


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 7


www.Vidyarthiplus.com CSE Lab-II

c).MICROSOFT ACCESS DATABASE:


STEPS :
1. Create a table (database) in Microsoft Access and save it.
2. Create data source as follows :
3. Control panel-> Administrative tools->Data sources (ODBC) : for creation of Microsoft
access drivers .
4. Then double click on database and then import Microsoft access (ODBC) data source(then
give Scott as username and tiger as password) if established the network connection.
5. Now select the database and table from the palette onto the canvas and establish the
connection between them.
6. Select the access data source i.e., table which we created in access.
7. Then execute the table/matrix

STREAM:

Dept of CSE, Page 8


www.Vidyarthiplus.com CSE Lab-II

PROCESS:

Dept of CSE, Page 9


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 10


www.Vidyarthiplus.com CSE Lab-II

2.) To explain different field options that facilitates to manipulate the data
AIM:
To implement different field options that facilitates to manipulate the data

a.) TYPE :
Type allows field metadata to be determined and controlled.The type node specifies field
metadata and properties. For example, you can specify a usage type(range, set, ordered set, or
flag) for each field ,set options for handling missing values and system nulls ,set the role of a
field for modeling purpose ,specify field and value labels and specify values for a field .
STEPS:
1. Select type node from the field options on palette onto the canvas.
2. Establish the connection from database/varfile to the type node and table or matrix(output).
3. Then edit the type by double click on the type node.
Field type values missing check direction
F1 type <read> none in/out/both
F2 type <read> none in/out/both
F3 type <read> none in/out/both
F4 type <read> none in/out/both
F5 type <read> none in/out/both
F6 type <read> none in/out/both
F7 type <read> none in/out/both
4. Then execute the table/matrix.
STREAM :

Dept of CSE, Page 11


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 12


www.Vidyarthiplus.com CSE Lab-II

b). FILTER :

Filter allows fields to be renamed or removed.The Filter node filters(discards) fields


,renames fields, and maps fields from one source node to another . Select varfile ,filter node and
table/matrix onto the canvas
1. Establish the connection from varfile to filter and to the table
2. Edit the filter and click on the attributes that we want to filter
Field Filter
Field name
Field name
Field name
Field name
Field name
Field name
Field name
3. Then apply and execute the connected table/matrix.

STREAM :

Dept of CSE, Page 13


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 14


www.Vidyarthiplus.com CSE Lab-II

c).DERIVE :

Derive allows new fields to be generated based on existing fields.The derive node
modifies data values or creates new fields from one or more existing fields. It creates fields of
type formula, flag , set , state, count, and conditional .
Formula : the new field is the result of an arbitrary CLEM(Clementine language for
expression manipulation) expression .
Flag: the new field is a flag ,representing a specified condition .
Set : the new field is one of two states ,switching between these states is triggered by a
specified condition.
Count : the new field is based on the number of times that a condition has been true.
Conditional : the new field is the value of one of two expressions ,depending on the value of
the condition
STEPS :

1. Select type node from the field options on palette onto the canvas
2. Establish the connection from database/varfile to the type node and table or matrix(output).
3. Then edit the type by double click on the type node.
Field type values missing check direction
F1 type <read> none in/out/both
F2 type <read> none in/out/both
F3 type <read> none in/out/both
F4 type <read> none in/out/both
F5 type <read> none in/out/both
F6 type <read> none in/out/both
F7 type <read> none in/out/both
4. Then execute the table/matrix.

Dept of CSE, Page 15


www.Vidyarthiplus.com CSE Lab-II

STREAM :

OUTPUT:

Dept of CSE, Page 16


www.Vidyarthiplus.com CSE Lab-II

Dept of CSE, Page 17


www.Vidyarthiplus.com CSE Lab-II

d). BINNING :

Binning allows numeric fields into sets. The binning node automatically creates new set
fields based on the values of one or more existing numeric range fields. For example, you can
transform a scale income field into new categorical field containing Groups of income as
deviations from the mean .once you can have created bins for new field ,you can generate a
derive node based on the cut points .
STEPS :
1. Select the varfile , binning node and table/matrix from the palette onto the canvas.
2. Establish the connection between them
3. Them edit binning and select the bin fields.
Bin fields : sal
4. Then execute the table/matrix.
STREAM :

Dept of CSE, Page 18


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 19


www.Vidyarthiplus.com CSE Lab-II

e.) TRANSPOSE :
Transpose transposes records to fields and fields into records.
STEPS :
1) Select the varfile ,transpose node and table/matrix from the palette onto the canvas.
2) Establish the connection between them.
3) Then edit transpose and select
Read from field : ename
Red values : smith
4) Then execute table/matrix.
STREAM :

OUTPUT:

Dept of CSE, Page 20


www.Vidyarthiplus.com CSE Lab-II

f.) FIELD REORDER :


Field reorder changes the sort order of fields .The field reorder node defines
the natural order used to display fields downstream . this order affects the display of fields in a
variety of places, such as tables, lists, and the field chooser .this operation is useful when
working with wide datasets to make fields of interest more visible.
STEPS :
1) Select the varfile ,field reorder node and table/matrix from the palette onto the canvas.
2) Establish the connection between them.
3) Then edit field reorder and select
Religion: sal and other fields and then click ok
4) Then execute table/matrix.

STREAM :

Dept of CSE, Page 21


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 22


www.Vidyarthiplus.com CSE Lab-II

3.) To explain different record options that facilitates to manipulate the data
AIM :
To implement different record options that facilitates to manipulate the data

a) SELECT :
Select a subset of records based on a specified condition .the select node selects or
discards a subset of records from the data stream based on a specific condition .For example, you
might select the records that pertain to a particular sales region.
STEPS :
1. Select the varfile, select node, and table/matrix from the palette onto the canvas.
2. Establish the connection between them.
3. Make a connection between the select and another new table and edit the select and give
appropriate data to retrieve the records.
4. Then execute the table/matrix to get the data according to the given condition.
STREAM :

Dept of CSE, Page 23


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 24


www.Vidyarthiplus.com CSE Lab-II

b.) AGGREGATE :
Aggregate provides summary information on groups of records.The Aggregate node
replaces a sequence of input records with summarized, aggregated.
STEPS :

1. Select the varfile, aggregate node and table from the palette onto the canvas.
2. Establish the connection between them and made a new output connection to aggregate.
3. Edit the aggregate and select the aggregate field. And then click any of sum, mean, min,
max, sdev according to the requirement.
4. Then execute the table/matrix for output.

STREAM :

Dept of CSE, Page 25


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 26


www.Vidyarthiplus.com CSE Lab-II

c.) SAMPLE :
Sample provides different methods for sample data.The sample node trims the size of
dataset according to parameters that you set. It is useful for paring down a large dataset, selecting
a random sample to generate a model or training a neural network.
STEPS :
1. Select the varfile, sample node and table from the palette onto the canvas
2. Establish the connection between them.
3. Make a connection between the sample and another new table and edit the select and give
appropriate data to retrieve the records
4. Then execute the table/matrix to get the data according to the given condition.

STREAM :

Dept of CSE, Page 27


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 28


www.Vidyarthiplus.com CSE Lab-II

d.) SORT :

Sort records according to the specified criteria .The sort node sorts records into
ascending or decending order based on the values of one or more fields.

STEPS :

1. Select the varfile , sort node and table from the palette onto the canvas.
2. Establish the connection between them.
3. Edit the sort and select a field on which we want to perform sorting.
4. Then execute the table/matrix.

STREAM :

Dept of CSE, Page 29


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Dept of CSE, Page 30


www.Vidyarthiplus.com CSE Lab-II

e.) MERGE :
Merge merges records from multiple inputs.The merge node takes multiple input records and
creates a single output record containing some or all of the input fields .it is useful for merging
data from different sources, such as internal customer data and purchased demographic data
STEPS :
1. Select the varfile ,merge node and table from the palette onto yhe canvas.
2. Establish the connection between them.
3. Edit the merge and select two keys (columns) to merge(join).
4. Then execute the table/matrix.
STREAM :

OUTPUT:

Dept of CSE, Page 31


www.Vidyarthiplus.com CSE Lab-II

Dept of CSE, Page 32


www.Vidyarthiplus.com CSE Lab-II

f.) DISTINCT :
Distinct includes or discards with distinct values in specified fields.The distinct node
removes duplicate records ,either by passing the first distinct record to the stream or by
discarding the first record and passing any duplicates to the data stream instead.
STEPS :
1. Select the varfile ,distinct node and table/matrix from the palette onto the canvas.\
2. Establish the connection between them.
3. Edit the distinct node and select a field which has duplicate values.
4. Then apply execute the table/matrix.
STREAM :

OUTPUT:

Dept of CSE, Page 33


www.Vidyarthiplus.com CSE Lab-II

Dept of CSE, Page 34


www.Vidyarthiplus.com CSE Lab-II

4.)To explain different visualization measures that includes different graphs


of data.
AIM:
To Implement different visualization measures that includes different graphs of data
a). HISTOGRAM:
Histogram displays a frequency graph of discredited continuous values. Histogram
node show the occurrence of values for numeric fields. They are often used to explore the date
before manipulations and model building .Similar to the distribution node, histogram nodes are
frequently used to reveal imbalances in the data.
STEPS :
1. Select the varfile, histogram node from the palette onto the canvas.
2. Establish the connection between them.
3. Edit the histogram node and enter a field to get the histogram graph.
4. Then apply execute the histogram.
STREAM:

OUTPUT:

Dept of CSE, Page 35


www.Vidyarthiplus.com CSE Lab-II

b.)DISTRIBUTION :
Distribution node displays a frequency graph of categorical values.Distribution nodes are
used to show the distribution of symbolic values in a dataset. They are frequently used before
manipulation nodes to explore the data and correct any imbalances. For example , if instances of
respondents without children occur much more frequently then other types of respondents ,you
might want to reduce these instances so that a more useful rule can be generated in later data
mining operations . A distribution node will help you to examine and make decisions about such
imbalances.
The distribution node is unusual in that it provides both a graph and a table to analyze your data.
STEPS :
1. Select the varfile, distribution node from the palette onto the canvas.
2. Establish the connection between them.
3. Edit and distribution graph and select the field for the graph.
4. Then apply execute the distribution graph of required field.
STREAM :

OUTPUT:

Dept of CSE, Page 36


www.Vidyarthiplus.com CSE Lab-II

c.)COLLECTION :
Collection graph displays the distribution of values for a numeric field by another field.
Collection graphs are similar to histograms except that collections show the distribution of
values for one numeric field relative to the values of another , rather than occurrence of values
for a single field. A collection is useful for illustrating a variable or field whose values change
over time .using 3-d graphing you can also include a symbolic axis displaying distributions by
category.
STEPS :
1. Select the varfile , collection node from the palette onto the canvas.
2. Establish the connection between them.
3. Edit the collection and select the collect and over fields.
4. Then apply execute the collection graph.
STREAM :

OUTPUT:

Dept of CSE, Page 37


www.Vidyarthiplus.com CSE Lab-II

d.) WEBPLOT :
Web displays a co-occurrence frequency graph for the categorized values .A web graph
maps associations between different categories . Start by connecting a web node to the source
node in your workspace .
STEPS :
1. select the varfile and web node from the palette onto the canvas.
2. Establish the connection between them.
3. Edit the web node and select the field to categorize the values.
4. Then apply execute the web graph.

STREAM :

OUTPUT:

Dept of CSE, Page 38


www.Vidyarthiplus.com CSE Lab-II

e.) MULTIPLOT :
Multiplot displays the data in a 2-d multiplot.
STEPS :
1. Select the varfile and multiplot node from the palette onto the canvas.
2. Establish the connection between them .
3. Edit the multiplot by selecting the x-field and y-field .
4. Then execute the multiplot node(graph).
STREAM :

OUTPUT:

Dept of CSE, Page 39


www.Vidyarthiplus.com CSE Lab-II

5.) To Generate Association rules by using Apriori and GRI algorithm


AIM:
To Implement Association rules by using Apriori and GRI algorithm.
STEPS:
1. Open the new stream.
2. Select the var file from sources and drag it to the stream.
3. Select the type from the field options and drag it to the stream.
4. Go to modeling tab and select the Apriori icon and GRE icon and drag it to the stream
5. Establish connection among them.

6. Select the var file and edit and load the Basket-in from the demos folder.And observe the
data, filter, types tabs on the same window.
7. Press apply and press ok.
8. Select type and edit the directions fields as follows. For non-product attributes select None
and remaining as both.
9. Click on read values.

Dept of CSE, Page 40


www.Vidyarthiplus.com CSE Lab-II

10.Select Apriori and click on edit. Set the support and confidence percentages as you wish.
11.Click on Execute.

12.Youll get the output icon in the right side of the stream under modeling tab.
13. Select GRI and click on edit. Set the support and confidence percentages as you wish.
14. Click on Execute.

Dept of CSE, Page 41


www.Vidyarthiplus.com CSE Lab-II

15. Youll get the output icon in the right side of the stream under modeling tab.

16. Add the output icons to the stream.


17. By double clicking on the output icons well get the outputs as follows:

Dept of CSE, Page 42


www.Vidyarthiplus.com CSE Lab-II

Dept of CSE, Page 43


www.Vidyarthiplus.com CSE Lab-II

COGNOS

6 a.) To Creating a catalog for oracle relational tables


AIM:
To Implement catalog for oracle relationaltables
1. Create a database user in oracle.uername and password required to connect with oracle.
2. Go to start All programscognos EP series 7 then click on cognos impromptu
administrator.
3. Impromptu window and welcome dialogue appears then click on close button.
4. In impromptu window go to catalog menu click on new menu item.
5. New catalog dialogue appears.
6. Enter catalog file name and description.
7. Select catalog type as personal.

8. Select database name or click on data base button.


9. Database definition manager appears.
10.Select oracle from database,gateways and drivers.

Dept of CSE, Page 44


www.Vidyarthiplus.com CSE Lab-II

11. Click on new database button.


12. Database definition oracle dialogue appears.
13. Enter logical database name for cognos use.
14. Enter sql*net connection spring.

15. Click on test button.


16. Test attach to database dialogue appears.
17. Enter user id(LBCEMCA).
18. Enter password(LBCEMCA).
19.Successful attachment message box appears then click on ok button.

Dept of CSE, Page 45


www.Vidyarthiplus.com CSE Lab-II

20. It will go back to database definition(oracle dialogue) then click on ok button.


21. It will go back to database definition manager .then click on ok button.
22. It will go back to new catalog dialogue.
23. Database name appears then click on ok button.
24. Catalog logon for catalog name dialogue appears.
25. Enter database user id and password .then click on ok button.

26. Tables dialogue appears.


27. Double click on LBCEMCA database in database tables lists.
28. The database is expanded and list of tables in the database appears.
29. Select emp table then click on add button and select department table then click on add
button.

Dept of CSE, Page 46


www.Vidyarthiplus.com CSE Lab-II

30. Click on ok button.


31. Joins dialogue appears then click on ok button(not defining any joins).

32. It will go to impromptu window.

Dept of CSE, Page 47


www.Vidyarthiplus.com CSE Lab-II

6 b.) To developing a report using created catalog


AIM:
To Implement developing a report using created catalog
1. Go to impromptu window go to file menu click on new menu item.
2. New dialogue box appears.
3. There are two tab pages in new dialogue box.
a) Fast find b) standard
4. Go to fast find tab then select the simple list report style.

5. Click on ok button.
6. A new report opens and query dialogue appears.
7. In the query dialogue go to data tab page then look into catalog.
8. Expand emp folder.
9. Select required columns then move them to query data.
10. Employee number query data.
Employee name query data.
Job query data.
Salary query data.
11.Expand department folder .select required columns then move
them to query data.
12. Department number query data.
Department name query data
Location query data.

Dept of CSE, Page 48


www.Vidyarthiplus.com CSE Lab-II

13.Click on ok.
14.Query execution error appears.

15. Click on done.


16. Report created with no data.

Dept of CSE, Page 49


www.Vidyarthiplus.com CSE Lab-II

6 c.) To joining the two tables in the catalog.


AIM:
To Implement joining of two tables in the catalog
1. Go to Impromptu window catalog joins menu item.
2. Joins dialogue appears .In joins dialogue go to edit tab page.
3. Select department in joins class and select emp in available tables.

4. Click on generate button.


5. Generate joins options dialogue appears.
6. choose using keys or first matching columns option.

7. Click ok button.

Dept of CSE, Page 50


www.Vidyarthiplus.com CSE Lab-II

8. Follow the steps of experiment two and develop the code.

Dept of CSE, Page 51


www.Vidyarthiplus.com CSE Lab-II

7 a.) To Creating new folder structures


AIM:
To Implement new folder structures
1. Open catalog impromptu administrator.
2. Go to catalog menu click on open menu item.
3. Select a catalog in open dialogue then click on open menu item.

4. Select a catalog in open dialogue then click on open button.


5. Enter user id and password for local data base connection.

6. Go to Impromptive window catalog menu click on folder menu item.

Dept of CSE, Page 52


www.Vidyarthiplus.com CSE Lab-II

7. Folder dialogue appears.


8. Click on new folder button.
9. New folder dialogue appears .enter folder name then click ok button.

Dept of CSE, Page 53


www.Vidyarthiplus.com CSE Lab-II

7 b.) To creating new calculation objects


AIM:
To implement new calculation objects
1. Open the existing catalog.
2. Open the folders dialogue.
3. Open a folder by double click on the folder.

4. Click on new calculation button.


5. Enter calculation name.

Dept of CSE, Page 54


www.Vidyarthiplus.com CSE Lab-II

6. Double click on catalog columns in available component .


7. Catalog dialogue appears then expand emp folder and select salary then click on ok button.

8. Double click on *(multiply) operation.


9. Double click on value folder then double click on number.
10. Enter the n umber manually.
11. Press right arrow on key board.
12. Double click on / (divide by) operator.
13. Press right arrow on key board.
14. Double click on number then type the number manually.
15. Press right arrow on key board.

16. Click on ok button.

Dept of CSE, Page 55


www.Vidyarthiplus.com CSE Lab-II

7 c.) To creating new condition objects


AIM:
To implement condition objects
1. Open the existing catalog.
2. Open folders dialogue.
3. Open a folder by double click on folder.
4. Click on new condition button.

5. New condition dialogue appears.


6. Enter condition name(job).
7. Double click on catalog column in available components.
8. Catalog dialogue appears.expand emp folder and select job then click on ok button.

9. Double click on in operator.


10. Double click on ( operator.
Dept of CSE, Page 56
www.Vidyarthiplus.com CSE Lab-II

11. Double click on select values then select values dialogue appears.
12. Double click on managers.
13. Double click on ) operator.
14. Click on ok button.

Dept of CSE, Page 57


www.Vidyarthiplus.com CSE Lab-II

7 d.)To editing the folders name within the catalog.


AIM:
To implement the folders name within the catalog.
1. Open the existing catalog.
2. Open folders dialogue appears.

3. Select a folder then click on edit button.


4. Edit name dialogue appears.
5. Old name appears in name box then replace the name by typing new name manually.

6. Click on ok button.

Dept of CSE, Page 58


www.Vidyarthiplus.com CSE Lab-II

7 e.) To creating a report using the above three programs


AIM:
To implement a report using the above three programs
1. Go to impromptu window then go to file name click on new menu item.
2. New dialogue appears.
3. Select simple list template from fast find tab then click on ok button.

4. Query dialogue appears.


5. Expand employee folder in catalog.
6. Move employee number ,employee name ,job, salary to query the data.
7. Expand department folders in catalog.
8. Move department number ,department name ,location to query the data.

Dept of CSE, Page 59


www.Vidyarthiplus.com CSE Lab-II

9. Expand calculations folder in catalog.


10. Move tab to query the data.

11. Go to filter tab page.


12. Double click on catalog columns in available components.

13. Catalog dialogue appears then expand conditions and folder select job then click on ok
button.

Dept of CSE, Page 60


www.Vidyarthiplus.com CSE Lab-II

Dept of CSE, Page 61


www.Vidyarthiplus.com CSE Lab-II

8.a) CREATION OF TYPE IN PROMPT


AIM :
To create type in prompt
1. Open the existing catalog.
2. Open folders dialogue.
3. Click on new folder button.

4. Enter the folder name (prompt) then click on ok button.


5. Double click on prompt folder and keep it open.
6. Click on new prompt button.
7. Prompt definition dialogue appears.
8. Enter name(dept number).
9. Select type(type in).
10. Enter message (enter value for department number).
11. Select data type(number).
12. Enter default value if needed.

Dept of CSE, Page 62


www.Vidyarthiplus.com CSE Lab-II

13. Click on ok button.


14. Click on ok button.

Dept of CSE, Page 63


www.Vidyarthiplus.com CSE Lab-II

8 b.)CREATING A REPORT USING TYPE IN PROMPT


AIM:
To Creating a report using type in prompt
1. Go to impromptu window then go to file menu then click on new menu item.
2. New dialogue appears then select simple list template and Click on ok button.

3. Query dialogue appears.


4. In the query dialogue go to data tab then look into catalog.
5. Expand employee folder.
6. Select required columns then move to query data.
(employee number,employee name,job,salary).
7. Expand department folder.
8. Select required columns then move to query data.
(department number,department name,location).

9. In the query dialogue box go to filter dialogue.


10. Double click on catalog columns.
11. Catalog dialogue appears.
12. Expand employee folder and select department number.
13. Double click on = operator.

Dept of CSE, Page 64


www.Vidyarthiplus.com CSE Lab-II

14. Double click on catalog columns.


15. Catalog dialogue appears.
16. Expand prompt folder and select department number then click on ok button.

17. Click on ok button.


18. Prompt dialogue appears and ask you enter value for department number.

19. Enter your value and click on ok button.


20. Impromptu window then go to report menu click on prompt menu item.
21. Prompt dialogue appears and ask you enter value for department number.
22. Enter your value and click on ok button.

Dept of CSE, Page 65


www.Vidyarthiplus.com CSE Lab-II

9 a.) CREATION OF CATALOGUE PICK-LIST PROMPT:-


AIM:
To create catalogue pick-list prompt:-
STEPS:
1. Creation of catalog - pick list prompt.
2. Open the existing catalogue .
3. Open folders dialogue.

4. Double click on prompt folder and keep it open.


5. Click on new prompt button.
6. Prompt definition dialogue appears.
7. Enter name(designation).
8. Select type (catalogue pick list).
9. Enter message (select value for job).
10. Expand employee folder in catalogue column.
11. Select job column and click on use button.
Dept of CSE, Page 66
www.Vidyarthiplus.com CSE Lab-II

12. Select order (descending order).

13. Click on ok button.


14. Click on ok button.

Dept of CSE, Page 67


www.Vidyarthiplus.com CSE Lab-II

9 b.) CREATING A REPORT USING CATALOGUE PICK-LIST


PROMPT.
AIM:
To create a report using catalogue pick-list prompt.
STEPS:
1. Impromptu window->go to file menu->click on new menu item.
2. New dialogue appears then select simple list template and click on ok button.

3. Query dialogue appears.


4. In the query dialogue go to data lab then look into catalogue.
5. Expand employee folder.
6. Select required columns then move them to query data empno, ename, job, and sal.
7. Expand dept folder.
8. Select required column then move them to query data deptno, dname, and loc.

Dept of CSE, Page 68


www.Vidyarthiplus.com CSE Lab-II

9. In the query dialogue go to filter dialogue.


10. Double click on catalogue column.
11. Catalogue dialogue appears.
12. Expand employee folder and select job column.

13. Click on ok button.


14. Double click on in operator.
15. Double click on ( operator.
16. Double click on catalogue columns.
17. Catalogue dialogue appears.

18. Expand prompt folder and select designation prompt then click on ok button.
19. Double click on ) operator.

Dept of CSE, Page 69


www.Vidyarthiplus.com CSE Lab-II

20. Click on ok button.

Dept of CSE, Page 70


www.Vidyarthiplus.com CSE Lab-II

COMPUTER NETWORKS

10.) Write a program to implement data link layer framing methods


character stuffing & bit stuffing.
AIM:
To implement data link layer framing methods character stuffing & bit stuffing.
PROGRAM:
#include<stdio.h>
void charStuff(char *txt,char *sdat)
{
int ln=strlen(txt),i,j;
sdat[0]='\0';
strcat(sdat,"stxdle");
for(i=0,j=6;i<ln;i++,j++)
{
sdat[j]=txt[i];
if(!strncmp(txt+i,"dle",3))
{
sdat[j+1]='\0';
strcat(sdat,"ledle");
j+=5;
i+=2;
}
}
sdat[j]='\0';
strcat(sdat,"dleetx");
}

void bitStuff(char *txt,char *sdat)


{
int ln=strlen(txt),i,j;
sdat[0]='\0';
strcat(sdat,"01111110");
for(i=0,j=8;i<ln;i++,j++)
{

Dept of CSE, Page 71


www.Vidyarthiplus.com CSE Lab-II

sdat[j]=txt[i];
if(!strncmp(txt+i,"11111",5))
{
sdat[j+1]='\0';
strcat(sdat,"11110");
j+=5;
i+=4;
}
}
sdat[j]='\0';
strcat(sdat,"01111110");
}

void main()
{
int ch;
char txt[500],sdat[500];
clrscr();
printf("Enter 1 for Character stuffing, any other for Bit stuffing\n");
scanf("%d",&ch);
printf("Enter data to be transmitted\n");
fflush(stdin);
gets(txt);
if(ch==1)
charStuff(txt,sdat);
else
bitStuff(txt,sdat);
printf("After Framing :\n");
printf("The data to be transmitted is\n");
puts(sdat);
getch();
}

Dept of CSE, Page 72


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

1) Enter 1 for Character stuffing, any other for Bit stuffing 1


Enter data to be transmitted
weldlecome
After Framing :
The data to be transmitted is
Stxdleweldledlecomedleetx

2) Enter 1 for Character stuffing, any other for Bit stuffing 0


Enter data to be transmitted
111101111100
After Framing :
The data to be transmitted is
01111110111101111100001111110

Dept of CSE, Page 73


www.Vidyarthiplus.com CSE Lab-II

11.) Write a c program to find CRC for a given message using


standardized generating polynomials CRC -12, CRC -13,CRC
CCITT.
AIM:
To find CRC for a given message using standardized generating polynomials CRC -12,
CRC -13,CRC CCITT.
PROGRAM:
#include<stdio.h>
void genverChecksum(int *M,int m,int *G,int n,int *csum)
{
int i,j;
for(i=0;i<n;i++)
csum[i]=M[i];
for(i=0;i<m;i++)
{
if(csum[0]==1)
for(j=0;j<n;j++)
csum[j]=(csum[j]+G[j])%2;
for(j=0;j<n-1;j++)
csum[j]=csum[j+1];
csum[n-1]=M[i+n];
}
}
void main()
{
int M[500],r[100],i,j,m,n,*csum,c,ch[]={13,17,33,17};
int G[4][33]={{1,1,0,0,0,0,0,0,0,1,1,1,1},
{1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1},
{1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,1,1,0,1,1,0,1,1,1},
{1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1}};
clrscr();
printf("Enter data in 0's and 1's (-1 at end)\n");
for(m=0;1;m++)
{
scanf("%d",&M[m]);
Dept of CSE, Page 74
www.Vidyarthiplus.com CSE Lab-II

if(M[m]==-1)
break;
}
printf("\t\t****MENU*****\n""\t\t1.CRC-12\n""\t\t2.CRC-16\n""\t\t3.CRC-32\n"
"\t\t4.CRC-CCIT\n""\t\tEnter your choice\n");
scanf("%d",&c);
if(c<1||c>4)
{
printf("Choose between 1 to 4 Only\n");
getch();
exit(0);
}
n=ch[c-1];
for(i=0;i<n-1;i++)
M[m+i]=0;
csum=(int *)malloc(sizeof(int)*n);
genverChecksum(M,m,G[c-1],n,csum);
printf("The Checksum is\n");
for(i=0;i<n-1;i++)
{
M[m+i]=csum[i];
printf("%d ",csum[i]);
}
printf("\nThe Transmitted data is\n");
for(i=0;i<m+n-1;i++)
printf("%d ",M[i]);
printf("\nAt Receivers side : \n");
printf("The Received data is\n");
for(i=0;i<m+n-1;i++)
printf("%d ",M[i]);
genverChecksum(M,m,G[c-1],n,csum);
printf("\nObtained Remainder is\n");
for(i=0;i<n-1;i++)
printf("%d ",csum[i]);
getch();
}

Dept of CSE, Page 75


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:
Enter data in 0's and 1's (-1 at end)
1 0 1 0 -1
****MENU*****
1.CRC-12
2.CRC-16
3.CRC-32
4.CRC-CCIT
Enter your choice 2
The Checksum is 0000000000111100
The Transmitted data is 10100000000000111100
At Receivers side :
The Received data is 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0
Obtained Remainder is 0000000000000000

Dept of CSE, Page 76


www.Vidyarthiplus.com CSE Lab-II

12.) Write a c program to implement Dijsktras algorithm to find shortest


path from given source node to all nodes.
AIM:
To implement Dijsktras algorithm to find shortest path from given source node to all
nodes.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<math.h>
#define IN 99
#define N 6
int dijkstra(int cost[][N], int source, int target);
int dijsktra(int cost[][N],int source,int target)
{
int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j;
char path[N];
for(i=1;i< N;i++)
{
dist[i] = IN;
prev[i] = -1;
}
start = source;
selected[start]=1;
dist[start] = 0;
while(selected[target] ==0)
{
min = IN;
m = 0;
for(i=1;i< N;i++)
{
d = dist[start] +cost[start][i];
if(d< dist[i]&&selected[i]==0)
Dept of CSE, Page 77
www.Vidyarthiplus.com CSE Lab-II

{
dist[i] = d;
prev[i] = start;
}
if(min>dist[i] && selected[i]==0)
{
min = dist[i];
m = i;
}
}
start = m;
selected[start] = 1;
}
start = target;
j = 0;
while(start != -1)
{
path[j++] = start+65;
start = prev[start];
}
path[j]='\0';
strrev(path);
printf("%s", path);
return dist[target];
}
main()
{
int cost[N][N],i,j,w,ch,co;
int source, target,x,y;
printf("\tShortest Path Algorithm DIJKSRTRA's ALGORITHM\n\n");
for(i=1;i< N;i++)
for(j=1;j< N;j++)
cost[i][j] = IN;
char path[N];
for(i=1;i< N;i++)
{

Dept of CSE, Page 78


www.Vidyarthiplus.com CSE Lab-II

dist[i] = IN;
prev[i] = -1;
}
start = source;
selected[start]=1;
dist[start] = 0;
while(selected[target] ==0)
{
min = IN;
m = 0;
for(i=1;i< N;i++)
{
d = dist[start] +cost[start][i];
if(d< dist[i]&&selected[i]==0)
{
dist[i] = d;
prev[i] = start;
}
if(min>dist[i] && selected[i]==0)
{
min = dist[i];
m = i;
}
}
start = m;
selected[start] = 1;
}
start = target;
j = 0;
while(start != -1)
{
path[j++] = start+65;
start = prev[start];
}
path[j]='\0';
strrev(path);

Dept of CSE, Page 79


www.Vidyarthiplus.com CSE Lab-II

printf("%s", path);
return dist[target];
}
main()
{
int cost[N][N],i,j,w,ch,co;
int source, target,x,y;
printf("\tShortest Path Algorithm DIJKSRTRA's ALGORITHM\n\n");
for(i=1;i< N;i++)
for(j=1;j< N;j++)
cost[i][j] = IN;
for(x=1;x< N;x++)
{
for(y=x+1;y< N;y++)
{
printf("Enter the weight of the path between node %d and %d: ",x,y);
scanf("%d",&w);
cost [x][y] = cost[y][x] = w;
}
printf("\n");
}
printf("\nEnter The Source:");
scanf("%d", &source);
printf("\nEnter The target");
scanf("%d", &target);
co = dijsktra(cost,source,target);
printf("\nShortest Path: %d",co);
}

Dept of CSE, Page 80


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

Shortest Path Algorithm DIJKSRTRA's ALGORITHM

Enter the weight of the path between node 1 and 2: 2


Enter the weight of the path between node 1 and 3: 4
Enter the weight of the path between node 1 and 4: 1
Enter the weight of the path between node 1 and 5: 8

Enter the weight of the path between node 2 and 3: 5


Enter the weight of the path between node 2 and 4: 3
Enter the weight of the path between node 2 and 5: 10

Enter the weight of the path between node 3 and 4: 2


Enter the weight of the path between node 3 and 5: 9

Enter the weight of the path between node 4 and 5: 7


Enter The Source:1
Enter The target5
BF

Shortest Path: 8

Dept of CSE, Page 81


www.Vidyarthiplus.com CSE Lab-II

13.) Write a c program to implement Distance Vector routing algorithm.


AIM:
To implement Distance Vector routing algorithm
PROGRAM:
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int i,j,k,nv,sn,noadj,edel[20],tdel[20][20],min; char sv,adver[20],ch;
clrscr();
printf("\n ENTER THE NO.OF VERTECES:");
scanf("%d",&nv);
printf("\n ENTER THE SOURCE VERTEX NUM,BER AND NAME:");
scanf("%d",&sn);
flushall();
sv=getchar();
printf("\n NETER NO.OF ADJ VERTECES TO VERTEX %c",sv);
scanf("%d",&noadj);
for(i=0;i<noadj;i++)
{
printf("\n ENTER TIME DELAY and NODE NAME:");
scanf("%d %c",&edel[i],&adver[i]);
}
for(i=0;i<noadj;i++)
{
printf("\n ENTER THE TIME DELAY FROM %c to ALL OTHER NODES: ",adver[i]);
for(j=0;j<nv;j++)
scanf("%d",&tdel[i][j]);
}
printf("\n DELAY VIA--VERTEX \n "); for(i=0;i<nv;i++)
{
min=1000; ch=0;
for(j=0;j<noadj;j++)
if(min>(tdel[j][i]+edel[j]))
{
min=tdel[j][i]+edel[j];
ch=adver[j];
}
if(i!=sn-1)
printf("\n%d %c",min,ch); else
printf("\n0 -"); }
getch();
}

Dept of CSE, Page 82


www.Vidyarthiplus.com CSE Lab-II

INPUT/ OUTPUT:
ENTER THE NO.OF VERTECES:12
ENTER THE SOURCE VERTEX NUMBER AND NAME:10 J ENTER NO.OF ADJ
VERTECES TO VERTEX 4
ENTER TIME DELAY and NODE NAME:8 A
ENTER TIME DELAY and NODE NAME:10 I
ENTER TIME DELAY and NODE NAME:12 H
ENTER TIME DELAY and NODE NAME:6 K
ENTER THE TIME DELAY FROM A to ALL OTHER NODES: 0 12 25 40 14 23 18 17
21 9 24 29
ENTER THE TIME DELAY FROM I to ALL OTHER NODES: 24 36 18 27 7 20 31 20 0
11 22 33
ENTER THE TIME DELAY FROM H to ALL OTHER NODES: 20 31 19 8 30 19 6 0 14 7
22 9
ENTER THE TIME DELAY FROM K to ALL OTHER NODES: 21 28 36 24 22 40 31 19
22 10 0 9
DELAYVIA--VERTEX 8 a
20 a
28 i
20 h
17i
30i
18h
12h
10i
0-
6k
15 k

Dept of CSE, Page 83


www.Vidyarthiplus.com CSE Lab-II

INFORMATION SECURITY

14.a) To Examine how sniffing software works and PGP works


AIM:
To Examine how sniffing software works
IMPLMENTATION OF SNIFFING:
1. Go to the site ethereal.com
2. Download the tool
3. In that environment click on option capture interfaces capture, this
opens a Window wait for few seconds, it will give the details of all packets captured. (Or)
right click
on open in a new window. It gives all the data related to the packet.
4. Click edit/apply design window. This is a filter.
5. Go to statistics, click on destination. It will give all the destination paths.
6. Statistics IP addresses.
7. Explore all the options like this.

IMPLMENTATION OF PGP:
1. Go to site GnuPGP.org this will run on windows as well as Linux.
2. Get the tool, download it.
3. In that go to Documentation, in that click on Guides, in that many are there but we used
Brendans page, click on that
4. List of commands are given
5. Execute it.

Dept of CSE, Page 84


www.Vidyarthiplus.com CSE Lab-II

14 b.) Write a program to implement format string vulnerabilities


AIM:
To implement format string vulnerabilities
FORMAT STRING PROGRAM :
# include <stdio.h>
# include <conio.h>
void main()
{
int input =2;
clrscr ();
printf(ABCdef \n\n%n,&input);
printf(value of var :%d,input);
getch();
}

EXPECTED OUTPUT :
ABCdef
Value of var : 2
Real output :
ABCdef
Value of var : 8

Dept of CSE, Page 85


www.Vidyarthiplus.com CSE Lab-II

15) Write a program to implement virus program.


AIM:
To implement virus program
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<graphics.h>
#include<fstream.h>
void fool();
void main()
{
clrscr();
for(int i=0;i<=100;i++)
{
textcolor(YELLOW+BLINK);
gotoxy(35,12);
cprintf("VIRUS LOADING");
gotoxy(39,15);
textcolor(GREEN);
cout<<i<<"%";
delay(75);
clrscr();
}
delay(100);
clrscr();
flushall();
gotoxy(20,12);
cout<<" 'HI GUEST' VIRUS CREATED NOW BY HACKER";
gotoxy(20,14);
cout<<"SAY GOOD BYE TO YOUR PC IN ";
for(int j=10;j>=0;j--)
{
gotoxy(48,14);

Dept of CSE, Page 86


www.Vidyarthiplus.com CSE Lab-II

cout<<j<<" SECONDS";
delay(1000);
}
clrscr();
cout<<"\n1.HARD-DISK CORRUPTION: ";
delay(4000);
cout<<"completed";
cout<<"\n\n2.MOTHER BOARD CORRUPTION: ";
delay(4000);
cout<<"completed";
cout<<"\n\n3.INSTALLING CYBERBOB.DLL -->WINDOWS/COMMAND :";
delay(4000);
cout<<"completed";
cout<<"\n\nPROCRAETORIAN.SYS SUCCESSFULLY PLANTED";
delay(3000); cout<<"\n\n\tVIRUS.EXE";
delay(2000);
cout<<"\n\n*************************";
cout<<"\n\n Sample test ";
cout<<"\n\n*************************";
delay(4000);
cout<<"\n\n**********************************";
cout<<"\n\nFor Real Virus ";
cout<<"\n\nMo: 010101010101 ";
cout<<"\n\n**********************************";
delay(10000);
}
void fool()
{
clrscr();
int g=DETECT,h;
initgraph(&g,&h,"c:\tc\bgi");
cleardevice();
delay(1000);
setcolor(2);
settextstyle(1,0,1);
delay(1000);
setbkcolor(BLUE);
getch();
delay(4000);
closegraph();
exit(0);
}

Dept of CSE, Page 87


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:

1.HARD-DISK CORRUPTION: completed


2.MOTHER BOARD CORRUPTION: completed
3.INSTALLING CYBERBOB.DLL -->WINDOWS/COMMAND :completed
PROCRAETORIAN.SYS SUCCESSFULLY PLANTED
VIRUS.EXE
*************************
Sample Test
*************************

Dept of CSE, Page 88


www.Vidyarthiplus.com CSE Lab-II

16.) Write a cryptography program to implement program


AIM:
To Implement cryptography program . /*cryptography program "6.6 As before,
suppose p = 467, alpha = 4, a = 101 and beta = 449. Suppose the message x = 286 is signed
with the (bogus) signature y = 83, and Bob wants to convince Alice that the signature is
invalid." -Douglas R. Stinson- See Cryptogrphy: Theory and Practice" by Douglas R. Stinson
pages 222-223. */
PROGRAM:
#include <stdio.h>
#include<conio.h>
long exp_mod(long x, long b, long n) /* returns x ^ b mod n */
{
long a = 1l, s = x;
while (b != 0)
{
if (b & 1l) a = (a * s) % n;
b >>= 1;
if (b != 0) s = (s * s) % n;
}
if (a < 0) a += n;
return a;
}
long Extended_Euclidean(long b, long n)
{
long b0 = b, n0 = n, t = 1, t0 = 0, temp, q, r;
q = n0 / b0; r = n0 - q * b0;
while (r > 0)
{
temp = t0 - q * t;
if (temp >= 0) temp = temp % n;
else temp = n - (- temp % n);
t0 = t;
t = temp;
n0 = b0;
b0 = r;

Dept of CSE, Page 89


www.Vidyarthiplus.com CSE Lab-II

q = n0 / b0;
r = n0 - q * b0;
}
if (b0 != 1)
return 0;
else
return t % n;
}
int main(void)
{
long a = 101, alpha = 4, beta = 449, e1 = 45;
long e2 = 237, f1 = 125, f2 = 9, i, j, p = 467; long q, x = 286, y = 83, c, d, C, D, r, s, t;
clrscr();
q = (p - 1) >> 1;
printf("a = %ld\n", a);
printf("alpha = %ld\n", alpha);
printf("beta = %ld\n", beta);
printf("e1 = %ld\n", e1);
printf("e2 = %ld\n", e2);
printf("f1 = %ld\n", f1);
printf("f2 = %ld\n", f2);
printf("p = %ld\n", p);
printf("q = %ld\n", q);
printf("x = %ld\n", x);
printf("y = %ld\n", y);
i = Extended_Euclidean(a, q);
c = (exp_mod(y, e1, p) * exp_mod(beta, e2, p)) % p;
d = exp_mod(c, i, p);
printf("Alice's challenge c = %ld\n", c);
printf("Bob's response d = %ld\n", d);
if (d != (exp_mod(x, e1, p) * exp_mod(alpha, e2, p)) % p)
printf("d != x ^ e1 * alpha ^ e2 mod p\n");
else
printf("d == x ^ e1 * alpha ^ e2 mod p\n");
C = (exp_mod(y, f1, p) * exp_mod(beta, f2, p)) % p;
D = exp_mod(C, i, p);

Dept of CSE, Page 90


www.Vidyarthiplus.com CSE Lab-II

printf("Alice's challenge C = %ld\n", C);


printf("Bob's response D = %ld\n", D);
if (D != (exp_mod(x, f1, p) * exp_mod(alpha, f2, p)) % p)
printf("D != x ^ f1 * alpha ^ f2 mod p\n");
else
printf("D == x ^ f1 * alpha ^ f2 mod p\n");
i = q - e2;
if (i < 0) i += q; j = q - f2;
if (j < 0) j += q;
r = (d * exp_mod(alpha, i, p)) % p;
s = exp_mod(r, f1, p);
r = (D * exp_mod(alpha, j, p)) % p;
t = exp_mod(r, e1, p);
if (s == t)
printf("Alice concludes y is a forgery\n");
else
printf("Alice does not conclude y is a forgery\n");
return 0;
}

Dept of CSE, Page 91


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:
a = 101
alpha = 4
beta = 449
e1 = 45
e2 = 237
f1 = 125 f2 = 9
p = 467
q = 233
x = 286
y = 83
Alice's challenge c = 305
Bob's response d = 109
d != x ^ e1 * alpha ^ e2 mod p
Alice's challenge C = 270
Bob's response D = 68
D != x ^ f1 * alpha ^ f2 mod p
Alice concludes y is a forgery

Dept of CSE, Page 92


www.Vidyarthiplus.com CSE Lab-II

17.) Write a program to implement n queens.


AIM:
To implement n queens Programs.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
#include<graphics.h>
class queen
{
int n,x[100];
public:
queen();
void nqueen(int,int);
int place(int,int);
};
queen::queen()
{
int k=1,n;
textcolor(GREEN);
cprintf("Enter the number of queens:");
cin>>n;
nqueen(k,n);
}
void queen::nqueen(int k,int n)
{
for(int i=1;i<=n;i++)
{
if(place(k,i))
{
x[k]=i;
clrscr();
if(k==n)
{

Dept of CSE, Page 93


www.Vidyarthiplus.com CSE Lab-II

for(int j=1;j<=n;j++)
{
textcolor(x[j]);
gotoxy(1,j);
cprintf("queen %d : %d",j,x[j]);
}
getch();
break;
}
else
nqueen(k+1,n);
}
}
return;
}
int queen::place(int k,int i)
{
int j;
for(j=1;j<=k;j++)
{
if((x[j]==i)||(abs(x[j]-i)==abs(j-k)))
return 0;
} return 1;
}
void main()
{
clrscr();
queen q;
}

Dept of CSE, Page 94


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:
Enter the number of Queens : 4
Queen 1 : 3
Queen 2 : 1
Queen 3 : 4
Queen 4 : 2
Enter the number of Queens : 8
Queen 1 : 1 1 2
Queen 2 : 5 7 8
Queen 3 : 8 4 6
Queen 4 : 6 6 1
Queen 5 : 3 8 3
Queen 6 : 7 2 5
Queen 7 : 2 5 7
Queen 8 : 4 3 4

queen 1 : 2
queen 2 : 8
queen 3 : 6
queen 4 : 1
queen 5 : 3
queen 6 : 5
queen 7 : 7
queen 8 : 4

Dept of CSE, Page 95


www.Vidyarthiplus.com CSE Lab-II

18.) Write a program to implement encryption and decryption.


AIM:
To implement encryption and decryption.
PROGRAM:
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
int main()
{
char name[30],target[30],ch,mod; //Declare Variables //
int num[100],i,option;
clrscr();
cout<<"\nEnter Your Option ";
cout<<"\n1. To Encrypt The File ";
cout<<"\n2. To Decrypt The File ";
cout<<"\nOption : ";
cin>>option;
if(option==1)
{
cout<<"\nEnter The Path Of A File Which Is To Be Encrypted : ";
gets(name);
if stream fin(name,ios::binary); //Open I/P File In A Binary Mode//
if(!fin)
{ //Show Error Occur If File Does Not Exist//
cout<<"\nError In Openinig Of A File : "; //Or Any Error Occurs //
return 1;
}
cout<<"\nEnter The New Encrypted File Name : ";
gets(target);
ofstream fout(target,ios::binary); //Open O/P File In A Binary Mode//
if(!fout)
{
cout<<"\nError In Opening Of Target File : ";
//Show Error If Any Error Occrs In Opening Of A File//
return 1;

Dept of CSE, Page 96


www.Vidyarthiplus.com CSE Lab-II

}
for(i=0;i<9;i++)
{ //Multiple for Loops For Storing The Numbers//
num[i]=i; //An Array //
}
for(i=14;i<31;i++) //Loops Will Store 100 Numbers//
{
num[i-5]=i; //which Will Encrypt The Contents Of A File//
}
for(i=33;i<=68;i++) //To Avoid Theerror Ocuur Caused By The//
{ //Enter Key,Tab Key & Space Key//
num[i-7]=i; //TheseVariations In Loops Is Made//
}
for(i=97;i<=122;i++)
{
num[i-35]=i;
}
while(fin)
{ //Open The Input File//
fin.get(ch);
if(ch==EOF)break; //Exit To Loop When End Of File//
if((ch>=97) && (ch<=122))
{ //Encrypt The Small Letters//
i=97;
mod=num[ch-i];
fout<<mod;
}
if((ch>=65) && (ch<=90))
{
i=39; //Encrypt The Capital Letters//
mod=num[ch-i]; //And Store In An Output File//
fout<<mod;
}
if((ch>=48) && (ch<=57))
{
i=4; //Encrypt The Numbers//

Dept of CSE, Page 97


www.Vidyarthiplus.com CSE Lab-II

mod=num[ch+i];
fout<<mod;
}
if((ch==10)||(ch==13))
{
mod=ch; //For Enter Key//
fout<<mod;
}
if(ch==32)
fout<<ch; //For Space Key//
if(ch==9)
fout<<ch; //For Tab Key//
if((ch>=33)&&(ch<=47))
{ //For Special Symbols// mod=ch+64;
fout<<mod;
}
if((ch>=58)&&(ch<=64))
{ //For Special Symbols//
mod=ch+54;
fout<<mod;
}
if((ch>=91)&&(ch<=96))
{
mod=ch+28; //For Special Symbols//
fout<<mod;
}
if((ch>=123)&&(ch<=126))
{
mod=ch-40; //For Special Symbols//
fout<<mod;
}
}
fin.close(); //Close The Input File//
fout.close(); //Close The Output file//
cout<<"\nYour File Is Encrypted Now........... ";
getch();

Dept of CSE, Page 98


www.Vidyarthiplus.com CSE Lab-II

return 0;
}
/*=================================================================*/
/* This Program Will Decrypt The Document */
if(option==2)
{
char name[30],target[30],ch,mod; //Declare Variables//
int num[100],i,flag;
cout<<"\nEnter The Path Of A File Name Which Is To Be Decrypted : ";
gets(name);
ifstream fin(name,ios::binary);
if(!fin) //Open The Encryped File In A Binary Mode//
{
cout<<"\nError In Opening Of A File : ";
return 1; //Show Error If File Does Not Exist//
} //Or Any Occurs In Opening Of A File//
cout<<"\nEnter The New Decrypted File Name : ";
gets(target);
ofstream fout;
fout.open(target,ios::binary); //Opens The Output File In An Binary Mode//
if(!fout)
{ //Show Error if Any Error Occurs In Opening Of A File//
cout<<"\nError In Opening Of A Target File : ";
return 1;
}
for(i=0;i<9;i++)
{
num[i]=i; //In An Array//
}
for(i=14;i<31;i++)
{
num[i-5]=i; //Loops Will Store 100 Numbers//
}
for(i=33;i<=68;i++) //Which encrypts The Document Also Decrypt It//
{
num[i-7]=i;

Dept of CSE, Page 99


www.Vidyarthiplus.com CSE Lab-II

}
while(fin)
{ //Opens The Encryped File//
fin.get(ch);
flag=0; //Turn Off Flag//
if(ch==EOF)break;
for(i=26;i<52;i++)
{
if(ch==num[i]) //Loop For Match The Small Letters Letters//
{
mod=i+39; //If Match Then Put Appropriate Letter//
fout<<mod; //In A OutPut File//
flag=1;
break ; //Turn On Flag And Exit The Loop//
}
}
if (flag==1) continue ; //If Flag Is On Then Continue Outer Loop//
for(i=0;i<26;i++)
{ //Loop For Match The Capital Letters//
if(ch==num[i])
{ //If Match Then Put Appropriate Letter//
mod=i+97; //In A OutPut File//
fout<<mod;
flag=1;break; //Turn On Flag And Exit From This Loop//
}
}
if (flag==1) continue ; //If Flag Is On Then Continue Outer Loop//
for(i=52;i<62;i++)
{ //Loop For Numerical Numbers//
if(ch==num[i])
{
mod=i-4;
fout<<mod;
flag=1; break ;
}
}

Dept of CSE, Page 100


www.Vidyarthiplus.com CSE Lab-II

if (flag==1) continue ;
if((ch==10)||(ch==13))
{
mod=ch; //Condition For Enter Key//
fout<<mod;
}
if(ch==32)
fout<<ch; //condition For Space Key//
if(ch==9)
fout<<ch; //Condition For Tab Key//
if((ch>=97)&&(ch<=111))
{
mod=ch-64; //For Special Symbols//
fout<<mod;
}
if((ch>=112)&&(ch<=118))
{
mod=ch-54; //For Special Symbols//
fout<<mod;
}
if((ch>=119)&&(ch<=124))
{
mod=ch-28; //For Special Symbols//
fout<<mod;
}
if((ch>=83)&&(ch<=86))
{ //For Special Symbols//
mod=ch+40;
fout<<mod;
}
}
fin.close(); //Close The Encrypted File//
fout.close(); //Close Your Original Decrypted File//
cout<<"\nThe File Is Being Decrypted............ ";
getch();
return 0; }
return 0;
}

Dept of CSE, Page 101


www.Vidyarthiplus.com CSE Lab-II

OUTPUT:
Enter Your Option
1. To Encrypt The File
2. To Decrypt The File
Option : 1
Enter The Path Of A File Which Is To Be Encrypted : c:\a.txt
Enter The New Encrypted File Name : c:\enc.txt

Your File Is Encrypted Now...........


Enter Your Option
1. To Encrypt The File
2. To Decrypt The File

Option : 1
Enter The Path Of A File Which Is To Be Decrypted : c:\enc.txt
Enter The New Decrypted File Name : c:\dec.txt
The File Is Being Decrypted .............

Dept of CSE, Page 102

You might also like