Introduction

Cryptography is used for security purposes. There are not so many examples of Encryption/Decryption in Python using IDEA encryption MODE CTR. Aim of this documentation :

Extend and implement of the RSA Digital Signature scheme in station-to-station communication. Using Hashing for integrity of message, that is SHA-1. Produce simple Key Transport protocol. Encrypt Key with IDEA encryption. Mode of Block Cipher is Counter Mode

Remarks

Language Used: Python 2.7 (Download Link: https://www.python.org/downloads/ )

Library Used:

*PyCrypto (Download Link: https://pypi.python.org/pypi/pycrypto )

*PyCryptoPlus (Download Link: https://github.com/doegox/python-cryptoplus )

Library Installation:

PyCrypto: Unzip the file. Go to the directory and open terminal for linux(alt+ctrl+t) and CMD(shift+right click+select command prompt open here) for windows. After that write python setup.py install (Make Sure Python Environment is set properly in Windows OS)

PyCryptoPlus: Same as the last library.

Tasks Implementation: The task is separated into two parts. One is handshake process and another one is communication process. Socket Setup:

**----------Client Side----------**

   server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
   host = raw_input("Server Address To Be Connected -> ")
   port = int(input("Port of The Server -> "))
   server.connect((host, port))

**----------Server Side---------**

   try:
   #setting up socket
   server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)     
   server.bind((host,port))
   server.listen(5)
   except BaseException: print "-----Check Server Address or Port-----"

“ socket.AF_INET,socket.SOCK_STREAM” will allow us to use accept() function and messaging fundamentals. Instead of it, we can use “ socket.AF_INET,socket.SOCK_DGRAM” also but that time we will have to use setblocking(value) .

Handshake Process:

random_generator = Random.new().read
    key = RSA.generate(1024,random_generator) 
    public = key.publickey().exportKey()

random_generator is derived from “from Crypto import Random” module. Key is derived from “from Crypto.PublicKey import RSA” which will create a private key, size of 1024 by generating random characters. Public is exporting public key from previously generated private key.