aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2015-04-23 13:33:20 +0200
committerCamil Staps2015-04-23 13:33:20 +0200
commit40f72b49017c7c4449092d32ca1cdc25520db0b2 (patch)
treeabccc5d14c01fc507e4d3e9ac79f22ad630b1519
parentPerformance (diff)
Cleanup
-rw-r--r--pypride.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/pypride.py b/pypride.py
index c011f74..82788d4 100644
--- a/pypride.py
+++ b/pypride.py
@@ -127,7 +127,8 @@ PBox = [0, 16, 32, 48, 1, 17, 33, 49, 2, 18, 34, 50, 3, 19, 35, 51, 4, 20, 36, 5
PBox_inv = [PBox.index(x) for x in xrange(64)]
# Matrices for permutation in the L layer
-L0 = [[0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0],
+L0_inv = L0 = [
+ [0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0],
[0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0],
[0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0],
[0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
@@ -143,7 +144,6 @@ L0 = [[0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0],
[0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0],
[0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0],
[0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,0]]
-L0_inv = L0
L1 = [[1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0],
[0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0],
[0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0],
@@ -210,7 +210,8 @@ L2_inv = [
[0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0],
[0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0],
[0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1]]
-L3 = [[1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
+L3_inv = L3 = [
+ [1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0],
[0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0],
[0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1],
@@ -226,7 +227,6 @@ L3 = [[1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0],
[0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0],
[0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0],
[0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1]]
-L3_inv = L3
def mapXor(xs):
"""Xor elements of a list together"""
@@ -239,8 +239,8 @@ def matrixMultiply(matrix, input):
input as Int
Output: Int"""
- mult = [ mapXor([1 for c_i, c in enumerate(r) if c == 1 and input & (0x1 << (15 - c_i))]) for r in matrix ]
- return sum([(1 << (15-i)) * v for i,v in enumerate(mult)])
+ mult = [mapXor([1 for i,c in enumerate(r) if c == 1 and input & (1 << (15 - i))]) for r in matrix]
+ return sum([(1 << (15 - i)) * v for i,v in enumerate(mult)])
def roundKey(key, i):
"""Calculate a round key
@@ -269,7 +269,7 @@ def sBoxLayer(state):
Input: 64-bit integer
Output: 64-bit integer"""
- return sum([Sbox[( state >> (i*4)) & 0xF] << (i*4) for i in xrange(16)])
+ return sum([Sbox[( state >> (i * 4)) & 0xf] << (i * 4) for i in xrange(16)])
def sBoxLayer_dec(state):
"""Inverse SBox function for decryption
@@ -277,7 +277,7 @@ def sBoxLayer_dec(state):
Input: 64-bit integer
Output: 64-bit integer"""
- return sum([Sbox_inv[( state >> (i*4)) & 0xF] << (i*4) for i in xrange(16)])
+ return sum([Sbox_inv[( state >> (i * 4)) & 0xf] << (i * 4) for i in xrange(16)])
def pLayer(state):
"""Permutation layer for encryption
@@ -285,7 +285,7 @@ def pLayer(state):
Input: 64-bit integer
Output: 64-bit integer"""
- return sum ([((state >> i) & 0x01) << PBox[i] for i in xrange(64)])
+ return sum ([((state >> i) & 1) << PBox[i] for i in xrange(64)])
def pLayer_dec(state):
"""Permutation layer for decryption
@@ -293,7 +293,7 @@ def pLayer_dec(state):
Input: 64-bit integer
Output: 64-bit integer"""
- return sum ([((state >> i) & 0x01) << PBox_inv[i] for i in xrange(64)])
+ return sum ([((state >> i) & 1) << PBox_inv[i] for i in xrange(64)])
def lLayer(state):
"""Perform the L layer:
@@ -333,7 +333,7 @@ def string2number(i):
Input: string (big-endian)
Output: long or integer
"""
- return int(i.encode('hex'),16)
+ return int(i.encode('hex'), 16)
def number2string_N(i, N):
"""Convert a number to a string of fixed size