From af85d98a7e9fa5684bef7ec328d702e531ed6c48 Mon Sep 17 00:00:00 2001 From: adityag3 Date: Mon, 22 Aug 2016 23:14:58 +0530 Subject: [PATCH 1/2] Adding script to perform CFB mode of encryption --- implementation.py | 33 +++++++++++++++++++++++++++++++++ setup.py | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 implementation.py mode change 100644 => 100755 setup.py diff --git a/implementation.py b/implementation.py new file mode 100644 index 0000000..92216bf --- /dev/null +++ b/implementation.py @@ -0,0 +1,33 @@ +import pyaes + +# A 256 bit (32 byte) key +key = "123456789012345ef890123456789012" + +# For some modes of operation we need a random initialization vector +# of 16 bytes +iv = "9988776655443310" + + +# Each block into the mode of operation must be a multiple of the segment +# size. For this example we choose 8 bytes. +aes = pyaes.AESModeOfOperationCFB(key, iv = iv, segment_size = 4) +plaintext = "1234567890123456" +ciphertext = aes.encrypt(plaintext) + +# '''v\xa9\xc1w"\x8aL\x93\xcb\xdf\xa0/\xf8Y\x0b\x8d\x88i\xcb\x85rmp +# \x85\xfe\xafM\x0c)\xd5\xeb\xaf''' +#print repr(ciphertext) + + +# The cipher-block chaining mode of operation maintains state, so +# decryption requires a new instance be created +aes = pyaes.AESModeOfOperationCFB(key, iv = iv, segment_size = 4) +decrypted = aes.decrypt(ciphertext) +#print decrypted +# True +#print decrypted == plaintext + +print "Unencrypted data: ", plaintext +print "Encrypted data : ", ciphertext +print "Decrypted data : ", decrypted +print "Enc == Dec : ", decrypted == plaintext diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 884701d..f2d5235 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/python from distutils.core import setup From 3f2bc626874b0186317c2e6e6106c738baf4eb93 Mon Sep 17 00:00:00 2001 From: adityag3 Date: Mon, 31 Oct 2016 16:07:10 +0530 Subject: [PATCH 2/2] demo code file added --- implementation.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/implementation.py b/implementation.py index 92216bf..b7dce2d 100644 --- a/implementation.py +++ b/implementation.py @@ -1,4 +1,5 @@ import pyaes +from time import time # A 256 bit (32 byte) key key = "123456789012345ef890123456789012" @@ -10,23 +11,29 @@ # Each block into the mode of operation must be a multiple of the segment # size. For this example we choose 8 bytes. +s = time() aes = pyaes.AESModeOfOperationCFB(key, iv = iv, segment_size = 4) -plaintext = "1234567890123456" +plaintext = "baf9dffc8b690539" ciphertext = aes.encrypt(plaintext) # '''v\xa9\xc1w"\x8aL\x93\xcb\xdf\xa0/\xf8Y\x0b\x8d\x88i\xcb\x85rmp # \x85\xfe\xafM\x0c)\xd5\xeb\xaf''' #print repr(ciphertext) - +p = time() +m = time() - s +print m # The cipher-block chaining mode of operation maintains state, so # decryption requires a new instance be created aes = pyaes.AESModeOfOperationCFB(key, iv = iv, segment_size = 4) decrypted = aes.decrypt(ciphertext) + +print time() - p #print decrypted # True #print decrypted == plaintext +print "CFB Mode" print "Unencrypted data: ", plaintext print "Encrypted data : ", ciphertext print "Decrypted data : ", decrypted