96
Cryptology And Communication INTRODUCTION : In today’s Knowledge Age, information transmission become part and parcel of our lives. In this scenario , computer networks holds pride of a Place. Now, as millions of ordinary citizens are using networks for banking, shopping, and filing their tax returns, network security is looming in the horizon as potentially massive problem. Hence this project aims at providing a modest solution to the problem using “Cryptology”. This project titled, Cryptology And Communication ”, employs efficient algorithms such as Data Encryption Standard(DES)to tackle the problem of network security. The project contains two parts viz., COMMUNICATION and CRYPTOLOGY. The communication part demonstrates that two or more computers can be linked together like a mini LAN. One computer was called SERVER and the other two its terminals or nodes. The source code was split into two .One exclusively for sending and receiving data (data can be files or messages) over the communication channel. This program is meant only for the nodes. The second program must be executed on a central computer, which was referred as FILE SERVER. A user working on the terminal can place a file in the server or get the file from the Dept of C S E, Narayana Engineering College , Nellore 1

Document 4

Embed Size (px)

Citation preview

Page 1: Document 4

Cryptology And Communication

INTRODUCTION : In today’s Knowledge Age, information transmission become

part and parcel of our lives. In this scenario , computer networks holds pride of

a Place. Now, as millions of ordinary citizens are using networks for banking,

shopping, and filing their tax returns, network security is looming in the horizon

as potentially massive problem. Hence this project aims at providing a modest

solution to the problem using “Cryptology”.

This project titled, ”Cryptology And Communication ”,

employs efficient algorithms such as Data Encryption Standard(DES)to tackle

the problem of network security.

The project contains two parts viz., COMMUNICATION

and CRYPTOLOGY. The communication part demonstrates that two or more

computers can be linked together like a mini LAN. One computer was called

SERVER and the other two its terminals or nodes. The source code was split into

two .One exclusively for sending and receiving data (data can be files or

messages) over the communication channel. This program is meant only for the

nodes. The second program must be executed on a central computer, which was

referred as FILE SERVER. A user working on the terminal can place a file in the

server or get the file from the server. Some of the features offered in the

COMMUNICATION part are:

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.

Dept of C S E, Narayana Engineering College , Nellore 1

Page 2: Document 4

Cryptology And Communication

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 providing greater security while transmitting, for each character, an

acknowledgement was sent back to the transmitter.

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.

The other part, CRYPTOLOGY, demonstrates how the message in plain

natural language called plaintext can be enciphered and again deciphered back

to the plaintext. Many famous algorithms or ciphering techniques such as

CAESAR CIPHER, NIHILIST TRANSPOSITION, VIGNERE CIPHER, UNIT

TRANSPOSITION, GRONSFELD CIPHER, BEAUFORT CIPHER,VARIANT

BEAUFORT,KNIGHT’S TOUR etc …. had been implemented successfully as

one integrated package. The enciphering process scrambles the bits so

thoroughly that a person wanting the information is unlikely to be able to

unscramble them.

Dept of C S E, Narayana Engineering College , Nellore 2

Page 3: Document 4

Cryptology And Communication

ANALYSIS :

The concept of cryptography has great importance. right

from the days of kings people want to communicate without being recognized. To

acheive that they used to change the text into unreadable or un intelligible form.

The well recorded strategy is followed by ceaser who used

to transfer data in encrypted form. in his method he used to replace every

character by the character three places next to it in the alphabet, there by making

it unreadable

During the second world war this concept played pivotal

role the germans invented enigma machine, the Japanese purple .the allied

forces had the great difficulty in decoding the actual text. Finally turing cracked

the code and discovered the machine bomb which can decrypt the

message .this led to the allied victory but the methods used for encryption are

old they used rotors and machines to do that. with the advent of computer and

the whole task is being done with the computer

The art of secret writing is not new today, It dates back to

thousand of years. The content of this chapter describes general terms most

often used in the field of “cryptology”. The moment you connect your computer

to any other computer, whether by Local Area Network with coworkers or by a

dial-up connection to an internet provider, you subject yourself to some risk that

your data could be compromised. Your data could be stolen or destroyed. Your

communications could be intercepted or misdirected.

The security of internet host sites is nebulous at best. Eventually all of

them will face some sort of break-in. it might be a hacker trying to prove that he

or she can gain unauthorized access to an internet site, or it might be a malicious

attempt to destroy data. Being forewarned is your best defense against your data

being corrupted or used in unauthorized fashion. One of the ways in which you

can ensure the privacy of your data is by cryptography.

Dept of C S E, Narayana Engineering College , Nellore 3

Page 4: Document 4

Cryptology And Communication

2.1 : Problem Specification

The word cryptography is the art and science of secret writing

and communication, embracing all kinds including codes and signaling .

Cryptanalysis is the art of “cracking” or “breaking” cryptic communication

messages called ciphers to which one doesn’t have a key. The term here

generally includes all kinds of hidden communication, but this project restricts it to

the sense of breaking written communications or cryptograms.

Cryptology deals almost exclusively with letters and words, and

can include such secret communication as those involving the telephone,

facsimile and certain aspects of television. The science of cryptology also deals

with deciding whether or not a given message is worth cracking. As for the turn

cryptology, it has come to signify the science that includes unspecified aspects of

cryptography and cryptanalysis, and the work involved in rendering a particular

communication system secure. The later embraces both preventing

unauthorized message-handling and intercepting messages from stations whose

cryptologists has the responsibility to prevent interceptors from obtaining what

from his point of view is secret and private.

The term cipher implies a method, or system, of secret writing

which is unlimited in scope; it should be possible, using any one given cipher, to

transform any plaintext (a message in common language), regardless of its

length and the language in which it is written, into a cryptogram, or single

enciphered message. The process of accomplishing this transformation is called

encipherment; the opposite process to that of transforming cryptograms into a

plaintext is called decipherment.

The word decrypt which is borrowed from modern French and

Italian writers with its various derivatives is being used to signify the process of

solving and reading cryptogram without any previous knowledge as to their keys,

Dept of C S E, Narayana Engineering College , Nellore 4

Page 5: Document 4

Cryptology And Communication

or secret formulas. Thus the word deciphers conveys only one meaning as

mentioned above the mechanical process of applying a known key.

A key is a word, and becomes a keyword. If more than one word is

serially involved in the key to a cipher, it remains keyword, though it can be called

as key phrase. If numerals constitute the key, the term becomes numerical key

or simply keyword. A keyword sets the pattern of a cipher, and may not

necessarily be a plaintext word.

Passive Active Intruder Intruder Just Listens Intruder Can alter

Messages

Plain Text

Encryption key, k Ciphertext Decryption Key

Dept of C S E, Narayana Engineering College , Nellore 5

EncryptionMethod

DecryptionMethod

Page 6: Document 4

Cryptology And Communication

2.2 : System Requirements

Software Requirements:

Language used : C,VC++

Operating System : Windows 98 .

Hardware Requirements :

Processor : Pentium - III or above.

RAM : 128MB.

Hard disk : 10GB

Dept of C S E, Narayana Engineering College , Nellore 6

Page 7: Document 4

Cryptology And Communication

DESIGN :

3.1 : Different Ciphering Techniques

The prime aim of this chapter is to describe in detail about various

ciphering techniques that are derived out of a few famous algorithms and are

used in this project. These algorithms are many in number but only few had been

successfully implemented in this project. Ciphering algorithms are classified as

follows.

Concealment ciphering

Transposition ciphering

Substitution ciphering

Other techniques.

The word diagram is being used to indicate a two-letters sequence:

similarly there are trigrams, tetragrams, pentagrams etc, to indicate sequence of

three, four, five, etc., letters. Ciphers, in general, fall into three major

classifications:

1. Concealment cipher,

2. Transposition cipher , and

3. Substitution cipher.

Minor types, such as “abbreviation “, are sometimes used, though these

have never seemed to be truly of a cryptographic nature.In concealment cipher,

which is not often seen in popular literature, the true letters of the secret

message are hidden, by any device and this type of cipher is intended to pass

without being suspected as the conveyor of a secret communication.

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.

Dept of C S E, Narayana Engineering College , Nellore 7

Page 8: Document 4

Cryptology And Communication

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

DECIPHERMENT SECTION ENCIPHERMENT SECTION

Vocabulary Code Code Vocabulary

Armored car 125 414 Horse Leave no evidence 600 392 About Careful 428 967 Meet me

Come; London 312 998 Fly is in the web Meet me 967 125 Armored car

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

Dept of C S E, Narayana Engineering College , Nellore 8

Page 9: Document 4

Cryptology And Communication

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 S P E C T

D E T A I L SF O R T R I G L E T HA C K N O W L E D G ET H E B O N D SF R O M F E W E L L

From this the decryptor can find out that the third column gives the secret

message, STRIKE NOW.

If column give no results, diagonals can be checked or a zigzag line

between first column and other can be inspected.

Dept of C S E, Narayana Engineering College , Nellore 9

Page 10: Document 4

Cryptology And Communication

2. TRANSPOSITION CIPHERING:

A method of producing cipher text from a plain text in which

the letters are disarranged from their natural order according to a particular

pattern or key is called transposition ciphering. These ciphering techniques

basically follow two types: regular and irregular. The regular type is further sub-

divided into two categories: geometrical & symmetrical. The geometric type is

also called complete unit transposition – is based on small unit or cycle repeated

over again and again .If the plain text message is not evenly divisible into units, it

is usually extended by the addition of extra characters called nulls. Some of the

keys are geometrical figures such as triangle, diamond etc.

Following is the example with a unit consisting of letters and geometrical

figure used is cross. The cryptograms are usually grouped into five letter units

before transmission by cable or radio.

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.

Another most popular geometrical figures used for transposition ciphering

appear as square, with or without series of numbers 1to25, 1 to 36 etc. Two

widely known examples of using a square are magic square and knightstour. The

magic square is a square in which row, column, diagonal adds up to a unique

number called magic number. Magic square with odd number of rows can be

Dept of C S E, Narayana Engineering College , Nellore 10

Page 11: Document 4

Cryptology And Communication

easily generated using Loubere’s method, which does not work for squares with

even number of rows. The knights-tour is based on the chessboard with a unit of

64 places. The piece called Knight moves diagonally in an awkward manner

unlike other pieces in the game of chess. The Knight takes a move 2x3 or 3x2

oblong. The tour starts at one corner of the board and covers all the places

touching each place exactly once. Out of the many possible tours, one such tour

is given below.

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.

Dept of C S E, Narayana Engineering College , Nellore 11

Page 12: Document 4

Cryptology And Communication

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 TH E N A VA L A I RB A S E ON R E P UB L I C DA 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

Plain Text: BLOW THE NAVAL AIRBASE ON REPUBLIC DAY.

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

Cipher text: BAL SOE WOT NHR EEN PAU VBA LLI ACI DRA BY

Dept of C S E, Narayana Engineering College , Nellore 12

Page 13: Document 4

Cryptology And Communication

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:

WASRC TLEED OVAEI BNRTB HAOPA EINUY LABHL.

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

Dept of C S E, Narayana Engineering College , Nellore 13

Page 14: Document 4

Cryptology And Communication

nihilist transposition. This cipher text may be again sent to cipherment applying

the keyword column wise, thus making the task of decryptment highly difficult.

There is another ciphering technique, which came into existence many

years ago, developed by cryptologist E. Myszkowsky, and is supposed to be

non-decryptable. The keyword is repeated throughout until the text is sufficient

enough to provide one key letter for one plain text letter. The letters in the key

are assigned numeric values. With all A’s receiving the first number, all B’s the

next number and so on. The ciphertext is taken off according to the sequence.

For the above plain text if keyword is ADVICE cipher text will be:

Keyword

A D V I C E A D V I C E A D V I C E A1 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

Cipher text: BEAET AALNI HISWV BOAR.

The AMSCO cipher follows all zeros of a columnar transposition cipher

except that letters are taken as pairs at every alternate place. Following is a

cipher called the UNITED STATES ARMY DOUBLE TRANSPOSITION in which

the same rules applies as in single columnar transposition. Nihilist transposition

cipher is employed twice; Nulls are added if required; and the key is also used.

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

Dept of C S E, Narayana Engineering College , Nellore 14

Page 15: Document 4

Cryptology And Communication

R B A S E X X

Primary Cryptogram: WAS TLE OVA BNR HAX EIX LAB. 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

Final Cryptogram: TNXLR LSBIW VXEHA OABAA E.

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.

Dept of C S E, Narayana Engineering College , Nellore 15

Page 16: Document 4

Cryptology And Communication

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.

Multiple-alphabet substitution makes use of several cipher alphabets

according to an agreed plan to construct the cryptogram. It is also called as

Double-key substitution, poly - alphabetic Substitution, etc. Sometimes the

term multi-Substitutional cipher is also used to indicate the multiple-alphabetic

substitution ciphering.

Polygram – Substitution is a method in which groups of letters replaced

with other groups consisting of different letters or numbers.

Fractional Substitution is another method in which first ordinary

substitution is performed on single letters and then these fractions are subjected

to further encryption. The result is a combination cipher rather than a purely

substitutional one. One of the oldest ciphering techniques of this type was used

by Julius Caesar. Another one of such kind was in use by Octavius. Caesar

formed the cryptogram be merely producing a shift on the normal alphabet. For

instance, D can be obtained by a “Shift” of 3 on A; hence this forms a Caesar

cipher 3. The entire cipher text is written down with a shift of 3. This kind of

ciphers is supposed to be weak ciphers. Following is an example for the shifted

cipher or Caesar cipher with a shift of 5.

Plain text: Blow The Naval Airbase On Republic Day.

Alphabet:

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

Substitute: F G H I J K L M N O P Q R S T U V W X Y Z A B C D E Cipher text: GQTB YMJ SFAFQ FNWGFXJ TS YMJ WJUZGQNH IFD.

Dept of C S E, Narayana Engineering College , Nellore 16

Page 17: Document 4

Cryptology And Communication

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 M N O P Q R S T U V W X Y Z

Substitute: Z Y X W V U T S R Q P O N M L K J I H G F 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.

Whenever a plain text alphabet is merely reversed and used as cipher

alphabet, the encipherment is called Reciprocal alphabet cipher. The inverse

alphabet cipher is one such example; the formation of other reciprocal alphabet

is as follows:

a) 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 b)A B C D E F G H I J K L M S R Q P O N Z Y X W V U T

c)E X A C T L Y B D F G H I Z W V U S R Q P O N M K J

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

In the example c) and d) given above the keyword EXACTLY is used. In

case any letter in the key repeated, it is just omitted. The key must consist of

well-mixed alphabets such as UNCOPYRIGHTABLE. The complex the cipher or

Dept of C S E, Narayana Engineering College , Nellore 17

Page 18: Document 4

Cryptology And Communication

substitute is, the stronger is the cipher text. For instance, the decryptment is very

difficult if the substitute is like the following:

Alphabet: 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

Substitute: U B J S Z L D K T P F M V E G N W R H O X C A I Q Y

Such kind of ciphers can be obtained by forming a mixed alphabetical

cipher. Some of the methods are as follows:

Keyword: EXACTLY

(a) (b) (c) E X A C T L Y E X A * * C T L Y E X A C T L Y B D F G H I J B D F G H I J K M 3 6 1 2 5 4 7 KM N O P Q R N O P Q R S U V W ------------------- S U V W Z Z A B C D E F G H I J K LM N O P Q R S T U

V W XY Z

Alphabet : 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 Cipher(a) : E B K S X D M U A F N V C G O W T H P Z L I Q Y J R

Cipher(b) : E B N Z X D O A F P G Q H R C I S T J U L K V Y M W

Ciphre(c) : C J Q X D K R Y A H O B F M T E L S Z B I P W G N U

In the polyalphabetic substitution cipher, the encipher can use any of

the 26 letters to substitute a particular letter. The earliest known cipher of this

kind is the PORTA in 1563. In 1586 came the VIGNERE; both of them used

tableau. The Vignere tableau uses a 26x26 grid of alphabets, which was

successfully eliminated in this project; otherwise an extra module would have

been needed to prepare the 26x26 grid. The vignere tableau is given below.

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 A 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 B 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 AC C D E F G H I J K L M N O P Q R S T U V W X Y Z A BD D E F G H I J K L M N O P Q R S T U V W X Y Z A B C

Dept of C S E, Narayana Engineering College , Nellore 18

Page 19: Document 4

Cryptology And Communication

E E F G H I J K L M N O P Q R S T U V W X Y Z A B C DF F G H I J K L M N O P Q R S T U V W X Y Z A B C D EG G H I J K L M N O P Q R S T U V W X Y Z A B C D E FH H I J K L M N O P Q R S T U V W X Y Z A B C D E F GI I J K L M N O P Q R S T U V W X Y Z A B C D E F G HJ J K L M N O P Q R S T U V W X Y Z A B C D E F G H IK K L M N O P Q R S T U V W X Y Z A B C D E F G H I JL L M N O P Q R S T U V W X Y Z A B C D E F G H I J KM M N O P Q R S T U V W X Y Z A B C D E F G H I J K LN N O P Q R S T U V W X Y Z A B C D E F G H I J K L MO O P Q R S T U V W X Y Z A B C D E F G H I J K L M NP P Q R S T U V W X Y Z A B C D E F G H I J K L M N OQ Q R S T U V W X Y Z A B C D E F G H I J K L M N O PR R S T U V W X Y Z A B C D E F G H I J K L M N O P QS S T U V W X Y Z A B C D E F G H I J K L M N O P Q RT T U V W X Y Z A B C D E F G H I J K L M N O P Q R SU U V W X Y Z A B C D E F G H I J K L M N O P Q R S TV V W X Y Z A B C D E F G H I J K L M N O P Q R S T UW W X Y Z A B C D E F G H I J K L M N O P Q R S T U VX X Y Z A B C D E F G H I J K L M N O P Q R S T U VWY Y Z A B C D E F G H I J K L M N O P Q R S T U V WXZ Z A B C D E F G H I J K L M N O P Q R S T UV W XY

Fig. Vignere Tableau

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: A B C A B C A B C A B C A B . . . .

Plaintext: B L O W T H E A I R B A S E . . . . Cryptogram: B M Q W U J E B K R C C S F . . . .

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 . . . .

Dept of C S E, Narayana Engineering College , Nellore 19

Page 20: Document 4

Cryptology And Communication

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.

True Beaufort Variant Beaufort

Key : C C C C C C C C . . . C C C C C C C C . . .Plaintext : A B C D E F G H . . . A B C D E F G H . . . C’gram : C B A Z Y XWV. . . Y Z A B C D E F . . .

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 ZCD O P Q R S T U V W X Y Z NEF P Q R S T U V W X Y Z N OGH Q R S T U V W X Y Z N O PI J R S T U V W X Y Z N O P QKL S T U V W X Y Z N O P Q RMN T U V W X Y Z N O P Q R SOP U V W X Y Z N O P Q R S TQR V W X Y Z N O P Q R S T UST W X Y Z N O P Q R S T U VUV X Y Z N O P Q R S T U V WWX Y Z N O P Q R S T U V W XYZ Z N O P Q R S T U V W X Y

Fig. Porta Tableau.

Keyword: E A S T E A S T E A S T F A T S F A T S F A T S Plaintext : B L O W N A V A L A I R B L OW N A V A L A I R Cryptogram :Q Y F A L N MWN N R I Q Y F A L N M W N NR I

Dept of C S E, Narayana Engineering College , Nellore 20

Page 21: Document 4

Cryptology And Communication

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

A B 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

C D 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

E F 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

G H 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

I J 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

K L 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

M N 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

O P 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

Q R 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

S T 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

U V 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

W X 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

Y Z 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

Dept of C S E, Narayana Engineering College , Nellore 21

Page 22: Document 4

Cryptology And Communication

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.

Dept of C S E, Narayana Engineering College , Nellore 22

Page 23: Document 4

Cryptology And Communication

Nihilist Numeric Substitution

1 2 3 4 51 A B C D E 13 = C2 F G H IJ K 34 = O3 L M N O P 32 = M4 Q R S T U 15 = E5 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 34C’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 44 A B C D E5 F G H I J6 K L M N O7 P Q R S T8 U V W X Y9 Z

The combinations 91,19,92,29,93,39,49 and 94 are not used for

cipherment. This cipher gives a better output and tends to be a stronger type

cipher. The cryptogram becomes totally unbreakable if the arrangement of

alphabets is made at random.

Delastelle as bifid and trifid had described one of the excellent examples

for the fractional substitution. The bifid uses a two-unit alphabet and extended to

Dept of C S E, Narayana Engineering College , Nellore 23

Page 24: Document 4

Cryptology And Communication

keyword feature by M.E.Ohaver. The decryptment hence becomes highly

difficult. An example has been given as follows:

Preparation of alphabet Checkerboard Substitutes

D I A * M O N 1 2 3 4 5 S = 43 BC E F G H K 1 D B L V I E = 25 L P Q R S T U 2 C P W A V N = 53 VWX Y Z 3 Q X F R Y D = 11

4 MG S Z O 5 H T N K UFirst Substitution : S E N D D I A M O N D S T O D E L H I N O W 4 2 5 1 1 1 2 4 4 5 1 4 5 4 1 2 1 5 1 5 4 2 3 5 3 1 1 5 4 1 5 3 1 3 2 5 1 5 3 1 5 3 5 3

Re- Substitution : 42 51 11 24 45 14 54 12 15 15 42 35 31 15 41 53 13 25 15 31 53 53 G H D A O V K B I I G Y Q I M N L E I Q N N

Cryptogram : GHADO VKBIIG YQIMN LEIQN 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.,

Plain text(P) P XOR K Cipher text Plain text(P)

(P XOR K) XOR K

here XOR implies a modulo-2 adder. Another logic can be found

as P-box, which can stand for both cipherment of letters or bits of each letter. If

P-box is applied for letters, then it will be transposition and for bits, it will be

substitution type cipher. P-box logic stands as a foundation for the DES

algorithm.

0 3 1 6

2 0 3 4

Dept of C S E, Narayana Engineering College , Nellore 24

Page 25: Document 4

Cryptology And Communication

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

3.3 : Data Flow Diagrams

With the computerization and the networking of computers the concept of

secure communication again came to the fore. The general threats to the

communication are

Dept of C S E, Narayana Engineering College , Nellore 25

Page 26: Document 4

Cryptology And Communication

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.

Here the communication between A and B is known to C.

Modification, this deals with the problem of other people modifying the actual contents of the communication.

The data transferred between A and B is being modified by C.

LEVEL 1 DFD The communication between different users by using

ciphering techniques can be shown as follows in the form of data flow

diagram.The encryption and decryption can be shown as follows.

Dept of C S E, Narayana Engineering College , Nellore 26

A B

C

A

C

B

Store/Send

Retrive

Page 27: Document 4

Cryptology And Communication

COMMUNICATION

4.1 Introduction :

Dept of C S E, Narayana Engineering College , Nellore 27

USER Encrypt

USER

Decrypt

Page 28: Document 4

Cryptology And Communication

Due to the tremendous impact of computers and computer

communications on society during the past decade, this period in history has

come to be called the information age. The productivity and profitability of both

organizations and individuals have been enhanced significantly by these

revolutionary tools. Individuals use computer communications almost daily to

conduct personal and professional business. This trend is accelerating as more

people discover the power of computers and communications both for business

and for homes.

The day-to-day transactions at department stores, banks,

reservation counters, and other business are all dependent on computer

communication. The information age is equally dependent on the computer and

the computer networks.

Modern organizations today are widely dispersed, with offices located in

diverse parts of a country and the world. Many of the computers and terminals at

the sites need to exchange information and data often daily. The networking of

computers permits the sharing of resources. The use of networking allows a very

flexible working environment. Employees can work at home by using terminals

tied through networks into the computer at the office.

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.

Dept of C S E, Narayana Engineering College , Nellore 28

Page 29: Document 4

Cryptology And Communication

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

Dept of C S E, Narayana Engineering College , Nellore 29

Page 30: Document 4

Cryptology And Communication

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.

//The variables we will need SOCKADDR_IN SockAddr;

//We need a socket variable but for now // lets assume its the variable Socket we

prepared before.

//bind() does require one of those prepa // red sockets, so at one point you will

need to create one.

/* For those who are paying attention you may have noticed that I said before

that we need a struct SOCKADDR variable. Except I didn't declare one here. The

reason is that struct SOCKADD_IN holds the same information in the same way

as struct SOCKADDR does, the difference is that struct SOCKADDR_IN is easier

to work with. */

Dept of C S E, Narayana Engineering College , Nellore 30

Page 31: Document 4

Cryptology And Communication

//We want to use port 50

SockAddr.sin_port = 50;

//We want an internet type connection (TCP/IP)

SockAddr.sin_family = AF_INET;

//We want to listen on IP address 127.0.0.1

//I'll give a few better ways to set thi // s value later

SockAddr.sin_addr.S_un.S_un_b.s_b1 = 127;

SockAddr.sin_addr.S_un.S_un_b.s_b2 = 0;

SockAddr.sin_addr.S_un.S_un_b.s_b3 = 0;

SockAddr.sin_addr.S_un.S_un_b.s_b1 = 1;

//Ok all the information is set, lets bind()

if (bind(Socket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) ==

SOCKET_ERROR)

      {

      printf("Attempt to bind failed.");

      }

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

Dept of C S E, Narayana Engineering College , Nellore 31

Page 32: Document 4

Cryptology And Communication

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

Dept of C S E, Narayana Engineering College , Nellore 32

Page 33: Document 4

Cryptology And Communication

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);

I never tested sending a SOCKADDR_IN the same as in bind() but I haven't

tested this so I won't guarantee the results of this.

So now we are listening on a TCP/IP port and ready to accept a connection. So

lets look into requesting a connection. To do this we use the connect() function.

This function takes the same parameters as the bind() function except the port

and address are the ones you want to connect to instead of listen on obviously.

The connect() function will return a 0 if successful. Here is an example of that:

//The variables we will need

SOCKADDR_IN SockAddr;

//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;

//We want an internet type connection (TCP/IP)

SockAddr.sin_family = AF_INET;

//We want to connect to the IP address 1 // 27.0.0.1

//I'll give a few better ways to set thi // s value later

SockAddr.sin_addr.S_un.S_un_b.s_b1 = 127;

SockAddr.sin_addr.S_un.S_un_b.s_b2 = 0;

SockAddr.sin_addr.S_un.S_un_b.s_b3 = 0;

SockAddr.sin_addr.S_un.S_un_b.s_b1 = 1;

Dept of C S E, Narayana Engineering College , Nellore 33

Page 34: Document 4

Cryptology And Communication

if (connect(Socket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) != 0)

      {

      printf("Failed to establish connection with server.");

      }

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:

int RetVal = SOCKET_ERROR;

char String[50];

while (RetVal == SOCKET_ERROR)

      {

      RetVal = recv(Socket, String, 50, 0);

      if ((RetVal == 0)||(RetVal == WSAECONNRESET)||(RetVal ==

WSAECONNABORT))

           {

           printf("Connection closed at other end.");

           break;

            }

      }

Dept of C S E, Narayana Engineering College , Nellore 34

Page 35: Document 4

Cryptology And Communication

Since errors are possible in sending the data I place it in a while loop as well.

Here is how that looks:

int RetVal = SOCKET_ERROR;

char String[] = "Hello";

while (RetVal == SOCKET_ERROR)

      {

      RetVal = recv(Socket, String, strlen(String) + 1, 0);

      if ((RetVal == 0)||(RetVal == WSAECONNRESET)||(RetVal ==

WSAECONNABORT))

           {

           printf("Connection closed at other end.");

           break;

           }

      }

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

Dept of C S E, Narayana Engineering College , Nellore 35

Page 36: Document 4

Cryptology And Communication

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]

Dept of C S E, Narayana Engineering College , Nellore 36

Page 37: Document 4

Cryptology And Communication

[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).

You can (and should) avoid dependence on some optional features by

redesigning your application. For example, you shouldn't require a specific

amount of receive buffer space for your application to function. The doesn't

require WinSocks to support the SO_RCVBUF socket option, so you may not be

able to specify the system buffer space you get. For datastream sockets, you can

(and should) always allocate this buffer space in your application instead of

relying on system buffers. For datagram sockets, you'd have to redesign your

application protocol to use smaller datagrams.

Of course, there are some applications that cannot possibly function when a

Windows Sockets implementation doesn't support a particular optional feature.

For example, SOCK_RAW support is essential to many network monitoring type

applications, that use ICMP pings.

Dept of C S E, Narayana Engineering College , Nellore 37

Page 38: Document 4

Cryptology And Communication

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.

In any case, the programming convenience of application reliance on optional

features does not justify the incompatibility your application will suffer on different

WinSock implementations. For instance, an application that uses socket sharing

won't function on WinSocks that don't allow socket sharing, and may not function

on different WinSocks that do allow it. Since it is possible to write any type of

application without relying on proprietary features, we recommend that you avoid

proprietary features altogether for the benefit of portability. After all, the main

reason to use WinSock is to avoid proprietary APIs and take advantage of the

standard. SOCK_RAW is a type of socket that denotes a "raw socket" in the

same way that SOCK_STREAM denotes a datastream socket and

SOCK_DGRAM denotes a datagram socket. It's a macro (defined in

WINSOCK.H) that you use as the value for the type parameter in socket()

function. As section 2.6.10 of the v1.1 Windows Socket specification states, the

support of SOCK_RAW is not mandated. However, it is encouraged, so many

Dept of C S E, Narayana Engineering College , Nellore 38

Page 39: Document 4

Cryptology And Communication

WinSock implementations do provide support (one notable exception are TCP/IP

stacks from Microsoft).

Unfortunately, the WinSock specification doesn't describe the acceptable syntax.

There are many variations of raw sockets, that correspond to different levels of

support. True raw sockets allow free reign of the network and transport protocol

headers.

Fortunately, few applications need low-level raw sockets support. Most

applications require the common variation that allows access to the ICMP

protocol to provide the ping facility, and this is what most WinSock

implementations provide. The Berkeley sockets API model for this "raw ICMP"

API is well-defined.

5. Coding And Screen Layouts :

/* 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);

Dept of C S E, Narayana Engineering College , Nellore 39

Page 40: Document 4

Cryptology And Communication

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");}

Dept of C S E, Narayana Engineering College , Nellore 40

Page 41: Document 4

Cryptology And Communication

if (c==4) { goto page2;} if (c==1) { goto page1;} }

/* FUNCTIONS TO PREPARE STRING OR CHARACTER,ACCEPT I/P AND COMMANDS*/

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; }

/* FUNCTIONS FOR IMPLEMENTING VARIOUS CIPHERS */

void arrange_matrix(int len){ register int l=0,z,i,j; z=stlen/len; if(stlen%len!=0) z++; for(i=0;i<len;i++) for(j=0;j<z;j++) { temp[i][j]=org[l]; l++;}

Dept of C S E, Narayana Engineering College , Nellore 41

Page 42: Document 4

Cryptology And Communication

}

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; }

void descend_vert(int num) {

Dept of C S E, Narayana Engineering College , Nellore 42

Page 43: Document 4

Cryptology And Communication

register i,m,len,t=0,l=0; len=stlen/5; if(num==ENCRYPT && stlen % 5 !=0)

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");

Dept of C S E, Narayana Engineering College , Nellore 43

Page 44: Document 4

Cryptology And Communication

}

else dup[i]=org[i]; } }

void gronsfeld(int num) { register int i,k=0,len; register char key[10]; stlen=strlen(org); printf("Enter a numeric key (less than 10 digits):"); fflush(stdin); gets(key); len=strlen(key)-1; for(i=0;i<stlen;i++) {

if (num==ENCRYPT) dup[i]=prepare_char(org[i]+key[k]-48); else dup[i]=prepare_char(org[i]-(key[k]-48)); k++; if(k>len) k=0; /* 26x26 grid eliminated succesfully*/

} }

void key_interruption(int num) { register int i,j,k=0,len; register char key[10],ch; printf("enter a key(less than 10 alphabets):"); fflush(stdin); gets(key); len=strlen(key)-1; for(i=0;i<stlen;i++) {

ch=org[i];if(isspace(ch)) k=0;elseif(isalpha(ch)) { if(num==ENCRYPT) ch=prepare_char(ch+key[k]-64); else ch=prepare_char(ch-key[k]+64); k++; if(k>=len) k=0; } dup[i]=ch;

Dept of C S E, Narayana Engineering College , Nellore 44

Page 45: Document 4

Cryptology And Communication

} }

void knights_tour(int num) { 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++; }

} }

void mit_rsa(int num) { register int i,c,c3; stlen=strlen(org); for(i=0;i<stlen;i++) if(num==ENCRYPT) { c=org[i]-64; c3=(c*c*c)%33; dp[i]=c3; } else {

Dept of C S E, Narayana Engineering College , Nellore 45

Page 46: Document 4

Cryptology And Communication

c=dp[i]; c3=(c*c*c)%33; c3=(c3*c3*c)%33; dup[i]=c3+64; } for(i=0;i<stlen;i++) printf("%4d",dp[i]); printf("\n");}

void nihilist_subst(int num) { register int i,k=0,len,key1[10],x1,y1,p; 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++) key1[i]=convert(key[i]); if(num==ENCRYPT)

for(i=0;i<stlen;i++) { dp[i]=convert(org[i])+key1[k]; printf("%4d",dp[i]); k++; if(k>=len) k=0; }

elsefor (i=0;i<stlen;i++) { p=dp[i]-key1[k]; x1=p/10; y1=p%10; x1--; y1--; x1=x1*5+y1; if(x1>10) x1++; dup[i]=x1+65; k++; if(k>=len) k=0; }

printf("\n"); }

Dept of C S E, Narayana Engineering College , Nellore 46

Page 47: Document 4

Cryptology And Communication

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];

Dept of C S E, Narayana Engineering College , Nellore 47

Page 48: Document 4

Cryptology And Communication

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*/ {

t=78+i; /*upper part is unique hence eliminated*/ for(j=0;j<13;j++) { po[i][j]=t; t++; if(t>90) t=78; }}

for(i=0;i<stlen;i++){ n=(key[k]-65)/2; t=org[i]; if(t<78) {

t-=65; dup[i]=po[n][t];

} else {

for(j=0;j<13;j++) if(po[n][j]==t) break; dup[i]=65+j; } k++; if(k<len) k=0;

}}

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]++;

Dept of C S E, Narayana Engineering College , Nellore 48

Page 49: Document 4

Cryptology And Communication

} 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 unit_transpose(int num) { register int i,j=0; stlen=strlen(org); for(j=0;j<stlen;j+=4) { if(num==ENCRYPT) { dup[j]=org[j]; dup[j+3]=org[j+1]; dup[j+1]=org[j+2]; dup[j+2]=org[j+3];

Dept of C S E, Narayana Engineering College , Nellore 49

Page 50: Document 4

Cryptology And Communication

} else { dup[j]=org[j]; dup[j+1]=org[j+3]; dup[j+2]=org[j+1]; dup[j+3]=org[j+2]; } } for(i=j-4;i<stlen;i++) dup[i]=org[i]; }

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 */

Dept of C S E, Narayana Engineering College , Nellore 50

Page 51: Document 4

Cryptology And Communication

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();

}

/* IMPLEMENTING COMMUNICATION PROGRAMMING USING WINSOCK */

Dept of C S E, Narayana Engineering College , Nellore 51

Page 52: Document 4

Cryptology And Communication

/* Server Programming */

/* Server.cppThis 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];

Initialize(); //initialize socekets

commSock=Listen(); //starts listening blocking till client connect

printf("Socket = %d\n", commSock);//int n=recv(commSock, receivedStr, 100, 0);

fp2=fopen("a5.txt","w");if(fp2==NULL){

printf("enter file not opened");exit(1);

}

do { Receivech(commSock,ch);

if(ch[0]=='y') { ReceiveData(commSock, receivedStr);

fputc(receivedStr[0],fp2);

Dept of C S E, Narayana Engineering College , Nellore 52

Page 53: Document 4

Cryptology And Communication

} 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);strcpy(sendstr,"hi we have sucess");Send(commSock, sendstr);

Close(commSock);}

/* Initialize() is used to initialize the windows sockets API */void Initialize() {

WORD wVersionRequested;WSADATA wsaData;int err;

wVersionRequested = MAKEWORD( 1, 1 );

err = WSAStartup( wVersionRequested, &wsaData );if ( err != 0 ) {

/* Tell the user that we couldn't find a useable *//* winsock.dll. */printf("\n couldn't find a useable winsock.dll");exit(1);

}

/* Confirm that the Windows Sockets DLL supports 1.1.*//* Note that if the DLL supports versions greater *//* than 1.1 in addition to 1.1, it will still return *//* 1.1 in wVersion since that is the version we *//* requested. */

if ( LOBYTE( wsaData.wVersion ) != 1 || HIBYTE( wsaData.wVersion ) != 1 ) {

/* Tell the user that we couldn't find a useable *//* winsock.dll. */WSACleanup( );

Dept of C S E, Narayana Engineering College , Nellore 53

Page 54: Document 4

Cryptology And Communication

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;

SOCKET serverSock=socket(AF_INET, SOCK_STREAM, 0);

/* set server address */serverAddr.sin_family = AF_INET;serverAddr.sin_port = SERVER_PORT;serverAddr.sin_addr.s_addr = INADDR_ANY;memset(&(serverAddr.sin_zero), 0, 8);

/* bind server to its port */if (bind(serverSock, (LPSOCKADDR)&serverAddr, sizeof(struct sockaddr))

== 0) {printf("\n\t Socket bound to its port.....");

} else {

printf("\n\t Socket Bind operation failed (Error #%d) exiting....", GetLastError());

exit(1); }

/* start listening for incoming connection requests */if (listen(serverSock,4)==0) {

printf("\n\t Listening for connection request.....");}else {

printf("\n\t listen() operation failed (Error #%d) exiting....", GetLastError());

exit(1); }

SOCKADDR_IN clientAddr;SOCKET clientSock;int sin_size=sizeof(struct sockaddr_in);

/* accept a connection request from the client */

Dept of C S E, Narayana Engineering College , Nellore 54

Page 55: Document 4

Cryptology And Communication

clientSock=accept(serverSock, (LPSOCKADDR)&clientAddr, &(sin_size));printf("\n\t Connection request received and accepted.");

sSock = serverSock;return(clientSock);

}

void ReceiveData(SOCKET sock, char * receivedStr) {int n=recv(sock, receivedStr, 1, 0);//receivedStr[n]='\0';

// printf("\n\n received string = %s\n"// " # of bytes received = %d\n", receivedStr, n);

}void Receivech(SOCKET sock, char * ch) {

int n=recv(sock, ch, 1, 0);//receivedStr[n-1]='\0';

printf("\n\n received string = %c\n"" # of bytes received = %d\n", ch[0], n);

}

void Send(SOCKET sock, char * strToSend) {int n=send(sock, strToSend, 100, 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();

}

Dept of C S E, Narayana Engineering College , Nellore 55

Page 56: Document 4

Cryptology And Communication

/* Client programming */

/* Client.cpp This program implements a TCP Client */

#include <winsock.h>#include <stdio.h>

#define SERVER_PORT htons(4000)

/* Function declarations */void Initialize();SOCKET Connect(char *);void Receive(SOCKET, char *);void Send(SOCKET, char *);void Close(SOCKET);void Sendch(SOCKET,char *);/* main() makes the appropriate funtion calls */

void main() {

FILE *fp;char receivedStr[100],sendStr[1],ch[1];

Initialize();

// strcpy(sendStr,"Hello TCP sockets");

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);

Dept of C S E, Narayana Engineering College , Nellore 56

Page 57: Document 4

Cryptology And Communication

//Send(clientSock,sendStr); }if(sendStr[0]==EOF){ ch[0]='n';

Sendch(clientSock,ch);}

Receive(clientSock,receivedStr);

fclose(fp);

Close(clientSock);}

/* Initialize() is used to initialize the windows sockets API */

void Initialize() {WORD wVersionRequested;WSADATA wsaData;int err;

wVersionRequested = MAKEWORD( 1, 1 );

err = WSAStartup( wVersionRequested, &wsaData );if ( err != 0 ) {

/* Tell the user that we couldn't find a useable *//* winsock.dll. */printf("\n couldn't find a useable winsock.dll");exit(1);

}

/* Confirm that the Windows Sockets DLL supports 1.1.*//* Note that if the DLL supports versions greater *//* than 1.1 in addition to 1.1, it will still return *//* 1.1 in wVersion since that is the version we *//* requested. */

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);

}}

Dept of C S E, Narayana Engineering College , Nellore 57

Page 58: Document 4

Cryptology And Communication

/* Connect() makes a connection request to the server */

SOCKET Connect(char *IpNumber) {

SOCKET clientSock=socket(AF_INET,SOCK_STREAM, 0);

if(GetLastError()!=0) {printf("\n Error # %d exiting....",GetLastError());exit(1);

}

/* specify server's address */

SOCKET serverSock=socket(AF_INET, SOCK_STREAM, 0);SOCKADDR_IN serverAddress;serverAddress.sin_family=AF_INET;serverAddress.sin_port=SERVER_PORT;serverAddress.sin_addr.s_addr=inet_addr(IpNumber);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);}

}

Dept of C S E, Narayana Engineering College , Nellore 58

Page 59: Document 4

Cryptology And Communication

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 :

Dept of C S E, Narayana Engineering College , Nellore 59

Page 60: Document 4

Cryptology And Communication

Help Menu 1

Help Menu 2

Dept of C S E, Narayana Engineering College , Nellore 60

Page 61: Document 4

Cryptology And Communication

Implementation Of Different Ciphering Techniques :

Dept of C S E, Narayana Engineering College , Nellore 61

Page 62: Document 4

Cryptology And Communication

Dept of C S E, Narayana Engineering College , Nellore 62

Page 63: Document 4

Cryptology And Communication

Dept of C S E, Narayana Engineering College , Nellore 63

Page 64: Document 4

Cryptology And Communication

IMPLEMENTATION

7.1 Applications & Discussion :

Modern encryption and decryption techniques make

practically impossible for an intruder to read messages over

communication channels.This chapter deals with various

applications and discussion on the result of Cryptology

Applications:

Secure communication channels

Authentication

Digital signatures

Computer user identification

Cryptology used for secure communications can be split into two categories,

secret_key and public_key.

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

Dept of C S E, Narayana Engineering College , Nellore 64

Page 65: Document 4

Cryptology And Communication

message originated from the particular source. It is in such disputable cases that

digital signatures are of great help.

COMPUTER USER IDENTIFICATION:

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.

COMPARATIVE STUDY OF VARIOUS CIPHERS:

Here the table below shows comparision of various ciphering techniques.

CipherName

Ab Ty Memory need

TimeNeed

Weak/ strong

Skill to decrypt

Advantages demerit

InterChange

ic S ---------- O(n) Moderate less Can be complex by few If no. of inter interchangesChanges are more plaintext can Be found

Complement

co S ---------- O(n) Very weak

Very less Difficult to easilyUnderstand on decryptablefirst look

Inverse in S 26 places to store the inverse alphabets

O(n) Weak Moderate

Reciprocal

re T ---------- O(n) Very weak

Very less Easily Decryptable

Ceasar technique

Cc T ---------- O(n) Weak less Uses a offset

Gronsfeld

Gr S A grid of 5*26 elements

O(n) Strong High Decryption diffi cult if 5*26 gridprepared random

Rail fence

rf T ------------ O(n) Moderate Moderate analysis

Myszkowsky

my T ------------ O(n) Very strong

Very high

Key is used

Vernam ve S ------------ O(n) Weak moderateUnit transposition

ut T ------------ O(n/k) k is length

Weak moderate Trail and samples can

Dept of C S E, Narayana Engineering College , Nellore 65

Page 66: Document 4

Cryptology And Communication

of unit yield the plaintext

ihilist transposition

nt T Strong high

Double transposition

dt T Strong high Very difficult To decrypt

Knights tour applied

kt T Grid of 8*8 elements

Moderate high Difficult to under can bestand the random only if the pattern of letters plaintext length and can confuse is a multiple of an expert analyst 64.

Porta po S Ciphername

Ab Ty Memory need

Timeneed

Weak /Strong

Skill to decrypt

advantages demerits

Vignere vi S Grid of 26*26 elements

O(n) Strong high The grid can be in implementation key is used

Variant beaufort

vb S 27*27 grid

O(n) Strong high -do-

True beaufort

tb S 27*27 grid

O(n) Strong high -do-

Zig-Zag zz T ------- O(n) Weak less A look at the alternative letters yields the text

Descend verticals

dv T --------- Moderate high Key used

T-cipher tc S --------- O(n) Strong high Very difficult To decrypt

MIT algorithm

O(n) Strong high difficult To decrypt

Key interruption

O(n) Strong Moderate Key used

Nihilist number substitution

O(n) Strong high Key used . Very difficult To decrypt

Index Ab-abbreviated form Ty-type S-substitution T-transposition

Dept of C S E, Narayana Engineering College , Nellore 66

Page 67: Document 4

Cryptology And Communication

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

Data profiles and graphs. The cryptologists can arrive at conclusions at a

quick rate. This is because, it is easier for humans to understand data that is

represented graphically than that which is numerics, and on the other hand

gives impressive look to the output.

A major part of cryptologists work will be simplified if the software is smart

enough to understand text input and basing on the input it can suggest the

cryptologists which algorithm will be the most suitable. A similar idea can also

be implemented while deciphering the cipher text.

One of most challenging work will be autoencipherment and

autodecipherment of given message. Many such algorithms available which

need very less effort to understand and implement. With the help of this, the

cryptologist’s job will be less mind-teasing. One very simple technique is to

generate, for instance, 20cipher text messages corresponding to the 20

different ciphering algorithms available automatically for the given plaintext

and selecting the one which is desirable. The same case also applies on

decipherment of ciphertext.

Dept of C S E, Narayana Engineering College , Nellore 67

Page 68: Document 4

Cryptology And Communication

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 complexity of ciphering a plaintext can be considerable raised complex

algorithms take much time for processing but generate highly reliable

ciphertext..These are the techniques used for enhancing the secrecy of

computer passwords.

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.

The transmission of data in our project can be done by using sockets.where

the communication is very fast.

Dept of C S E, Narayana Engineering College , Nellore 68

Page 69: Document 4

Cryptology And Communication

9. FUTURE ENHANCEMENTS:

The future enhancements in this project can be

explained as follows.

Highly complex and reliable error checking and correcting methods can be

applied. The result of such computations can be suffixed to the packet to be

transmitted. A similar check can be made after the receipt of the packet to

ensure the correctness.

The transfer of data done using this project is slow and needs improvement.

The slowness is because of the protocol that every character must be

acknowledged. This may be avoided by introduction of 1KB or 2KB packets

without response after every character. But after every packet, the transfer

will be much more feasible. Even though there is a risk of loss of information,

it can be tackled easily by checking the checksum field and in case of corrupt

packet, a request for retransmission can be made.

A file to be sent can be divided into number of packets with header,

checksum, etc. This helps in increasing the communication speed along with

greater reliability.

This project works on the basis of simplex protocol for noisy channel. This can

be extended so as to implement much-sophisticated algorithms such as

sliding window protocols.

Dept of C S E, Narayana Engineering College , Nellore 69

Page 70: Document 4

Cryptology And Communication

10. BIBLIOGRAPHY:

Name Of The Book Authors 1. Network Security William Stallings

2. Security For Computer D.W.Davis and W. .L.Price

3. Complete Reference Herbert Schildt VC++ 4. John Wayner Disappearing Cryptography

WEBSITES:

www.Laynetworks.com

www.cryptography.com

www.cryptography-tutorial.com

www.winsock.com

Dept of C S E, Narayana Engineering College , Nellore 70