diff options
author | Camil Staps | 2015-04-23 09:30:44 +0200 |
---|---|---|
committer | Camil Staps | 2015-04-23 09:30:44 +0200 |
commit | 58aad98659ac50e76989dc612619f57541f99bdd (patch) | |
tree | 54baff08ebd950346f4e95f7ae6a3eb9826f7ff0 /pypride.py | |
parent | Readme (diff) |
Added test vectors
Diffstat (limited to 'pypride.py')
-rw-r--r-- | pypride.py | 197 |
1 files changed, 96 insertions, 101 deletions
@@ -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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,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 |