Monday, January 23, 2006
Tourism Adviser - Expert System in Prolog
Title: : Tourism Adviser Expert System
Author : Ferad Zyulkyarov
Date : 23.01.2006
University : Dokuz Eylul University
Department : Computer Engineering
Course : CSE423 Logic Programming and Expert Systems
Lecturer : Prof. Dr. Tatyana Yakhno
This is a very simple Expert System implemented in prolog (Visual Prolog).
It captures the knowledge of a hotel adviser. The knowledge base consists
of the "hotel" type facts that each fact specifies a single hotel.
The expert system begins running by unifying (staring) from the first
occurrence of the "run" predicate. It asks the user for a general
question. Depending on the given answer, the execution flow (unification)
branches on the corresponding "suitable_for" rule. The backtracking
continues until all rules have been exhausted (all solutions are found),
not until finding the first matching (solution).
The solution consists of two general types of rules:
1) derivation rules that are defined by "suitable_for" predicate;
2) and utility rules:
- price;
- ask_attribute;
- clear_facts;
- location_to_distance;
- clear_facts.
The entry point of the program is the first "run" rule.
References:
(1) PDC, Visual Prolog Language Tutorial, "Building a Small
Expert System", p.439-p.444, 2001
(2) Simple tourism adviser Expert System, avalable online at:
http://www.generation5.org/content/2002/prg01.asp,
last accessed on 08.12.2005
*/
facts
/*
hotel(Name, Distance, Stars, Season, Animation, Suit, Catering, BuildingType)
Specifies a hotel.
Name - the name of the hotel
Distance - the distance to the nearest city in kilometers.
Stars - the number of stars assigned to the hotel (1-5)
Season - the seasons that the hotel is open
summer - only summer
winter - only winter
all - all seasons
Animation - whether the hotel has animation (yes/no)
Suit - whether the hotel has a suit room (yes/no)
Catering - specifies the type of catering the hotel provides
all - all inclusive
breakfast - only breakfast
self - nothing
BuildingType - is the type of the rooms the hotel has
0 - only rooms
1 - only apartments
2 - only bungalow
3 - all the above
*/
hotel(string, integer, integer, symbol, integer, integer, symbol, integer)
/*
attribute(AttributeName, AttributeValue)
A pair of attribute name and value in the memory database.
AttributeName - is the name of the attribute.
AttributeValue - is the value of the attribute.
*/
attribute(symbol, symbol)
predicates
/*
The entri point of the program.
*/
nondeterm run
/*
Clears collected facts.
*/
clear_facts - determ ()
/*
ask_attribute(AttributeName, Message, AttributeValue)
Asks the user for the value of the attribute. The question
is accompanied with the message.
Inputs:
AttributeName - the name of the attribute
Message - the message associated with the question; can be
the possible values.
Outputs:
AttributeValue - the value of the attribute entered by the user.
*/
ask_attribute(symbol, symbol, symbol) - nondeterm (i, i, o)
/*
suitable_for(Criteria, Hotel)
Checks whether the specified hotel satisifes (is suitable for)
the specified criteria.
Input:
Criteria - the criteria
Hotel - the hotel
*/
nondeterm suitable_for(symbol, symbol)
/*
location_to_distance(Location, MinLimit, MaxLimit)
Obtains the range for the distance of the hotel.
Input:
Location - is the location (city or resort)
Output:
MinLimit - the minimum distance allowed
MaxLimit - the maximum distance allowed
*/
location_to_distance(symbol, integer, integer) - nondeterm (i, o, o)
/*
price(Hotel, Price)
Checks the price of the hotel. The test is done based onthe
stars of the hotel.
Inputs:
Hotel - the hotel to be checked
Output:
Price - the price category (expensive, moderate or cheap).
*/
nondeterm price(symbol, symbol)
clauses
% declaration of the facts
hotel("Hilton", 0, 5, all, 0, 1, breakfast, 0).
hotel("Efes", 1, 4, all, 0, 1, breakfast, 0).
hotel("Titanik", 550, 5, summer, 1, 1, all, 3).
hotel("Cesme Sheraton", 110, 5, summer, 1, 0, all, 0).
hotel("Lara", 110, 3, summer, 1, 0, all, 2).
hotel("Babadan", 1, 3, all, 0, 0, self, 0).
hotel("Bornova Yurt", 8, 1, all, 0, 0, self, 0).
hotel("Uludagi", 450, 5, winter, 1, 0, all, 2).
hotel("Kars", 900, 3, winter, 0, 0, all, 3).
hotel("Abant", 600, 3, winter, 0, 0, all, 1).
hotel("Bolu", 420, 3, winter, 0, 0, breakfast, 0).
hotel("Sari Kamis", 880, 4, winter, 0, 0, all, 3).
% The entry point
run:-
ask_attribute(location, "{resort, city}", Location),
hotel(Hotel, _, _, _, _, _, _, _),
suitable_for(Location, Hotel),
write("Suitable Hotel: ", Hotel),
nl, fail.
run:-
write("\nUnable to advise a hotel.\n"),
clear_facts,
readchar(_).
/* Utility Rules */
clear_facts:-
write("Please press the space button to exit.\n"),
retractall(_, dbasedom),
readchar(_).
ask_attribute(Attr, PossibleValues, AttrValue):-
attribute(Attr, AttrValue), !;
write("Enter ", Attr, " ", PossibleValues, " : "),
readln(AttrValue),
assertz(attribute(Attr, AttrValue)).
location_to_distance(Location, MinLimit, MaxLimit):-
Location = resort, MinLimit = 50, MaxLimit = 1000;
Location = city, MinLimit = -1, MaxLimit = 10;
Location = airport, MinLimit = 10, MaxLimit = 50.
price(Hotel, Cost):-
hotel(Hotel, _, Stars, _, _, _, _, _),
Stars >3, Stars < 6, Cost = expensive;
hotel(Hotel, _, Stars, _, _, _, _, _),
Stars > 1, Stars < 4, Cost = moderate;
hotel(Hotel, _, Stars, _, _, _, _, _),
Stars = 1, Cost = cheap.
/* Derivation rules */
suitable_for(city, Hotel):-
location_to_distance(city, MinLimit, MaxLimit),
hotel(Hotel, Distance, _, _, _, _, _, _),
Distance > MinLimit,
Distance < MaxLimit,
ask_attribute(trip_type, "{business, city visitation}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for(resort, Hotel):-
location_to_distance(resort, MinLimit, MaxLimit),
hotel(Hotel, Distance, _, _, _, _, _, _),
Distance > MinLimit,
Distance < MaxLimit,
ask_attribute(season, "{summer, winter}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for(business, Hotel):-
price(Hotel, Cost),
Cost = expensive.
suitable_for("city visitation", Hotel):-
price(Hotel, Cost),
Cost = moderate;
price(Hotel, Cost),
Cost = cheap.
suitable_for(summer, Hotel):-
hotel(Hotel, _, _, summer, _, _, _, _),
ask_attribute(guest_typem, "{honey month, friends, family, alone}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for(winter, Hotel):-
hotel(Hotel, _, _, winter, _, _, _, _),
ask_attribute(guest_type, "{honey month, friends, family, alone}", AttrVal),
suitable_for(AttrVal, Hotel).
suitable_for("honey month", Hotel):-
hotel(Hotel, _, 5, _, _, 1, all, _).
suitable_for(friends, Hotel):-
hotel(Hotel, _, _, _, _, _, _, RoomType),
RoomType > 0,
price(Hotel, Price),
not(Price = expensive).
suitable_for(family, Hotel):-
hotel(Hotel, _, _, _, 1, _, all, RoomType),
RoomType > 0,
Price(Hotel, Price),
not(Price = expensive).
suitable_for(alone, Hotel):-
hotel(Hotel, _, _, _, _, _, _, 0),
price(Hotel, Price),
not(Price = cheap).
goal
run.
Tuesday, January 10, 2006
Kerberos – Explained Shortly
Protocol Description
Kerberos uses as its basis the Needham-Schroeder protocol. It makes use of a trusted third party, termed a Key Distribution Center (KDC), which consists of two logically separate parts: an Authentication Server (AS) and a Ticket Granting Server (TGS). Kerberos works on the basis of "tickets" which serve to prove the identity of users.
Kerberos maintains a database of secret keys; each entity on the network — whether a client or a server — shares a secret key known only to itself and to Kerberos. Knowledge of this key serves to prove an entity's identity. For communication between two entities, Kerberos generates a session key which they can use to secure their interactions.
ScenarioThis section gives an example of the Kerberos protocol in action. The following abbreviations will be used:
AS –Authentication Server;
TGS – Ticket Granting Server;
SS – Service Server.
In one sentence: the client authenticates itself to AS, then demonstrates to the TGS that it's authorized to receive a ticket for a service (and receives it), then demonstrates to the SS that it has been approved to receive the service, see the figure below.
In more detail:
A user enters a username and password on the client.
The client performs a one way hash on the entered password, and this becomes the secret key of the client.
The client sends a clear-text message to the AS requesting services on behalf of the user. Sample Message: "User XYZ would like to request services". Note: Neither the secret key nor the password is sent to the AS.
The AS checks to see if the client is in its database. If it is, the AS sends back the following two messages to the client:
Message A: Client/TGS session key encrypted using the secret key of the user.
Message B: Ticket-Granting Ticket (which includes the client ID, client network address, ticket validity period, and the client/TGS session key) encrypted using the secret key of the TGS.
Once the client receives messages A and B, it decrypts message A to obtain the client/TGS session key. This session key is used for further communications with TGS. (Note: The client cannot decrypt the Message B, as it is encrypted using TGS's secret key.) At this point, the client has enough information to authenticate itself to the TGS.
When requesting services, the client sends the following two messages to the TGS:
Message C: Composed of the Ticket-Granting Ticket from message B and the ID of the requested service.
Message D: Authenticator (which is composed of the client ID and the timestamp), encrypted using the client/TGS session key.
Upon receiving messages C and D, the TGS decrypts message D (Authenticator) using the client/TGS session key and sends the following two messages to the client:
Message E: Client-to-server ticket (which includes the client ID, client network address, validity period) encrypted using the service's secret key.
Message F: Client/server session key encrypted with the client/TGS session key.
Upon receiving messages E and F from TGS, the client has enough information to authenticate itself to the SS. The client connects to the SS and sends the following two messages:
Message G: the client-to-server ticket, encrypted using service's secret key.
Message H: a new Authenticator, which includes the client ID, timestamp and is encrypted using client/server session key.
The server decrypts the ticket using its own secret key and sends the following message to the client to confirm its true identity and willingness to serve the client:
Message I: the timestamp found in client's recent Authenticator plus 1, encrypted using the client/server session key.
The client decrypts the confirmation using its shared key with the server and checks whether the timestamp is correctly updated. If so, then the client can trust the server and can start issuing service requests to the server.
The server provides the requested services to the client.
