BREAKING KNAPSACK CIPHER USING GENETIC ALGORITHM

Lekha J.R.
1
Dr.E.George Dharma Prakash Raj
2
1
M.Tech., Bharathidasan University, Tiruchirappalli.
2
Assistant Professor, Dept. of CSE, BARD, Tiruchirappalli.
Abstract:
With the exponential growth of networked
system and application such as eCommerce,
the demand for effective internet security is
increasing. Cryptology is the science and study
of systems for secret communication. It
consists of two complementary fields of study:
cryptography and cryptanalysis. Evolutionary
Algorithms like Genetic Algorithms (GA) are
used for the cryptanalysis of many well-known
ciphers. However most of the Cryptanalytic
attacks using GA are sequential. The
experimental result of research indicates that
the efficiency of genetic algorithm attack on
knapsack cipher can be improved with
variation of initial assumption.
Keywords–Genetic Algorithm, Knapsack
Cipher.
I INTRODUCTION
The demand for effective internet security is
increasing exponentially day by day.
Businesses have an obligation to protect
sensitive data from loss or theft. Such sensitive
data can be potentially damaging if it is
altered, destroyed, or if it falls into the wrong
hands. So they need to develop a scheme that
guarantees to protect the information from the
attacker. Cryptology is at the heart of
providing such guarantee. Cryptology is the
science of building and analyzing different
encryption and decryption methods.
Cryptology consists of two subfields;
Cryptography & Cryptanalysis. Cryptography
is the science of building new powerful and
efficient encryption and decryption methods. It
deals with the techniques for conveying
information securely. The basic aim of
cryptography is to allow the intended
recipients of a message to receive the message
properly while preventing eavesdroppers from
understanding the message. Cryptanalysis is
the science and study of method of breaking
cryptographic techniques i.e. ciphers. In other
words it can be described as the process of
searching for flaws or oversights in the design
of ciphers.
II RELATED WORK
Though many researchers have tried
evolutionary computing approaches for
cryptnalysis, it is worth mentioning a few
important works with reference to current
context. In 1993, Spillman [3] tried to attack
the knapsack cipher with Genetic Algorithm.
He tried to formulate the cryptnalysis problem
as an optimization problem. In 1997,
Kolodziejczyk also tried with improved
versions of genetic algorithms to attack the
same knapsack cipher. In 1999, Yaseen [7]
presented a Genetic Algorithm for attacking
Chor-Rivest knapsack Cipher. In 2006,
Poonam Garg [9] and Aditya Shastri [2]
extended Spillman’s work by carefully
engineering the initialization parameters of
cryptanalyzing Genetic Algorithm. Their
results showed that initial parameters of GA
can widely affect the performance of the
attack.
III KNAPSACK CIPHER
A. Knapsack Problem
The knapsack problem is formally explained
as follows. Given a knapsack of volume V
units and K items each of volume I1 , I2 , I3
… IK units. We would like to find out if its
possible to fill the knapsack with some of the
items. Formally, we would like to find a
number V by summing a subset of numbers
from the set {I1, I2, I3 …IK}.
∑ Mj * Ij = V ; j = 1 to K; Mj € {0, 1}
B. Encryption
The knapsack problem can be formulated into
a public key cryptography based knapsack
cipher. A knapsack sequence is the sequence
of values I1, I2, I3 … IK that indicates the
values of the volumes of individual items.
Given a knapsack sequence and a V value, a
simple greedy strategy won’t work for all
cases. Depending on the nature of knapsack
sequence we could solve the knapsack
problem in polynomial time based on greedy
strategy. If the knapsack sequence is super
increasing in nature it can be solved using
greedy approach. A super increasing sequence
is one in which,
∑IJ < Ip; p = 1 to K; J = 1 to K-1
Example of super increasing sequence is
I={1 3 6 13 27 52 105 211}. This super
increasing knapsack sequence would serve as
the Public Key. Now a message W =
01010111 would be encrypted as follows
E=∑ Mj * Ij. This is shown inTtable-1.
Plain
Text
Binary
Knapsack
Sequence
Cipher text
W
0101011
1
1 3 6 13 27
52 105 211
(0*1) + (1*3) +
(0*6) + (1*13)
+ (0*27) +
(1*52) +
(1*105) +
(1*211) =384
Table-1
C. Decryption
Consider Table-2, 384 is the encrypted text
and is sent to receiver. The receiver uses
greedy algorithm of using the largest number
in the sequence that would fit with in the
encrypted text and recursively solve the
problem for the remainder R = E – Largest
number that could fit, until there is no
remainder i.e R becomes zero.
E
Sequenc
e
Largest
number
that could
fit
Binary
Plain
text
384 211 173 1
W
173 105 68 1
68 52 16 1
16 27 - 0
16 13 3 1
3 6 - 0
3 3 0 1
0 1 - 0
Table-2
The algorithm is given below:
Knapsack Cipher Algorithm:
Input
Read Message to be encrypted.
Read the Knapsack Sequence.
Output
Encrypted Message in numeric
form
Algorithm
Step-1: Split the message into character
Array
Step-2: Calculate the message length
Step-3: Assign the knapsack sequence
into character array as
knapsequence
Step-4: For 1 = 0 to message_length – 1
Step-5: Find ASCII value of a character
Step-6: Convert the integer value into
binary value(8 bit form)
Step-7: Assign the binary value into the
character array binary
Step-8: Initialize Sum=0
Step-9: For j=0 to 7
Step-10: If binary(j) = 1
Step-11: Sum=Sum + knapsequence(j)
Step-12: End if
Step-13: End For
Step-14: Append ‘O’ to the encrypted
message as separator
Step-15: Append Sum with encrypted
message.
Step-16: End For
Step-17: Display encrypted message
IV. GENETIC ALGORITHM
The genetic algorithm is based upon
Darwinian evolution theory. The genetic
algorithm is modeled on a relatively simple
interpretation of the evolutionary process,
however, it has proven to a reliable and
powerful optimization technique in a wide
variety of applications. Holland in 1975, was
first proposed the use of genetic algorithms for
problem solving. Goldberg and Dejong [1]
were also pioneers in the area of applying
genetic processes to optimization. Over the
past twenty years numerous application and
adaptation of genetic algorithms have
appeared in the literature. During each
iteration of the algorithm, the processes of
selection, reproduction and mutation each take
place in order to produce the next generation
of solution.
Genetic Algorithm begins with a randomly
selected population of chromosomes
represented by strings. The GA uses the
current population of strings to create a new
population such that the strings in the new
generation are on average better than those in
current population (the selection depends on
their fitness value).
Encoding :
The following restriction have been made for
encoding
(1) Only the ASCII code will be
encrypted.
(2) The superincreasing sequence will
have 8 elements; these number of elements
guarantee that each character has a unique
encoding (There are 256 ASCII codes and
8 elements length will allow to encrypt 28
characters)
(3) Plaintext has not more then 100
character length.
Initialization:
A random population of chromosomes (binary
string 0’s and 1’s) is generated. The size of the
population has range in between 10 to 100.
The number of bits in each chromosome is
equal to the number of elements key (i.e. 8).
Evaluation:
Based on the fitness function given in equation
1 the fitness value evaluates how the given
sum is close to the target value for the
knapsack. The value of the fitness function
should be in the range of 0 to 1. Fitness value
1 indicates an exact match with the target sum
for the knapsack. If the value of sum is greater
then targets then it have a lower fitness value
of chromosome, in this way it produces the
infeasible solution. If the value of sum is less
then target then it will produce a high fitness
value and produce feasible solutions. Feasible
solutions have a greater chance of being
followed by the algorithm.
Selection:
The important part of algorithm is selection of
predicted sequence. When the sum is equal to
the target sum, the predicted sequence is
considered as the knapsack sequence.
Stop (Terminating) condition:
After executing the above-mentioned steps a
knapsack sequence is found. Until the status
reaches the TRUE condition the resultant
knapsack sequence is applied for all the cipher
values.
V. FITNESS FUNCTION
Spillman [3] proposed the fitness measure
given in Equation-1.
Fitness =
¹
¹
¹
¹
¹
¹
¹
'
¹
>

,
`

.
| −

,
`

.
| −

Target Sum if
MaxDiff
Target
1
Target Sum if
Target
Target
1
6
1
2
1
Sum
Sum
Let M={ m
1
, m
2
…… m
n
}, m
1
∈{0,1} be an
arbitrary solution and the public key
A = { a1, a2, ….. an}
Sum= ∑
·
n
j
j j
m a
1
;
Target =
'

j
j
a
;
FullSum= ∑
·
n
j
j
a
1
MaxDiff = max{Target, FullSum – Target}
VI. PROPOSED ALGORITHM AND ITS
IMPLEMENTATION
Input
Read Encrypted message.
Output
Getting the original message
Algorithm
Step-1: Split the encrypted message into
character Array using the
appended character ‘O’
Step-2: First
Step-3: For I =0 to encry_length
Step-4: Predict a sequence in incremental
order // sequence as 1 2 3 4 5 6 7
8
Step-5: Convert the encrypt(i) to its
binary equivalent
Step-6: Initialize sum = 0
Step-7: For j = 0 to 7
Step-8: If binary(j) =1
Step-9: Sum = Sum + predictsequence(j)
Step-10: End if
Step-11: End For
Step-12: If Sum = target Sum
Step-13: Assign Status = True
Step-14: Else
Step-15: Assign Status = False
Step-16: End For
Step-17: If All_status = true
Step-18: Sequence found
Step-19: Get back message from the
sequence
Step-20: Goto Last
Step-21: Else
Step-22: Change the predicted sequence
and try again.
Step-23: Goto first
Step-24: Last:
Step-25: Message decrypted
successfully.
Reading the plain text:
In this, the message that has to be sent to the
receiver is selected for encryption in the Fig 1.
Fig 1
Generating Cipher text:
Using the knapsack as public key, the selected
message is encrypted.
Fig 2
The cipher text for the selected message is
shown in Fig 3.
Fig 3
Decryption using Knapsack sequence:
Recovering the plain text from the cipher text
using Knapsack sequence in Fig 4.
Fig 4
Decryption using GA based approach:
Breaking knapsack cipher and recovering the
plain text without the knowledge of knapsack
sequence using GA based approach.
Fig 5
VIII. CONCLUSION
Our paper presents the genetic algorithm based
approach attack on the knapsack cipher. Our
work has shown that the proposed algorithm
helped in decrease of computational time
complexity. Though the efficiency of genetic
algorithm based approach attack on knapsack
cipher can be improved by variation of initial
assumptions, there was no decrease in the
number of generations. It might be due to the
same fitness function used by Spillman [3].
Hence, Evolutionary Computing Approaches
like Particle Swarm Optimization could be
tried for the same problem in future.
REFERENCES
[1] Goldberg, D.E., “Genetic Algorithms in
Search, Optimization and Machine Learning”,
Addison-Wesley, Reading, 1989.
[2] Poonam Garg,Aditya Shastri, “ An
Improved Cryptanalytic Attack on Knapsack
Cipher using Genetic Algorithm”,
International Journal of Information
Technology, Volume 3,2006.
[3] Spillman R.” Cryptanalysis of knapsack
ciphers using genetic Algorithms”
Cryptologia, October 1993.
[4] J. H. Holland, Adaptation in Natural and
Artificial Systems. The University of Michigan
Press, Ann Arbor, MI, 1975.
[5] Merkle R,Martin E Hellman “Hiding
information and signatures in trapdoor
knapsacks”, IEEE transanctions on
information theory,Volume 24, 1978.
[6] Shamir A.”A polynomial time algorithm
for breaking merkle hellman public key
cryptosystem”, Proceedings of IEEE
symposium on foundations on computer
science, IEEE New York, 1982.
[7] Yaseen and Sahasrabuddhe “A Genetic
Algorithm for cryptanalysis of Chor Rivest
Knapsack Public key cryptosystem”, Third
international conference on computational
intelligence and multimedia applications,
1999.
[8] Matousek R, “Hill Climbing and 0/1
knapsack problem”, Proceedings of Mendel
conference, July 2002.
[9] Poonam Garg, “Genetic Algorithm, Tabu
Search & Simulated Annealing Attack on
Transposition Cipher”, proceeding of third
AIMS International conference on
management at IIMA – 2006, 983-989
[10] Ragevan.”Cryptanalysis of
knapsackcipher using Parallel Evolutionary
Computing, International Journal of
Information Technology, Volume 1, No.1,
May 2009.