Cryptography Using Xor Cipher
Satish Kumar Garg
Govt. P G College Ambala Cantt. - 133001
*Corresponding Author E-mail: sat.phy@gmail.com
ABSTRACT
In the present work the author has introduced a new cryptographic method using XOR Cipher for data encryption and decryption of any data file at three stages (1) First, by converting each character into corresponding binary code using Extended ASCII Code thus we get 8N bits for input file containing of N characters (2) Secondly, creating a string of 0’s and 1’s such that total number of 0’s and 1’s is 8N, the consecutive numbers of 0’s and 1’s in this string may be from 1 to 7 (3) Thirdly, apply XOR operation on binary strings obtained at stages one and two and (4) Finally, converting binary string obtained at stage three into corresponding characters using reverse Extended ASCII Code. The results obtained after application of this algorithm are excellent.
KEYWORDS: Encryption, Decryption, XOR Cipher
I. INTRODUCTION :
The security and originality of data which is transmitted through internet [1,2] has now become very challenging because there is always a possibility that anyone may intercept our data. So it is not safe to send confidential data from one computer to another computer. The confidential data may be bank statements, bank transaction, military information, confidential data of companies etc. Hence the data should be protected from any unwanted intruder otherwise any massive disaster may happen all on a sudden. In order to make secure the system one should consider the security primary attributes such as confidentiality, integrity and availability, and secondary attributes such as authenticity, non-repudiation and accountability etc. There are a large number of methods and techniques to achieve security goals, one of these is Cryptography. Cryptography [3,4] is the study of mathematical techniques related to aspects of information security such as confidentiality, data integrity, entity authentication, and data origin authentication. Cryptography is not the only means of providing information security, but rather one set of techniques. The cryptographic algorithm can be classified into two categories: (i) Symmetric Key Cryptography where one key is used for both encryption and decryption purpose. (ii) Public Key Cryptography where two different keys are used one for encryption and the other for decryption purpose. Due to massive computation the public key crypto system may not be suitable in security of data in sensor networks [5].
II THEORY : In the present study, the author has used XOR Cipher which is basically a XOR Gate. The truth table of a XOR Gate is as under (Table 1) :
Table 1.
|
Table 2.
|
From the above Truth table 1, it is clear that if the value of X = 0, then the value of output Z is equal to the value of Y and if the value of X = 1, then the value of output Z is inverted to the value of Y.
Again if X is used as control signal and another input is Z, then output of the XOR Gate is Y´ which is equal to Y, as shown in Table 2. This fact is used to superimpose digital signal (corresponding to input data) on carrier digital signals of varying widths. Then the digitally modulated signal is transmitted from source node A to destination node B. At destination node B, the digitally modulated signal is demodulated again using XOR Gate, e.g., alphabet ‘a’ is represented in binary form as 0110 0001, if we use this as input and a clock pulse of width of single unit Ck = 01010101 as control signal, which shall be used as digital carrier pulse, then output of XOR Gate is Y = 0011 0100 as in Table 3. Y = 0001 0100 represents ‘4’, hence we see that ‘a’ is encrypted into ‘4’.
Table 3.
|
Table 4.
|
Now if we use Y = 0011 0100 as input and Ck = 01010101 as control signal, output of XOR Gate is Y´ = 0011 0100 as in Table 2. Y´ = 0011 0100 is used to represent a, hence we see that 4 is decrypted into ‘a’.
This algorithm is based on the concept that each character is represented by a unique 8-bit code in Extended ASCII Code system and if one or more bits are changed in a 8-bit code[6], then corresponding character is entirely changed. When any text of 10 characters is converted into binary form we get 80 bits which contains about 50% of 0’s and 1’s each. Therefore, total number of possible combinations is about 80!/(40!)2= 1075×1020. The Super Computer available is Teraflop which is capable of doing 1012 floating point calculations per second, so a teraflop super computer shall take about 3409 Years to find all possible combinations. This time is sufficiently large for any message to reside on any network [5].
III. PROPOSED ENCRYPTION ALGORITHM:
Step 1. Read (String) : Number of Characters
Step 2. Count Characters (N)
Step 3. If N<10 then Return
Step 4. Convert each character into corresponding binary code using Extended ASCII Code thus we get 8N bits for input data containing N characters
Step 5. Create a string of 0’s and 1’s such that total number of 0’s and 1’s is 8N, the consecutive numbers of 0’s and 1’s in this string may be from 1 to 7
Step 6. Use XOR Gate on binary strings obtained at steps 4 and 5
Step 7. Convert binary string obtained at stage six into corresponding characters using reverse Extended ASCII Code.
Step 8. Print Output i.e., Cipher Text
IV. SCHEMATIC DIAGRAM FOR PROPOSED ALGORITHM
V. PSEUDO CODE FOR PROPOSED ENCRYPTION ALGORITHM
// Read the input string of characters and Check the number of characters N, if N is less than 10, give error message
Step 1: Start
Step 2: Read input N
Step 3: If (N.length()< 10)
Print error message ‘Program is Not Applicable’;
//Convert N characters into binary form using Extended ASCII Code
Step 4: initialize character array str[]// copying each character from the string of N
characters to character array str[]
Step 5: for(i=0; i<N.length(); i++)
{
If(i==N.length() – 1)
Str[i] = N.substring(i);
else
Str[i] = N.substring(i, i+1);
}
Step 6: initialize byte array bytes[] // copy each character from the string of N characters
of character array converted to byte char
Step 7: for(i=0; i<str.length; i++)
{
bytes[i]= (byte) Str[i];
}
Step 8: for each byte in array, convert each byte to binary bits and create string of those
binary bits
// Generate a string of consecutive 0’s and 1’s such that no. of consecutive 0’s and 1’s is 1 to 7 and length of this binary string is 8 N
Step 9: Read value of ck // number of 0’s and 1’s to occur consecutively
Step 10 : string st = „‟; // empty string
Step 11 : bitsetb1[l]; bitsetb2[l];
Step 12 : for(integer i=0; i<l; i++) // Loop on string of all bits
{
ifa1[i] = = 1
set bit in bitset b1;
}
for(integer i=0; i<l; i++) // Loop on string of all bits
{
if((i%(2*ck))<ck)
st=st+"0";
else
{
st=st+"1";
Set bit in bitset „b2‟;
}
}
Step 13: print bits string and string „st‟ string on which XOR operations is being
performed
Step 14: b1.xor (b2); // apply XOR operation on obtained strings
Step 15: st = „‟; // clear string „st‟ to store the result after XOR operation string
Step 16: for (i=0;i<l;i++)
{
If (b1.get (i))
st=st + "1";
else
st=st + "0";
}
// Convert 8N bits so obtained into the characters of N characters using reverse Extended ASCII Code
Step 17: String s2 = ‘’;
Step 18: String s=binary; // to store the binary string
Step 19: char nextChar; // declare the variable to store next significant character in string
Step 20: for(inti = 0; i<s.length(); i += 8) //this is a little tricky, as we want [0, 7], [9, 16], etc
{
nextChar = Integer value of s.substring(i, i+8);
s2 = s2 + nextChar;
}
Step 21: return s2 to output file // return the final string
The decryption algorithm is just the reverse of the encryption algorithm
VI. IMPLEMENTATION OF PROPOSED ALGORITHM :
The author has implemented the said proposed algorithm on Java platform for different values of Ck = 1 to 7 e.g., for input data :
“Ambala Cantt is situated on the North-Eastern edge of Haryana. It is known as City of Scientific Instruments on International level. It is gate way to Chandigarh, Panjab, Himachal Pradesh and Jammu & Kashmir”
S. No. |
Key Ck |
Cipher Text |
1. |
1 |
87494u4;!!u<&u&<! 4!01u:;u!=0u:'!=x4&!0';u0120u:3u 4',4;4{u!u<&u>;:";u4&u<!,u:3u6<0;!<3<6u;&!' 80;!&u:;u;!0';4!<:;49u90#09{u!u<&u24!0u"4,u!:u=4;1<24'=yu4;?47yu<846=49u'410&=u4;1u488 usu‑4&=8<' |
2. |
3 |
]Ñ}ª<2ªr│<┤<«hªhú<‑⌐<»yQ?s│t\?}│y⌐<ú{τsτT╡e⌐}_τUτuτw¿kτ}τ_│eQ¿zQ?ór«zñ<8⌐o╡i ór┤<‑⌐<8⌐h╡r│u‑⌐}τp▒yΘ<8│<┤<ªhτk╛<¿<2»}úuªnδ<!ªrª~]τT¬}»}τLªx┤tQªrτV¬qτ:Q?}»q╡ |
3. |
4 |
Nbmncn/Lna{{/f|/|f{zn{jk/`a/{gj/A`}{g"Jn|{j}a/jkhj/`i/Gn}vnan!/F{/f|/da`xa/n|/Lf{v/`i/\lfja{fifl/Fa|{}zbja{|/`a/Fa{j}an{f`anc/cjyjc!/F{/f|/hn{j/xnv/{`/Lgnakfhn}g#/_naenm#/Gfbnlgnc/_}nkj|g/nak/Enbbz/)/Dn|gbf} |
4. |
5 |
F¼?sfß│qs╡╨l'▓?jf╡??h»╨wbß╛ms⌐▌9~t╡? q'ñ?z'«?\Wf│?qf∩╨5k'¿?\ti«??f▓╨?vs╕╨y'??zi╡?vdß╣ls│?zi╡?\piß╣kb│?kn«?s'¡? zk∩╨5k'¿?\xf╡?\hf╕╨p'??qc¿?moφ╨, ~i½?‑3'??~d⌐??W│?zt⌐╨qcß║rj┤╨Z?Lá?rn│ |
5. |
6 |
B?]b?^#│^m?K#?L#?Vw?^w?[#?Q#?Wf╨ql?Kk▌zb?Kf?Q#?[d?l?K?Mz?Qb▐J?j?h?Pt?b?@?Kz╨Pe╨l`?Zm?Ve?\#╣Qp?Mv?Zm?L#?Q #╣Qw?Mm?Kj?Qb?o?If?#╣K#?L#?^w?t?F#?P#│Wb?[j?^q?#á^m?^a▄K?Rb?Wb?S?^g?Lk╨^m?I?Rn?%╨tb?Wn?M |
6. |
7 |
@?e?sí_B?i?kαr▄t?k╡‑u?c╨p«_u?b╨Q» u?*╡~│ d?i╨zñ d▄h???‑s?f?~ε_H?'?lαo?p??í !┐n?fαg▄T?vÑu?a?|α6o?s?j¡ o?t╨p«_H?s?m «‑u?h?~¼_m?q?sε_H?'?lα`?b╨hí!?h╨\¿‑o?n?~▓-▄W?q¬‑c╨'╕v¡‑b?f??? `?b?wα‑o?'║~¡t▄!╨Tí i?n? |
VII. RESULTS AND DISCUSSION:
From the above Table, it is clear that if we change the key Ck from 1 to 7 then output of the proposed algorithm i.e., Cipher Text is entirely different.
VIII. CONCLUSION:
The proposed scheme was tested in Java platform for different values of Ck = 1 to 7. In all cases the result came as per the literature and work seems to be satisfactory based on security metrics. It has been estimated that to crack the code we will require more time than the data will reside on the medium to travel. So, it can be said that the proposed scheme will produce an efficient secured algorithm for data transfer in both wired and wireless networks.
REFERENCES:
1. S. K. Garg, Review of Secured Routing for Wireless Ad hoc Network, International Journal of Computing and Business Research, 2 (1), 2011.
2. S. K. Garg, Wireless Network Security Threats, International Journal of Information Dissemination and Technology, 1 (1), 2011.
3. T. Karygiannis and L. Owens, Wireless Network Security, NIST Special Publication, 2002.
4. William Stallings, Cryptography and Network Security: Principles and Practice, Prentice Hall, 5th Edition, 2011.
5. R. H. Karpinski, Reply to Hoffman and Shaw, Datamation, 16(10) p. 11 (Oct. 1970)
6. S, K. Garg, Cryptography Using Controlled NOT Gate : Algorithm SKG 3.00, International Journal of Electronics Engineering, 6 (1), 20-24, 2014
Received on 16.11.2016 Modified on 24.11.2016 Accepted on
30.11.2016 ©A&V Publications All right
reserved DOI:
10.5958/2349-2988.2017.00004.3 Research J. Science and Tech. 2017; 9(1):25-28.
|
|