Document 4
Document 4
Document 4
INTRODUCTION :
File transfer can be done in both directions i.e. server to the node and node to
the server, operating at the terminal.
Facility to send urgent messages from node to the server had been provided.
The users can share printer. The users working on the nodes can utilize a
printer connected to the server.
Directory service of the server had been provided to the users working on
different nodes. This helps in locating files on the file server.
More than two computers can be connected, i.e. two computers are
connected to the server to demonstrate the ability and the server can access
both the nodes.
For better security, each character was encrypted and the transmitted over
the line. On reaching the destination, it was decrypted back to the original
form. This process is similar to the function of presentation layer of a LAN.
ANALYSIS :
being corrupted or used in unauthorized fashion. One of the ways in which you
can ensure the privacy of your data is by cryptography.
Passive Active
Intruder Intruder
Just Listens Intruder Can alter
Messages
Encryption Decryption
Plain Text Method Method
Software Requirements:
Hardware Requirements :
RAM : 128MB.
DESIGN :
♦ Concealment ciphering
♦ Transposition ciphering
♦ Substitution ciphering
♦ Other techniques.
1. Concealment cipher,
2. Transposition cipher , and
3. Substitution cipher.
In transportation cipher, the true letters of the secret message are taken
out of their text-order, and are rearranged or “scrambled” according to the key
pattern.
In substitution cipher, the original letters are replaced with substitutes or
cipher-symbols, and these symbols are arranged in the same order as their
originals. Popular, hobby type cryptograms usually leave word spacing and
punctuation in place, and eliminate all cipher alphabet patterns that cause any
letter to equal the same letter in the standard alphabets. These cryptograms are
called “ aristocrats”. Word spacing and punctuation is “dead give always” to the
experienced analysts. Hence to make a cipher just a bit more secure it can be
reduced to five or six letter code groups, eliminating original word spacing and
punctuation. In this context, cipher text is referred to as code groups when its
letters are spaced five or six letters to a group. A code system is more
cumbersome than a cipher system, since the code book (or the key) that must
necessarily be provided contains a long list of words, phrases or sentences. A
single number can stand for one or more words as
A code book can be quite bulky, and must be always guarded carefully. A
pair of code books with symbols arranged at random would afford a high degree
of secrecy. This type of effort for producing secret code is referred to as encoding
and reducing them to the plain text is called decoding. Even though, they offer
the highest degree of secrecy the code book becomes worthless if comprised
without the knowledge of the parties in communication.
1. CONCEALMENT CIPHERING:
It is the oldest known secret writing method in which cipher text seems to
be like a plain message. It is difficult to suspect that it is conveyer of a secret
communication. The oldest application is found in the ancient device of writing
the secret message on the Shaved head of the slave, and dispatching the slave
after his growing hair had covered the message. Another device is some what
more practical: The secret message is written on a wooden tablet, then covered
with wax coating, and second message is written on the top.In the Middle Ages,
the development over concealment writing called puncture cipher was used. This
was very famous in England, and was used to avoid the payment of postage.
This puncture cipher was practiced by simply punching holes with pintos that
these letters when read in regular order would convey desired information.
Concealment cipher is known by various names such as NULL cipher, OPEN
LETTER cipher, CONVENTIONAL WRITING, DISSIMILATED WRITING and so
the name NULL cipher means that the cryptograph has a great portion of letters
null or insignificant letters and only a few truly significant letters convey the
meaning. For example, the message: To those friends considering, it is
always news but all filled ciphers disturb happiness with varied answer,
give the concealed meaning THIS IS A NULL CIPHER. This is obtained by
reading a first letter in first word, second letter in second word, and so on. There
are many other ways. For instance: inspect details for Trigleth-acknowledge the
bonds from fewer can be written down in rows as shown below.
I N SP E C T
DE TA I L S
FO R
TR IGL E T H
AC KNOW L EDGE
TH E
BO NDS
F R OM
F E WE L L
From this the decryptor can find out that the third column gives the secret
message, STRIKE NOW.
2. TRANSPOSITION CIPHERING:
A D E H I L M P
B C F G J K N O
Plaintext : ABCDEFGHIJKLMNOP.
Cryptogram (a) : ADBCE HFGIL JKMPN O.
Cryptogram (b) : ACBDE GFHIK JLMON P.
Cryptogram (c) : ADEHI LMPBC FGJKN O.
If the message is for instance ABCDE, the above figure gives many simple
ways in which a plaintext can be enciphered by transposition of letters. In
cryptogram (a) and (b) the letters of a unit are still together whereas in
cryptogram (c), the letters of one unit has been mixed with letters of another unit.
The decrypted message can be obtained by transpositioning in opposite way.
MAGIC SQUARE:
8 1 6
3 5 7
4 9 2
KNIGHT’S TOUR:
1 4 53 18 55 6 43 20
52 17 2 5 38 19 56 7
3 64 15 54 31 42 21 44
16 51 28 39 34 37 8 57
63 14 35 32 41 30 45 22
50 27 40 29 36 33 58 9
13 62 25 48 11 60 23 46
26 49 12 61 24 47 10 59
The first letter of plain text is placed at the cell indicated by numeral one,
second letter at 2, third at 3 and so on. Once the job of positioning is over, the
cipher text is ready and can be written row-wise. Geometric transposition is also
called unit transposition.
An example of complete unit transposition is indicated below which
corresponds to the message: Blow the Naval Airbase on Republic Day KKK
(32 letters plus 3 nulls) is written in form of block with five letters per row.
B L O W T
H E N A V
A L A I R
B A S E O
N R E P U
B L I C D
A Y K K K
Cryptograms:
(a) By descending verticals:
BHABN BABEL ARLYO NASEL… ,etc.
(b) By alternating verticals from the top right:
TVROU DKKCP EIAWK IESAN OYLRA… ., etc.
(c ) By diagonals:
BHNAE OBLNW NAAAT BRSIV ALEER …, etc.
Both the writing in and taking off follow a rule, and hence the cipher is
also called route transposition and some times rectangle transposition.
Decryptment is absolutely based on trials on the known routes. Major problem
that an analyst encounters is the dimensions.
One of the simple method of transpositioning the letters is obtained by
dividing the given plain text into two strings and forming cipher text by writing
down alternate letters as
B L O W T H E NAVALA I R B
AS E O N R E P U B L I C DAY
Cipher text: BAL SOE WOT NHR EEN PAU VBA LLI ACI DRA BY
This looks like zigzag way of arrangement. This is of regular type. The
irregular type of transposition is comparatively complex with higher degree of
difficulty, the simplest being RAIL-FENCE Cipher. In this the arrangement of
letters look like the fencing provided for guarding the rail track. For instance the
above plain text may be represented as,
B T A A A N U C
L W H N V L I B S O R P B I D Y
O E A R E E L A
Cipher text: BTA AAN UCL WHN VLI BSO RPB IDY OEA REE LA.
Rather than remembering the system, which changes from time to time, it
will be better to use the same system, but is governed by the changeable
numeric key or a code word. For example a numeric key 4731256 can be derived
from the keyword NUMBERS by arranging letters in it alphabetically. Using this
keyword the cipher text for the above plain text will be
N U M B E R S
4 7 3 1 2 5 6
B L O W T H E
N A V A L A I
R B A S E O N
T H E R E P U
B L I C D A Y
Cipher text:
In this cipher, seven letters or seven numbers implies seven columns and
hence the key-length is seven. The decryptment is just opposite to encryptment,
and is completely based on how it is written in and taken off. This cipher is called
nihilist transposition. This cipher text may be again sent to cipherment applying
the keyword column wise, thus making the task of decryptment highly difficult.
A D V I C E A D V I C E A D V I C E A
1 8 17 14 5 11 2 9 18 15 6 12 3 10 19 16 7 13 4
Plain text: B L O W T H E N A V A L A I R B A S E
Plaintext: B L O W T H E N A V A L A I R B A S E
1ST Encipherment
N U M B E R S
4 7 3 1 2 5 6
B L O W T H E
N A V A L A I
R B A S E X X
2nd Encipherment
N U M B E R S
4 7 3 1 2 5 6
W A S T L E O
V A B N R H A
X E I X L A B
The columns of the upper block are always used directly as rows in the
lower block and then columns of the lower block are taken off as cryptogram.
This kind of ciphers take the decryptor to trace for the length of the keyword and
hence time of several hours or several days. The double columnar transposition
can be made much complex when the key length is made long and the columns
short, and can be made further more complicated by carrying out cipheremnet a
third time; a different key with each new block can perhaps be used
3. SUBSTITUTION CIPHER:
As the name indicates, a substitution cipher makes use of a set of symbols
or letters to replace the existing letter with a new letter or symbol at that place.
This kind if ciphering is used in the daily life also: The Morse code which uses
dots and dashes, the Braille which is used for blind, the drum language of the
African jungles, and so on. A cipher text as such is a difficult task to crack for a
decryptor. The decryptor has to deal with a cryptogram, which consists of
arbitrary science, and he begins the decryption by making a substitution of his
own, by replacing each unfamiliar symbol with a letter or number.
The substitution cipher is classified into four major groups as given below:
Simple Substitution makes use of only one cipher alphabet; also called as
mono-alphabetic substitution.
Alphabet:
AB C DE FG H I JK L MN O P Q R S T UVWXYZ
Substitute:
FG H I J KL M NO P Q R S T U V W X Y Z ABCDE
Cipher text:
GQTB YMJ SFAFQ FNWGFXJ TS YMJ WJUZGQNH IFD.
This can be rewritten into groups of three letters or five letters according to
the choice of the user. The plain text can be again found out by producing a shift
of five but in reverse side. Producing the inverse alphabet and substituting it does
another method of producing a cipher text. The inverse alphabets are given
below.
Alphabet:
A B C D E F G H I J K L MN O P QR S TU V WX Y Z
Substitute:
Z Y X W VU T S RQ P O NM L K J I H GF E D C B A
The same plain text would look as the following cryptogram once
enciphered using the inverse cipher.
Cipher text:
YOLD GSV MZEZO ZRIYZHV LM GSV IVKFYORX WZB.
α a) A B C D E F G H I J K L M
NOPQRSTUVWXYZ
b)A B C D E F G H I J K L M
SRQPONZYXWVUT
c)E X A C T L Y B D F G H I
ZWVUSRQ PONMKJ
d)E X A C T L Y B D F G H I
J K M NO P Q R S U V W Z
Alphabet :
ABCDEFGH I J K L M NO PQRSTUV WXY Z
Cipher(a) :
EBKSXDMUAFN V C GOWTHPZL I Q Y J R
Cipher(b) :
EBNZXDOA FPG Q H RC I S TJULK V YMW
Ciphre(c) :
C J Q X D K R YAH O B F MTE LSZBI P WGN U
ABC D E F G H I J K L MNO P Q R S T U V W X Y Z
A ABC D E F G H I J K L M NO P Q R S T U V WX Y Z
B BCD E F G H I J K LM N O P Q R S T UV W X Y Z A
C CDE F G H I J KL MN O P QR S T U VW X Y Z A B
D DEF G H I J K LMNO P Q RS T U V WX Y Z A B C
E EFG H I J K LMNO P Q R ST UV W X Y Z A B C D
F FGH I J K LM N O PQ R S T UVW X YZ A B C D E
G GH I J K L MN O P Q R S T U VWX Y ZAB C D E F
H H I J K L M N O PQ R S T U V WXY ZABC D E F G
I I J K L M N O P Q RS T U V W X YZ ABCDE F G H
J J K L M N O P Q R S T U V W X Y ZA B C DE F G H I
K K L M N O P Q R S T U V W X Y Z AB CDE FG H I J
L L M N O P Q R S T U V W X Y Z A BC DEF GH I J K
M M N O P Q R S T U V W X Y Z A B CDE FG HI J K L
N N O P Q R S T U V W X Y Z A B C DE F GH I J K LM
O O P Q R S T U V W X Y Z A B C DE F G H I J KL M N
P P Q R S T U V W X Y Z A B C D E F G H I J KL MNO
Q Q R S T U V W X Y Z A B C D E F G H I J KLMN O P
R R S T U V W X Y Z A B C DE F G H I J K LMNOPQ
S S T U V W X Y Z A B C D E F G H I J K L MN OPQR
T T U V W X Y Z A B C D E F G H I J K L MNO PQ RS
U U V W X Y Z A B C D E F G H I J K L MNO PQ R ST
V V W X Y Z A B C DE F G H I J K L MN O P QR STU
W W X Y Z A B C DE F G H I J K L MNO PQ RS TUV
X X Y Z A B C D E F G H I J K L M N O P Q R S T U VW
Y Y Z A B C D E F G H I J K L M N O P Q R S T U V WX
Z Z A B C D E F G H I J K L M N O P Q R S T UV W XY
This can be consolidated when working with numerals i.e., A=0,B=1,. .,..,
Z=25 can be used to add or subtract to the ASCII code of the plaintext. The
cryptogram is based on the period (i.e., the length of key). If the key is CAT, then
the cryptogram will have a period of 3.
Keyword: ABCABCABCABCAB....
This can be grouped into 3 or 5 letter words. The Gronsfeld cipher arrived
in 1655 and is a tricky method purely based on the numeric key. The idea is
based on producing shift from the plaintext letter. Following is an example for
Gronsfeld encipherment.
Key: 2 3 1 0 4 2 3 1 0 4 2 3 1 0 . . . .
Plaintext: B L O W T H E A I R B A S E. . . .
Cryptogram: D O P W X J H B I V D D T E. . . .
The Beaufort cipher has two types – true Beaufort and variant Beaufort. It
uses a 27x27-alphabet square in which all four of the outside alphabets are alike.
The tableau resembles that of Vignere tableau. Sir Francis Beaufort developed
the Beaufort cipher in 1857. Following is an example, which has the keyword C.
The porta cipher and its tableau are due to Giovanni Battista della porta.
The tableau consists of 13 cipher alphabets along with their inverses, are
governed by two key-letters. The porta tableau and encipherment are given
below.
A B C D E F G H I J K L M
AB N O P Q R S T U V W X Y Z
CD O P Q R S T U V W X Y Z N
EF P Q R S T U V W X Y Z N O
GH Q R S T U V W X Y Z N O P
IJ R S T U V W X Y Z N O P Q
KL S T U V W X Y Z N O P Q R
MN T U V W X Y Z N O P Q R S
OP U V W X Y Z N O P Q R S T
QR V W X Y Z N O P Q R S T U
ST W X Y Z N O P Q R S T U V
UV X Y Z N O P Q R S T U V W
WX Y Z N O P Q R S T U V W X
YZ Z N O P Q R S T U V W X Y
Fig. Porta Tableau.
The decipherment is many times easy as two or more keys can yield the
plain text. The key-interruption method is simple to apply and easy to understand.
A key word such as ORGANIZATIONAL is selected and applied on words along
with word-spacing irregularly as ORGA OR ORGANIZA ORG ORGANI O
ORGANIZATI ORG ---- The numeric ciphers implemented in the project are T-
cipher and Nihilist numeric Substitution. Both use a grid of cipher alphabets
called Checkerboard.
Porta Table
Giovanni Baptista della Porta developed the Porta Table cipher method in
1565. The table uses a keyword and the table below to encipher messages.
Porta Table
AB a b c d e f g h i j k l m
n o p q r s t u v w x y z
CD a b c d e f g h i j k l m
z n o p q r s t u v w x y
EF a b c d e f g h i j k l m
y z n o p q r s t u v w x
GH a b c d e f g h i j k l m
x y z n o p q r s t u v w
IJ a b c d e f g h i j k l m
w x y z n o p q r s t u v
KL a b c d e f g h i j k l m
v w x y z n o p q r s t u
MN a b c d e f g h i j k l m
u v w x y z n o p q r s t
OP a b c d e f g h i j k l m
t u v w x y z n o p q r s
QR a b c d e f g h i j k l m
s t u v w x y z n o p q r
ST a b c d e f g h i j k l m
r s t u v w x y z n o p q
UV a b c d e f g h i j k l m
q r s t u v w x y z n o p
WX a b c d e f g h i j k l m
p q r s t u v w x y z n o
YZ a b c d e f g h i j k l m
o p q r s t u v w x y z n
To begin, write out your plain message and write out the keyword above it, as
shown below:
Keyword: JACKET
Plain Message: LOOK UNDER THE COUCH.
The next step is to use the Porta table to create the enciphered message. Use
the letters from the keyword (jacket in the example above) to locate the correct
line to use in the Porta table. In the example above "J" is the first keyword letter.
Thus, locate "J" on the left hand side of the Porta table - the letters in all
uppercase. Once you locate the "J," the 5th set of uppercase letters in the Porta
table, you use the letter from the plain message to find the enciphered letter
above or below it. In this example the value for "L" in the "J" set is "U". See the
example below:
Notice how the letter "O" from the word "LOOK" has a different cipher value
because of the different keyword letters. The first "O" is directly under the
keyword character "A." Thus, the value of "O" in the "A" set is "B." The second
"O" is in the "C" set with a value of "C" for letter "O."
Once the cipher has been written you may want to add in extra characters, like
the "z" at the end of my rewritten cipher, to confuse decipherers. Another good
idea is to rewrite the cipher, as shown above, into blocks of letters. The example
above blocks letters into groups of 3.
To decipher a message encoded with the Porta table you'll need the keyword and
the Pora table for reference. Simply write out the enciphered message and the
keyword above it. Then, find the corresponding values for each letter, as you did
during the enciphering process. When you are all done read the string of letters
carefully to separate out the words and rewrite your message as a plain message
with spaces and punctuation.
1 2 3 4 5
1 A B C D E 13 = C
2 F G H IJ K 34 = O
3 L M N O P 32 = M
4 Q R S T U 15 = E
5 V W X Y Z 44 = T
Plain text :
S E N D S U P P L I E S
43 15 33 14 43 45 35 35 31 24 15 43
Key : 13 34 32 15 44 13 34 32 15 44 13 34
C’gram : 56 49 65 29 87 58 69 67 46 68 28 77
Both the plain text and key are converted to codes and added to get the
cryptogram, which is not grouped. In the T-cipher, no key is used but the plain
text is enciphered according to specific pattern. The row and column positions
are interchanged according to the even-odd position of the plain text.
Plain text : M Y N A M E I S...
Cryptogram : 62 84 63 40 62 44 53 37. . .
This kind of codes are obtained in the T-cipher which uses a check board
as follows:
0 1 2 3 4
4 A B C D E
5 F G H I J
6 K L M N O
7 P Q R S T
8 U V W X Y
9 Z
Re- Substitution :
42 51 11 24 45 14 54 12 15 15 42 35 31 15 41 53 13 25 15 31 53 53
GH D A O V K B I I G Y Q I M N L E I Q N N
The bifid has two units of numbers; for a trifid there must be three units.
Other simple ciphers are due to Vernam and Data Encryption Standard (DES).
The Vernam cipher assumes a key and XORs every bit with the plain text letter,
i.e.,
0 3
1 6
2 0
3 4
4 2
5 7
6 1
7 5
Fig : Pbox
4. OTHER TECHNIQUES:
The conventional private key ciphers use the same key to
decipher message as used to encipher it. All cryptograms, until Diffile and
Hellman’s article in 1976,kept both the encryption and decryption keys secret. By
application of key, abc becomes XYZ, and on the same key XYZ becomes abc;
each can be derived from the other. Diffile and Hellman proposed to use an
encryption algorithm, E, and a decryption algorithm, D. Both E and D are chosen
so that deriving D would be impossible even if a complete description of E has
been provided, i.e.,
1. D (E (P)) = P.
2. It is impossible to derive D from E.
3.E cannot be broken by a chosen plaintext attack.
The users A and B using this scheme of Public Key Cryptography use
two different keys to pass secret messages. A computes his first message EB (p)
and sends it to B. B decrypts it by applying his secret key DB, i.e., he computes
3.2
1.interception
2.modification
3.fabrication
the problem of interception is other people might know what we are talking.
there by they can our sectets i,e this is threat to confidentiality . by dencrypting
the text of communication we can thwart those attempts.
A B
Modification, this deals with the problem of other people modifying the actual
contents of the communication.
B
A
LEVEL 1 DFD
Store/Se
USER Retrive
Encrypt nd
Decrypt
USER
COMMUNICATION
4.1 Introduction :
4.3 Sockets :
First and foremost in order to use the Winsock API you have to link to the
libraries mpr.lib and wsock32.lib. To do this in Visual Studio create a new project
then under the "Projects" menu choose "Settings...", or just hit Alt+F7. In the top
left of the dialog box there is a drop down list box labeled "Settings For:" change
it to read "All Configurations". In the tab control on the right of the dialog box
select the "Link" tab. In the middle of the tab there is an edit box labeled
"Object/Library Modules:" add the name of the libraries you want to link to, be
sure all the labraries in the list are separated by spaces. That being done you can
now begin to program.
The first step in using the WinSock API is to initialize WSA. I'm not positive what
WSA is, I'm assumng its short for WinSockApi, but I can't back that up. Whatever
it is it has to be initilized. This is done by calling WSAStartup(). This function
takes two parameters a version number in a WORD value and a WSADATA
structure, it returns an integer the return will be 0 if initialization is successful.
Here is an example of the initialization process:
WSADATA WsaDat;
if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)
{
printf("WSA Initialization failed.");
}
matter, For the version number I use the macro MAKEWORD(). It splits the
version number up and its easy to see what you are requesting. When you send
that version number you are requesting a specific version of WinSock, in the
example I am requesting version 1.1. You can request version 1.0, 1.1, and 2.0,
version 2.0 is not available in Win 95 without being specifically installed it does
exist in all later versions of Windows. The exact benifits of each version I'll leave
to you to research, from what I have read version 1.1 has all the important
features and since its available in all version of Windows without a patch it is
acceptable for most applications.
After you have initialized WinSock the next step is to create a socket. Sockets are
of two types stream sockets and datagram sockets. Stream sockets are easier to
use so I'll demonstrate them. All sockets are of type SOCKET, and you create
them with the socket() function. The socket() function takes three parameters.
The first is the type of connection you would like to use, for this use AF_INET this
designates you want to use an Internet style connection (or in other words use
TCP/IP) as far as I know this is the only connection permitted through WinSock.
The second parameter is the type of socket to use, for stream sockets use
SOCK_STREAM, or for datagram sockets use SOCK_DGRAM. The thrid
parameter is some value for the protocol from what I have read this value has
very little meaning and is usually ignored so I always pass zero here. The
socket() function will return the socket or INVALID_SOCKET if it can't create the
socket. Here is an example of that:
SOCKET Socket;
Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Socket == INVALID_SOCKET)
{
printf("Socket creation failed.");
}
Now we have a usable socket, what we need to do is make use of it. As with any
network connections you have to have a server and a client. For clarity I'm going
to call the server the computer that is listening for and incoming connection and
the client the computer that requests a connection with a server. Since the server
has to be listening before a client can connect I'll show how to setup the server
first. First we bind the socket to a TCP/IP port. This is done with the bind()
function. The bind() function takes three parameters, a socket to bind to, a pointer
to a data structure that has the port information (structure type STRUCTADDR),
and the size of the structure with the port information. There are a few points of
interest in this process so i'll just explain inside an example.
That ought to be fairly straight forward to figure out. The connection type should
always be AF_INET, the port is an unsigned integer between 0 and 65,565, and
the address is four unsigned short values from 0 to 255 that is a valid IP address
of the server. We can specify the IP address we want to listen to, what if we want
to listen on multiple addresses? You could run throuh this process multiple times
to bind a socket on each address, or you could set the
SockAddr.sin_addr.S_un.S_addr to INADDR_ANY like this:
SockAddr.sin_addr.S_un.S_addr = INADDR_ANY;
Instead of setting the four octets of an IP address. The next issue that comes up
would be how do I know my IP address? There is a way of finding the address,
but its a little involved so I'm going to discuss that later. Now that we have a valid
socket bound to a TCP/IP port we need to listen on that socket for incoming
connections. We use the listen() function to accomplish that. The listen() function
takes two parameters a bound socket and the number of connections to accept.
Here is how that looks:
//Once again we're carrying through the Socket variable from the previous
example.
//We're only going to accept 1 incoming // connection.
listen(Socket, 1);
Not much to listen(). Just to clarify the listen() function does not accept the
incoming connections, it just sets your socket to listening on the specified port, no
more no less. To accept the incoming connection you use accept(). The accept()
function will will watch the port for a breif time then return an error. So unless you
know exactly when the connection is coming and can start accept at just the right
time you are going to miss the connection. One way around this is to place
accept() in a while loop until a connection is received. There is a problem with
this technique, in a DOS or console application its fine since nothing else can be
happening it doesn't but in a windows program it will stop responding until it gets
out of that loop. You may be able to set the accept() function to run on a short
timer or in a loop that is called in a thread. At any rate here is how it would look if
it were in a while loop until it received a connection:
//We are still carrying through the Socket variable from before
SOCKET TempSock = SOCKET_ERROR;
while (TempSock == SOCKET_ERROR)
{
TempSock = accept(Socket, NULL, NULL);
}
Socket = TempSock;
The reason for creating the TempSock variable is to preserve our real socket. I
don't want to overwrite it with an error just because we missed a connection. I
never looked into what is returned on a successful connection, I would assume it
is the socket you started with, but from examples I looked at it doesn't appear to
do that. All the documentation I read on accept() skipped over the return value,
they just copied the results back into the original socket so I am doing the same.
The second two parameters can be used to gain information on who connected
by passing a pointer to a SOCKADDR structure and its size like this:
SOCKADDR Addr;
accept(Socket, &Addr, sizeof(Addr);
//We need a socket variable but for now lets assume its a variable Socket we
prepared earlier.
//We want to use port 50
SockAddr.sin_port = 50;
SockAddr.sin_addr.S_un.S_un_b.s_b3 = 0;
SockAddr.sin_addr.S_un.S_un_b.s_b1 = 1;
Now that we have a server with a connected client they need to exchange
information. This is done exactly the same for the client as it is for the server. The
functions to use are send() and recv(). They both take four parameters the socket
to send on, the data to send, and the number of bytes in the data. The way they
expect the data is in a pointer to a char. You can bundle other values into this just
typecast it into a char * and pass the correct number of bytes. The fourth
parameter isn't used so give a zero there. These functions will return the number
of bytes send or received if successful. They will return 0, WSAECONNRESET,
or WSAECONNABORT if the connection was closed at the other end. These
functions will also return SOCKET_ERROR if some error occurs during the
transmission. They recv() function, like the accept() function, only watches for a
brief period for the data to come through. Once again I place the function in a
while loop until data is received. Here is how the recv() function looks in such a
loop:
break;
}
}
Since errors are possible in sending the data I place it in a while loop as well.
Here is how that looks:
In these examples the data to send, or the received data is in the character array
String. When the data is received there is a fixed amount of data that can be
received so it is possible to overrun the buffer. That is a quick run through of how
to use WinSock for network communications.
Now as I said before there are ways of determining your own network address.
This is by calling gethostname(). This will not return your IP address, only the text
computer name. This function takes two parameters a character array to place
the computer name in and the number of characters you have allocated in that
array. Here is how it looks:
char Name[255];
gethostname(Name, 255);
If you look at the example above you'll note that it uses the IP address, not the
computer name. What you can do is to call gethostbyname() which will give you
information about a host based on its name. It takes only one parameter, the
string that has the computer name, and it returns a pointer to a HOSTENT
structure. Here is an example:
HOSTENT *HostInfo;
HostInfo = gethostbyname("computer");
if (HostInfo == NULL)
{
printf("Attempt to retreive computer information failed.");
}
The gethostbyname() function will search through DNS records in order to find
the IP address. The careful readers will note that this HOSTENT structure is still
worthless since it doesn't fit into the SOCKADDR_IN anywhere. The IP address
is in the HOSTENT structure, its just buried. Here are the members of the
HOSTENT structure that I found useful. The h_addrtype member holds the type
of address this uses, as with the sockets the only type is AF_INET. The h_name
is a character array that will contain the complete host and domain name for that
computer, for instance host.domain.com. One catch to this, it will not do reverse
name lookups, for example if you look up the computer name "MyComputer"
h_name will hold "MyComputer.MyDomain.com" , however if you look up the
computer named "10.10.10.1" (which is really its IP) it will not translate that into a
computer name gethostbyname() will just put the text "10.10.10.1" in h_name.
The last member I want to discuss is h_addr_list, this one is somewhat confusing
so of course it has the information we are really after. The member h_addr_list if
a variable of type char**, but every time I have used it only one dimension of the
array is used. In the data that is filled the first four bytes hold the four octets of the
IP address. The rest of the array holds the same information as h_name. The
octets are written as unsigned char values so you would have to place them into
the SOCKADDR_IN structure like this:
SOCKADDR_IN SockAddr;
HOSTENT *HostInfo;
SockAddr.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)HostInfo-
>h_addr_list[0][0];
SockAddr.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)HostInfo-
>h_addr_list[0][1];
SockAddr.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)HostInfo-
>h_addr_list[0][2];
SockAddr.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)HostInfo-
>h_addr_list[0][3];
In that way you can use the computer's name to find its IP so you can connect to
any server you have the name of. Using this same technique you can also find
your own computers IP address. Most optional features can enhance the
performance and capabilities of your application. However, your application
should not fail if and when the optional features aren't available. For example,
generally you can get better bulk data throughput if you increase your input and
output buffer sizes with SO_RCVBUF and SO_SNDBUF. However, your
application should still be able to function with the default buffer sizes if your
attempts to change the buffer sizes fail (with the WSAENOPROTOOPT or
WSAEINVAL error).
Of course, there are some applications that cannot possibly function when a
Windows Sockets implementation doesn't support a particular optional feature.
You should avoid using options that don't have standard API and behavior
definitions. For example, sharing sockets. The Windows Sockets specification
doesn't mention the possibility of sharing sockets, so socket sharing is an
optional feature by implication. The problem is that each WinSock implementation
that allows sharing may have different requirements. The SO_DEBUG socket
option is another optional feature without a description. The WinSock
specification doesn't describe SOCK_RAW or multicast support either, but
fortunately we can refer to the de facto standard defined by Berkeley Sockets.
Using a proprietary API extension like socket sharing is a step backward. You
limit your application, and you complicate it also. The v1.1 WinSock does not
define a standard way to identify individual WinSock implementations. There's no
standards committee to assign specific manufacturer identifiers like the IEEE
does for Ethernet and Token Ring network interface manufacturers. The
WSAData structure returned by WSAStartup() provides a location for vendor
specific information, but does not prescribe the format.
/* CRYPTOGRAPHY
Program for enciphering and deciphering various messages given
by users or those which are stored in text files. */
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <graphics.h>
#define ENCRYPT 1
char org[200],cp[200],temp[20][10],acp[6],dup[200],tp[200];
FILE *fp,*fp1;
int stlen; /*length of string to be operated upon*/
int ed; /*determine whether to encode or decode*/
int dp[200]; /*states numeric cipher text codes*/
help()
{
char c,acp[6];
setbkcolor(1);
page1:
cleardevice();
settextstyle(SMALL_FONT,HORIZ_DIR,5);
setcolor(10);
outtextxy(19,100,"AS CC CL CO");
outtextxy(19,200,"DC DV FA GR");
outtextxy(19,300,"HE IC IN KI");
outtextxy(19,400,"KT LD MI MY");
setcolor(7);
outtextxy(19,100," :I/P STRING :CEASAR CIPHER :CLEAR
:COMPLEMENT " );
outtextxy(19,200," :DIGRAM COUNT :DESEND_VERT
:5_ALPHABET :GRONSFELD " );
outtextxy(19,300," :HELP :INTERCHANGE :INVERSE
:KEY_INTER. " );
outtextxy(19,400," :KNIGHTS TOUR :LOAD FILE :NIHILST SUBS
:MYSKOWSKY " );
goto bot;
page2:
cleardevice();
setcolor(10);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
outtextxy(19,100,"NC NK NS PG");
outtextxy(19,200,"PO QU RE RF");
outtextxy(19,300,"SA TB UC UT");
outtextxy(19,400,"VB VE VI ZZ");
setcolor(7);
outtextxy(19,100," :NIHILIST CHAR :NIHILIST NUM :NIHILIST_SUB
:PROFILE GRAPH");
outtextxy(19,200," :PORTA :QUIT :REVERSE
:RAILFENCE ");
outtextxy(19,300," :SAVE DATA :TRUE_BEAUFORT :UPPER CASE
:UNIT_TANSP ");
outtextxy(19,400," :VER.BEAUFORT :VERNAM :VIGNERE
:ZIG ZAG ");
bot:
setcolor(4);
outtextxy(19,450,"press ESC to accept command,^a to page up,^d to page
down");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
outtextxy(180,30,"HELP MENU");
c= getch();
if (c==27) {cleardevice();
strcpy(acp,"ac");}
if (c==4) { goto page2;}
accept_command(char tp[])
{
register int i,j;
puts("\nENTER THE COMMAND(... AT ANY TIME PRESS 'HE' FOR HELP...)");
for(i=0;;i++)
{
tp[i]=getchar();
if (tp[i]=='\n') break;
}
while(isspace(tp[0]) && ispunct(tp[0]))
{
for (j=0;j<i;j++) tp[j]=tp[j+1];
i--;
}
return i;
}
encrypt_decrypt()
{
int ab;
printf("ENCRYPT(1)/DECRYPT(2): ");
scanf("%d",&ab);
return ab;
}
void char_key()
{
register i,k,l=0,len;
register char key[10],t;
stlen=strlen(org);
printf("enter the key(less than 10 alphabets):");
gets(key);
len=strlen(key)-1;
arrange_matrix(len);
for(l=0;l<len-1;l++)
for(i=l+1;i<len;i++)
{
if(key[i]>=key[i+1])
{
t=key[i+1];
key[i+1]=key[i];
key[i]=t;
for(k=1;k<=len;k++)
{
t=temp[k][i+1];
temp[k][i+1]=temp[k][i];
temp[k][i]=t;
}
}
}
}
convert(int x)
{
register int y,x1,y1,xx,t;
if(x>73) t=x-1; /* if x>'l'decrease x */
else
t=x;
y=t-65;
x1=y%5; /*find row and column numbers*/
y1=y/5;
x1++; /*increment x,y by 1 to get exact number*/
y1++;
xx=y1*10+x1; /* formula to compute encoded number*/
return xx;
}
for(i=stlen;i<(len+1)*5;i++)
org[i]='Q';
stlen=strlen(org);
len=stlen/5;
for(i=0;i<5;i++)
{
t=i;
for(m=0;m<len;m++)
{
if(num==ENCRYPT)
dup[l]=org[t];
else
dup[t]=org[l];
t=t+5;
l++;
}
}
}
void digram_count()
{
register int di[26][26],i,r,c;
for(r=0;r<26;r++)
for(c=0;c<26;c++)
di[r][c]=0;
for(i=0;i<stlen-1;i++)
{
r=org[i]-65;
c=org[i+1]-65;
di[r][c]++;
}
for(r=0;r<26;r++)
{
for(c=0;c<26;c++)
{
i=di[r][c];
if(i!=0)
printf("%3c%c-%2d",r+65,c+65,i);
if(wherex()>75)
printf("\n ");
}
}
printf("\n");
}
else dup[i]=org[i];
}
}
}
{
register int i,k,l=0;
int t[8][8]={ 1, 4,53,18,55, 6,43,20,
52,17, 2, 5,38,19,56, 7,
3,64,15,54,31,42,21,44,
16,51,28,39,34,37, 8,57,
63,14,35,32,41,30,45,22,
50,27,40,29,36,33,58, 9,
13,62,25,48,11,23,46,26,
49,12,61,24,47,10,59, 3 };
stlen=strlen(org);
for(i=stlen;i<64;i++) org[i]='Q';/* where Q is the null character*/
org[64]='/0';
strcpy(dup,org);
stlen=strlen(dup);
for(i=0;i<8;i++)
{
for(k=0;k<8;k++)
{
if(num==ENCRYPT)
dup[l]=org[t[i][k]-1];
else
dup[t[i][k]-1]=org[l];
l++;
}
}
}
printf("%4d",dp[i]);
printf("\n");
}
void num_key()
{
register char key[10];
register int i=0,l=0,m,k,len;
printf("enter the key (less than 10 digits):");
fflush(stdin);
gets(key);
len=strlen(key)-1;
do
{
for(i=0;i<len;i++)
{
m=key[i];
for(k=0;k<11;k++)
{
if(m>=0)
{
temp[i][k]=m;
m--;
}
else
{
temp[i][k]=org[l];
l++;
}
}
}
}
while(l!=stlen);
l=0;
for(k=0;k<11;k++)
{
for(i=k+1;i<=len;i++)
if(isalpha(temp[i][k]))
{
dup[l]=temp[i][k];
l++;
}
dup[l+1]= ' ';
}
}
void porta()
{
register int t,i,n,j,k=0,len,po[13][13];
register char key[10];
stlen=strlen(org);
printf("enter a key(less tha 10 alphabets):");
fflush(stdin);
gets(key);
len=strlen(key)-1;
for(i=0;i<13;i++) /* prepare lower part of tableau*/
{
void profile_graph()
{
register int al[26],i,k=0,d;
float ap[26];
for(i=0;i<26;i++) al[i]=0;
printf("string lengths: %d\n",stlen);
for(i=0;i<stlen;i++)
{
d=org[i]-65;
al[d]++;
}
for(i=0;i<26;i++) ap[i]=100*al[i]/stlen;
puts("FREQUENCY COUNT CHART");
puts("----------------------");
for(i=0;i<13;i++)
{
printf("%2c%3d%6.2f",k+65,al[k],ap[k]);
for(d=0;d<ap[k];d++) printf("*");
k++;
gotoxy(45,wherey());
printf("%2c%3d%6.2f",k+65,al[k],ap[k]);
for(d=0;d<ap[k];d++) printf("*");
printf("\n");
k++;
}
}
void true_beaufort()
{
register int i,k=0,len;
register char key[10];
stlen=strlen(org);
printf("enter a key(less tha 10 digits):");
fflush(stdin);
gets(key);
len=strlen(key)-1;
for(i=0;i<stlen;i++)
{
dup[i]=prepare_char(key[k]-org[i]+65);
k++;
if(k<len) k=0; /* 27x27 grid is eliminated */
}
}
void vernam_cipher()
{
register int i,k=0,len;
register char key[10];
printf("enter the key(less than 10 digits):");
fflush(stdin);
gets(key);
len=strlen(key)-1;
for(i=0;i<stlen;i++)
{
if(k>len) k=0;
dup[i]=org[i]^key[k];
k++;
}
}
/* SELECTION OF CIPHERING TECHNIQUES */
void command_processor()
{
register int i,quit=1;
register char p,q;
char a,b,fname[64];
int x,offs;
while (quit!=0)
{
x=accept_command(acp);
if (x>0)
{
p=toupper(acp[0]);
q=toupper(acp[1]);
}
}
}
/* MAIN PROGRAM */
main()
{
int gmod=0,gdr;
gdr=DETECT;
initgraph(&gdr,&gmod,"e:\\tc\\bgi ");
rectangle(10,0,600,460);
outtextxy(30,430,"AUTHOR:BATCH-1V");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,5);
outtextxy(130,200,"CRYPTOGRAPHY");
line(10,420,600,420);
getch();
cleardevice();
command_processor();
getch();
}
/* Server Programming */
/* Server.cpp
This program implements a TCP Server */
#include <WinSock.h>
#include <stdio.h>
#define SERVER_PORT htons(4000)
/* Function declarations */
void Initialize();
SOCKET Listen();
void Close(SOCKET);
void ReceiveData(SOCKET, char *);
void Send(SOCKET, char *);
void Receivech(SOCKET, char *);
/* main() makes the appropriate funtion calls */
SOCKET sSock;
void main() {
FILE *fp2;
SOCKET commSock;
char receivedStr[1],sendstr[100],ch[1];
do {
Receivech(commSock,ch);
if(ch[0]=='y')
{ ReceiveData(commSock, receivedStr);
fputc(receivedStr[0],fp2);
}
else
break;
}while(1);
printf("Socket = %d\n", commSock);
//receivedStr[0]='\0';
//n=recv(commSock, receivedStr, 100, 0);
// ReceiveData(commSock, receivedStr);
printf(" recevied completely:\n");
fclose(fp2);
Close(commSock);
}
wVersionRequested = MAKEWORD( 1, 1 );
if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 ) {
/* Tell the user that we couldn't find a useable */
/* winsock.dll. */
WSACleanup( );
printf("\n couldn't find a useable winsock.dll");
exit(1);
}
}
/* Listen() binds and listens as the server and accepts any incoming connection
request */
SOCKET Listen() {
SOCKADDR_IN serverAddr;
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = SERVER_PORT;
serverAddr.sin_addr.s_addr = INADDR_ANY;
memset(&(serverAddr.sin_zero), 0, 8);
SOCKADDR_IN clientAddr;
SOCKET clientSock;
int sin_size=sizeof(struct sockaddr_in);
sSock = serverSock;
return(clientSock);
}
}
void Receivech(SOCKET sock, char * ch) {
int n=recv(sock, ch, 1, 0);
//receivedStr[n-1]='\0';
/* Client programming */
#include <winsock.h>
#include <stdio.h>
/* Function declarations */
void Initialize();
void main() {
FILE *fp;
char receivedStr[100],sendStr[1],ch[1];
Initialize();
SOCKET clientSock=Connect("127.0.0.1");
ch[0]='y';
fp=fopen("d:\\input.txt","r");
if(fp==NULL)
{ printf("file not opened");
exit(1);
}
while((sendStr[0]=fgetc(fp))!=EOF) {
Sendch(clientSock,ch);
Send(clientSock,sendStr);
//Send(clientSock,sendStr);
}
if(sendStr[0]==EOF)
{ ch[0]='n';
Sendch(clientSock,ch);
}
Receive(clientSock,receivedStr);
fclose(fp);
Close(clientSock);
}
void Initialize() {
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 ) {
/* Tell the user that we couldn't find a useable */
/* winsock.dll. */
WSACleanup( );
printf("\n couldn't find a useable winsock.dll");
exit(1);
}
}
/* Connect() makes a connection request to the server */
if(GetLastError()!=0) {
printf("\n Error # %d exiting....",GetLastError());
exit(1);
}
memset(&(serverAddress.sin_zero), 0, 8);
if (connect(clientSock, (LPSOCKADDR)&serverAddress, sizeof(struct
sockaddr))==0) {
///printf("\n\t Connection with server established.....");
}
else {
printf("\n\t connect() operation failed (Error #%d) exiting....",
GetLastError());
exit(1);
}
return(clientSock);
}
void Receive(SOCKET sock, char * receivedStr) {
int n=recv(sock, receivedStr, 100, 0);
receivedStr[n-1]='\0';
printf("\n\n received string = %s\n"
" # of bytes received = %d\n", receivedStr, n);
}
void Send(SOCKET sock, char * strToSend) {
int n=send(sock, strToSend, 1, 0);
if (n<0) {
printf("\n send() failed Error # = %d",WSAGetLastError());
exit(1);
}
else {
printf( "\n\n Send() successful \n" " # of bytes sent = %d\n", n);
}
}
void Sendch(SOCKET sock, char * ch) {
int n=send(sock, ch, 1, 0);
if (n<0) {
printf("\n send() failed Error # = %d",WSAGetLastError());
exit(1);
}
else {
printf( "\n\n Send() successful \n"
" # of bytes sent = %d\n", n);
}
}
void Close(SOCKET sock) {
closesocket(sock);
WSACleanup();
}
Screen Layouts :
Help Menu 1
Help Menu 2
IMPLEMENTATION
Applications:
SECRET_ KEY:
Only one key is used for both enciphering and deciphering the message
PUBLIC_KEY:
Different keys are used for enciphering and deciphering the message. This
means that who ever enciphers the message is unable to decipher.
AUTHENTICATION:
Any intruder may inject messages of his own into a communication
channel. Authentication is the detection of such forged encrypted messages.
DIGITAL SIGNATURES:
Authentication allows a receiver to be confident that the message
has been sent by the source, it does not enable him to convince others that the
message originated from the particular source. It is in such disputable cases that
digital signatures are of great help.
These are the techniques used for enhancing the secrecy of computer
passwords. Whenever user seeks the service of a computer, how can the
computer make sure that the user is not forgetting a faults identity. The computer
does not need to know the actual passwords, it merely needs to be capable of
validating the given passwords.
7.2 Limitations :
Many of the famous ciphering techniques such as Ceaser
cipher, Beaufort, Vignere, Nihilist, Porta, Gronsfeld, etc., had been discussed in
this project. Because of many practical considerations, many more famous
ciphering techniques are not included such as polyfair alphabetic,
AMSCOciphering, DES algorithms, etc. These techniques needed greater
amount of time, memory space and above all greater understanding of the
methods. Algorithms such as Data Encryption Standard(DES)algorithms are
needed highly complex, and also need operations at the bit level. There are
.
The code that has been made more interactive and informative.This is done
by allowing few status profiles With the inclusion of high performance
and selecting the one which is desirable. The same case also applies on
decipherment of ciphertext.
8. CONCLUSIONS :
This project helps effective communication between two parties without third
party being involed.This project helps confidential exchange of
information.Hackers cannot gain any knowledge about the text of users who use
these components. This project has few limitations and it can be expanded in the
future to a cosiderable extent.
Some of the important arena where the scope of expansion is identified has
been described in detail in this chapter. , many more famous ciphering
techniques are not included such as polyfair alphabetic, AMSCOciphering,
DES algorithms, etc. These techniques needed greater amount of time, memory
space and above all greater understanding of the methods. Algorithms such as
Data Encryption Standard(DES)algorithms are needed highly complex, and
also need operations at the bit level. This chapter will be of great usage or those
headers and enthusiasts who wish to
Select cryptology as their topic of interest.
The source code of this project has been presented in C language; the
executable coded thus produced occupies large space and take more time to
execute when compared with assembly language.
9. FUTURE ENHANCEMENTS:
10. BIBLIOGRAPHY:
WEBSITES:
www.Laynetworks.com
www.cryptography.com
www.cryptography-tutorial.com
www.winsock.com