From 8bdc94b368b8558a9b73235064e002abfaf86774 Mon Sep 17 00:00:00 2001 From: phil Date: Fri, 10 Oct 2008 22:22:25 +0000 Subject: [PATCH] Minor changes: range->xrange, [].extend(.. for i) -> [... for i] git-svn-id: svn+ssh://devel.yobi.be/home/svn/CryptoPlus/trunk@88 49921240-e1b6-4d8d-af3b-5ae6c3d9e7c1 --- src/CryptoPlus/Cipher/pypresent.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/CryptoPlus/Cipher/pypresent.py b/src/CryptoPlus/Cipher/pypresent.py index b4ef8d4..ddf5613 100644 --- a/src/CryptoPlus/Cipher/pypresent.py +++ b/src/CryptoPlus/Cipher/pypresent.py @@ -24,7 +24,7 @@ class Present: ciphertext will be returned. """ state = string2number(block) - for i in range (1,self.rounds): + for i in xrange (1,self.rounds): state = addRoundKey(state,self.roundkeys[i-1]) state = sBoxLayer(state) state = pLayer(state) @@ -38,7 +38,7 @@ class Present: plaintext will be returned. """ state = string2number(block) - for i in range (1,self.rounds): + for i in xrange (1,self.rounds): state = addRoundKey(state,self.roundkeys[self.rounds-i]) state = pLayer_dec(state) state = sBoxLayer_dec(state) @@ -50,21 +50,19 @@ class Present: # 0 1 2 3 4 5 6 7 8 9 a b c d e f Sbox= [0xc,0x5,0x6,0xb,0x9,0x0,0xa,0xd,0x3,0xe,0xf,0x8,0x4,0x7,0x1,0x2] -Sbox_inv = [] -Sbox_inv.extend(Sbox.index(x) for x in range(16)) +Sbox_inv = [Sbox.index(x) for x in xrange(16)] PBox = [0,16,32,48,1,17,33,49,2,18,34,50,3,19,35,51, 4,20,36,52,5,21,37,53,6,22,38,54,7,23,39,55, 8,24,40,56,9,25,41,57,10,26,42,58,11,27,43,59, 12,28,44,60,13,29,45,61,14,30,46,62,15,31,47,63] -PBox_inv = [] -PBox_inv.extend(PBox.index(x) for x in range(64)) +PBox_inv = [PBox.index(x) for x in xrange(64)] def generateRoundkeys80(key,rounds): """Generate the roundkeys for a 80 bit key Give a 80bit hex string as input and get a list of roundkeys in return""" roundkeys = [] - for i in range(1,rounds+1): # (K1 ... K32) + for i in xrange(1,rounds+1): # (K1 ... K32) # rawkey: used in comments to show what happens at bitlevel # rawKey[0:64] roundkeys.append(key >>16) @@ -84,7 +82,7 @@ def generateRoundkeys128(key,rounds): Give a 128bit hex string as input and get a list of roundkeys in return""" roundkeys = [] - for i in range(1,rounds+1): # (K1 ... K32) + for i in xrange(1,rounds+1): # (K1 ... K32) # rawkey: used in comments to show what happens at bitlevel roundkeys.append(key >>64) #1. Shift @@ -105,7 +103,7 @@ def sBoxLayer(state): Takes a hex string as input and will output a hex string""" output = 0 - for i in range(0,16): + for i in xrange(16): output += Sbox[( state >> (i*4)) & 0xF] << (i*4) return output @@ -114,8 +112,8 @@ def sBoxLayer_dec(state): Takes a hex string as input and will output a hex string""" output = 0 - for i in range(0,16): - output += Sbox_inv[(( state >> (i*4)) & 0xF)] << (i*4) + for i in xrange(16): + output += Sbox_inv[( state >> (i*4)) & 0xF] << (i*4) return output def pLayer(state): @@ -123,7 +121,7 @@ def pLayer(state): Takes a 64bit hex string as input and will output a 64bit hex string""" output = 0 - for i in range(64): + for i in xrange(64): output += ((state >> i) & 0x01) << PBox[i] return output @@ -132,7 +130,7 @@ def pLayer_dec(state): Takes a 64bit hex string as input and will output a 64bit hex string""" output = 0 - for i in range(64): + for i in xrange(64): output += ((state >> i) & 0x01) << PBox_inv[i] return output -- 2.11.4.GIT