Advanced Programming Language Concepts (Functional Programming and Logical Programming Concepts)
Advanced Programming Language Concepts (Functional Programming and Logical Programming Concepts)
Abstract
This documentation will discuss about the two applications. The first application is detecting
Steganography (hidden messages) in images and implemented by using Haskell. To design and
implement of all image processing steps and detection processes use the features of functional
programming and provide the ability of reusability and future enhancement.
The other application is providing details of the Solar system using prolog programming language.
The concepts and features of logical programming languages are used to design and implement
that application.
List of Figures
Figure 1: Main Menu........................................................................................................14
Figure 2: Image Gallery...................................................................................................15
Figure 3: Select LSB Tool................................................................................................15
Figure 4: Detect Hidden Messages.................................................................................16
Figure 5: User Manual.....................................................................................................17
Figure 6: Exit....................................................................................................................17
Figure 7: Query 1.............................................................................................................40
Figure 8:: Query 2............................................................................................................40
Figure 9:Query 3..............................................................................................................40
Figure 10:Query 4............................................................................................................40
Figure 11;:Query 5...........................................................................................................41
Figure 12:Query 6............................................................................................................41
Figure 13:: Query 7..........................................................................................................41
Figure 14: Query 8...........................................................................................................41
Figure 15:Query 9............................................................................................................41
Figure 16:Query 10..........................................................................................................42
Figure 17:Query 11..........................................................................................................42
Figure 18:Query 12..........................................................................................................42
Figure 19:Query 13..........................................................................................................42
Figure 20:Query 14..........................................................................................................42
3
1 Functional Programming
1.1 Introduction
The functional programming paradigms are purely based on mathematical discipline. Collection of
functions made up the whole program. Also not like the imperative programming languages, those
are avoided the side effects.
In this application detect the hidden massages inside the images using Haskell functions. It holds
the five images with the hidden messages. To represent the images use the concept of pixels. Each
pixel includes the binary value of R G B colors. Likewise hold the several pixel data to represent
the images. Then provide the several Steganalysis tools to user to select one of the tools for the
detection process. Finally hidden message will be detecting according to the selected tool.
The following are the functional features that applied in this application.
Divide the application in to several modules to increase the readability and allow for future
enhancement.
1.2. Scope
Users only be able to use the images that listed in the application.
5
Users only be able to use the Steganalysis LSB tools which listed in the application.
1.3 Assumptions
The stated ASCII values are same as the Unicode character values.
Messages are hidden from the beginning to the end continuously in the image.
1.5
Type
Usage
7
Image
Pure functions
Function
Type
Usage
Separate the R, G, B color values into
separateColors
Image ([Int],[Int],[Int])
separate lists.
[(Int, Int, Int)] ([Int],[Int],[Int])
Filter only the red color values.
(based on input value)
getRvalue
getGvalue
([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[00110]
Filter only the green color values.
getBvalue
([Int],[Int],[Int]) [Int]
([11100],[00110],[11000])[10100]
Split the individual values into a list.
splitValue
Int [Int]
11100 [1,1,1,0,0]
[Int] [Int]
[10001,11110,11111] [1,0,1]
isElement
Int Bool
existing or not.
Converting the integer values into
binaryToChar
Int Char
Type
Usage
Take the splitValue function (split
individual values) and the required
integer list as parameters and split all
the values in to one list.
splitValues
[1,1,1,1,0,0,0,1,0,1,0,1]
Take each 5th element from the splitted
list in to separate list. Get
getNth
[Int] [Int]
as inputs.
[1,1,1,1,1,0,0,0,0,0] [1,0]
9
Type
Usage
map
(a b) [a] [b]
concatMap
unzip3
take
drop
concat
[[a]] [a]
10
read
String a
show
a String
Type
Usage
type
Primitive recursion
Function
getLSB
individual value.
[Int] [Int]
[11110,10001,11111] [0,1,1]
Creates the groups of splitted
elements.
First take the first five element
(character ASCII size) and then drop
groupSpliter
[Int] [Int]
binaryToString
[Int] String
IO Functions
Name
Type
Usage
askUser
IO ()
Modules
Name
Type
Usage
common
Common.hs
application.
images
Images.hs
Steganalysis.hs
main
Main.hs
1.6
Screens
Main menu
13
This is the main menu of this application. This will provide the ability to select an option at a time.
Image Gallery
14
Application will display the images after selecting option 1. User must require toselect an image to
run the application.
After selecting option 2, steganalysis LSB tools will be displayed. User must require selecting one
of the tools to detect the hidden message.
15
After selecting steganalysis LSB tool, application will be detect the hidden message and displays it.
User Manual
16
If select option 4, user will be able to see the instruction of the application.
Exit
Figure 6: Exit
17
Expected output
Actual output
Main module
user
software).
selects
option
detection tools.
If
user
selects
option
3,
message.
Displays the software instructions
If
user
selects
required
to
option
display
4,
the
with
the
menu
name
instructions.
software instructions.
Terminate the application.
If
user
required
selects
to
terminate
application.
Image module
option
5,
the
Common module
Steganalysis module
the message
of
Successfully
detected!!
(Therefore functions which under
this modules work properly).
1.7
Source Code
Main.hs
module Main where
19
main=do askUser
askUser :: IO ()
askUser
= do putStrLn " "
putStrLn "(Detecting Steganography (hidden messages) in Images) "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "\t \t******************************"
putStrLn "\t \t** STEGANALYSIS SOFTWARE **"
putStrLn "\t \t**
**"
20
IMAGE GALLARY
**"
21
**"
do
if(choice2=="a")
then
do let im = image1
--print im
return im
putStrLn " "
else if(choice2=="b")
then
do let im = image2
--print im
return im
putStrLn " "
else if(choice2=="c")
then
do let im = image3
--print im
return im
putStrLn " "
22
else
do let im = image5
--print im
return im
putStrLn " "
else if(choice1=="2")
then
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "Please select LSB Steganography Tool: "
putStrLn " "
putStrLn " "
putStrLn "\t \t [1] Stego one bit RED color "
putStrLn " "
putStrLn "\t \t [2] Stego one bit GREEN color "
putStrLn " "
putStrLn "\t \t [3] Stego one bit BLUE color "
23
do
if(choice3=="1")
then
do let get_red = getRvalue
--print get_red
return get_red
putStrLn" "
else if(choice3=="2")
then
do let get_green = getGvalue
--print get_green
return get_green
putStrLn" "
else
else if(choice1=="3")
then
24
else if(choice1=="4")
then
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn "\t \t******************************"
putStrLn "\t \t**
INSTRUCTIONS
25
**"
**"
else
do putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " "
putStrLn " \t \t Thank you for using!!"
putStrLn " "
26
images.hs
module Images where
image1 :: Image
image2 :: Image
image3 :: Image
image4 :: Image
image5 :: Image
image1
=
(11011,10001,10011),
[(10001,10001,10101),(11000,10010,10000),(11100,10100,11110),(11110,10000,10100),
(11111,10001,10101),(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),
(11110,11010,10000),
(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(10001,11001,10001),
(10111,10001,11111),
(11001,10011,10001),(11101,10101,11111),(11111,10001,10101),(11011,10001,10011),
(10001,11101,11111),
(10101,11101,10111),(10011,10011,10101),(11001,11001,10111),(11001,10001,10101),
(11001,10011,11101)]
image2
=
(11111,10111,11011),
[(11001,10001,10111),(11011,10001,10011),(11101,10111,11111),(10100,10100,11100),
(11111,10001,10011),(10001,10101,10011),(10010,10010,10100),(10001,11001,10001),
(10111,10001,11111),
(10001,10001,10101),(11001,10011,10001),(11101,10101,11111),(11111,10001,10101),
(11011,10001,10011),
27
image3
=
(11001,10011,10001),
[(10011,10111,11111),(11110,10000,10100),(11111,10001,10011),(10101,11101,10111),
(11001,10011,10001),(11101,10101,11111),(11111,10001,10101),(11010,10000,10010),
(10000,11100,11110),
(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(11111,11011,10001),
(10001,11101,11111),
(11111,10001,10101),(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),
(11111,11011,10001),
(10101,11001,10011),(10101,10111,11111),(11111,10111,11011),(11111,10001,10101),
(10111,11111,10001)]
image4
=
(10011,10111,11111),
[(10101,11101,10111),(10011,10011,10101),(10100,10100,11100),(11000,10010,10000),
(10101,11101,10111),(10010,10010,10100),(11000,11000,10110),(11001,10001,10101),
(11001,10011,11101),
(11111,10001,10101),(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),
(11111,11011,10001),
(11111,10001,10011),(10001,10101,10011),(10011,10011,10101),(10001,11001,10001),
(10111,10001,11111),
(11001,11001,10111),(11001,10001,10101),(11001,10011,11101),(11001,11111,10101),
(11101,10101,11001)]
image5
=
(10010,10010,10100),
[(11011,10101,10001),(11111,10111,11011),(11110,10000,10100),(10000,10100,10010),
(11111,10001,10101),(11110,10000,10010),(10100,11100,10110),(10100,10100,11100),
(11110,10110,11010),
(11011,10101,10001),(11111,10111,11011),(11111,10001,10101),(10001,10101,10011),
(10011,10011,10101),
(10011,10111,11111),(11111,10001,10101),(11111,10001,10011),(10101,11101,10111),
(11001,10011,10001),
28
common.hs
module Common where
splitValues ::(Int -> [Int])-> [Int] -> [Int]
splitValues f x = concatMap f x
splitValue :: Int -> [Int]
splitValue 0 = []
splitValue x = splitValue (x `div` 10) ++ [x `mod` 10]
getAboveNth:: Int -> [Int] -> [Int]
getAboveNth _ [] = []
getAboveNth n xs = head xs : getAboveNth n (drop n xs)
getNth :: (Int -> [Int] -> [Int]) -> Int -> [Int] -> [Int]
getNth f n = f n . drop (n-1)
getLSB :: [Int] -> [Int]
getLSB [] = []
getLSB (x:xs) = (x `mod` 2) : getLSB xs
groupSpliter ::[Int]->[Int]
groupSpliter []=[]
groupSpliter xs = toSingleNum (take 5 xs):(groupSpliter (drop 5 xs))
where toSingleNum ys = read $ concat $ map show ys
isElement :: Int -> Bool
isElement x | x==11111 || x==11110 || x==11101 || x==11011 || x==10111 || x==11100 || x==11001 || x==10011 ||
x==11000 || x==10001 = True
|otherwise
= False
29
Steganalysis.hs
30
2 Logical Programming
2.1 Introduction
Logical paradigms are based on the basic facts and rules relations according to the problem
domain. Therefore those are seems less natural in more general areas of computation. Collection of
facts and rules are made up the whole program and required to generate queries to run the program.
This application is about the solar system. At the beginning, enter the basic details of the solar
system as facts in to the application. Then user will be able to ask questions about the solar system
using queries.
The following are the logical features that applied in this application.
Create different kind of facts, such as simple facts, facts with one argument, facts with two
arguments and facts with more arguments.
31
2.2 Scope
Due to large scale of the solar system, provide only planets details.
2.3 Assumptions
32
Facts
Simple facts
Fact
Explanation
solar_system_is_elliptical_in_shape.
the_Sun_is_in_the_center_of_the_solar_system.
our_solar_system_is_always_in_motion.
the_Sun_is_the_biggest_object_in_our_solar_system.
solar_system_is_more_than_4_billion_years_old.
33
explanation
planet(mercury).
Mercury is a planet.
planet(venus).
Venus is a planet.
planet(earth).
Earth is a planet.
planet(mars).
Mars is a planet.
planet(jupiter).
Jupiter is a planet.
explanation
planet_of(mercury,solar_system).
similar(venus,earth).
calledAs(mars,red_planet).
moons(fobos,dimos,mars).
explanation
explanation
brightest(sun,solar_system).
,days_59 ,no_natural_planets).
own,no of satellit)
Rules
Rule
explanation
If ,
high_temperature(sun).
high_temperature(venus).
high_temperature(jupiter).
impossible_to_live(X):- high_temperature(X).
no_oxygen(X):- impossible_to_live(X).
no_water(X):-
oxygen.
no_oxygen(X).
no_oxygen(X).
no_oxygen(X).
no_oxygen(X).
If,
temp_high(saturn).
no oxygen in pluto.
oxy_less(saturn).
no oxygen in Saturn.
wat_less(mars).
no water in mars.
wat_less(saturn).
no water in Saturn.
high_temp(venus).
oxy_no(mars).
no oxygen in jupiter.
oxy_no(jupiter).
no oxygen in venus.
wat_no(venus).
no water in venus.
wat_no(mars).
no water in mars.
wat_no
(Z).
wat_no(Z).
wat_no(Z).
If,
bigger_than(earth,mercury).
bigger_than(saturn,earth).
bigger_than(earth,pluto).
smallest(Y,X):-
biggest
biggest(X,Y).
If,
closer(sun,mercury).
closer(mercury,venus).
closer(venus,earth).
beyond(X,Y):- closer(X,A),closer(A,B),closer(B,Y).
beyonds(X,Y):-closer(X,Z),closer(Z,Y).
can_see(X) :-
(X),
closer
(X,
planet(X),
planet(X),
Queries
37
earth).
result
?-solar_system_is_elliptical_in_shape.
true.
?-the_Sun_is_in_the_center_of_the_solar_system.
true..
?-our_solar_system_is_always_in_motion.
true.
?-the_Sun_is_the_biggest_object_in_our_solar_system.
true.
?-solar_system_is_more_than_4_billion_years_old.
true.
result
?-planet(mercury).
true.
?-planet(venus).
true.
?-planet(star).
false.
?-planet(astroid).
false.
result
?-planet_of(mercury,solar_system).
true.
?-similar(venus,earth).
true.
?-bigger(jupiter,mars).
false.
?-moons(fobos,dimos,saturn).
false.
result
38
true.
?-planets(mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,star).
false.
?-planets(astroid,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).
false.
?-planets(astroid,venus,earth,mars,satellite,saturn,uranus,neptune,pluto
false.
result
?- brightest(Who,solar_system).
Who = sun.
Which_is_first
mercury.
?- planet(2,venus,Rev_around_sun,days_243,no_natural_planets).
Rev_around_sun
days_225.
?- planet(3,earth,year_1,Rev_around_own,one_natural_planets).
Rev_around_own
hrs_24.
?- planet(4,mars,year_2,hrs_25,Howmay_natural_planets).
Howmay_natural_planets
= two_natural_planets.
result
?- high_temperature(X).
?- high_temperature(venus).
true.
?- impossible_to_live(pluto).
false.
?- impossible_to_live(X).
?- no_oxygen(X).
?- cant_live_in(Y).
Y = saturn.
?- cant_live_in(saturn).
true.
?- cant_live_in(pluto).
false.
39
?- impossible_to_live_in_planet(mars).
true
?- impossible_to_live_in_planet(earth).
false.
Screen Shorts
1. solar_system_is_elliptical_in_shape.
Figure 7: Query 1
2. the_Sun_is_in_the_center_of_the_solar_system.
3. planet(mercury).
Figure 9:Query 3
4. planet(venus).
Figure 10:Query 4
5. planet_of(mercury,solar_system).
40
Figure 11;:Query 5
6. similar(venus,earth).
Figure 12:Query 6
7. planet_of(X,solar_system).
8. similar(venus,X).
9. planets(mercury,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).
Figure 15:Query 9
10. planets(A,B,earth,mars,jupiter,saturn,uranus,neptune,pluto).
41
Figure 16:Query 10
11. planets(A,venus,earth,mars,jupiter,saturn,uranus,neptune,pluto).
Figure 17:Query 11
12. brightest(Who,solar_system)
Figure 18:Query 12
Figure 19:Query 13
14. high_temperature(X).
Figure 20:Query 14
15. impossible_to_live(sun).
Figure 21::Query 16
42
Figure 22:Query 17
17. cant_live_in(Y).
Figure 23:Query 19
18. cant_live_in(saturn).
Figure 24:Query 20
19. impossible_to_live_in_planet(Z).
Figure 25:Query21
20. biggest(X,pluto).
Figure 26:Query22
43
44