aboutsummaryrefslogtreecommitdiff
path: root/pypride.py
diff options
context:
space:
mode:
Diffstat (limited to 'pypride.py')
-rw-r--r--pypride.py197
1 files changed, 96 insertions, 101 deletions
diff --git a/pypride.py b/pypride.py
index f055b92..458206f 100644
--- a/pypride.py
+++ b/pypride.py
@@ -1,6 +1,6 @@
# Python PRIDE implementation
# Version: 1.0
-# Date: 22/04/2015
+# Date: 23/04/2015
#
# =============================================================================
#
@@ -82,102 +82,104 @@ 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],
- [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],
- [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,0],
- [0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1],
- [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],
- [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,0,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],
+ [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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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,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],
- [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,0],
- [0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1]]
+ [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],
+ [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,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,0],
+ [0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1],
+ [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,0],
+ [0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1]]
L3_inv = L3
def mapXor(xs):
@@ -295,11 +297,4 @@ def number2string_N(i, N):
Output: string (big-endian)
"""
s = '%0*x' % (N*2, i)
- return s.decode('hex')
-
-if __name__ == "__main__":
- cipher = Pride("0000000000000000fedcba9876543210".decode('hex'))
- encryption = cipher.encrypt("0123456789abcdef".decode('hex'))
- print encryption.encode('hex')
- decryption = cipher.decrypt(encryption)
- print decryption.encode('hex') \ No newline at end of file
+ return s.decode('hex') \ No newline at end of file