Anonymous user
Data Encryption Standard: Difference between revisions
→{{header|Python}}: edit 32.11.18: removed the long message as there were issues with padding rsulting in wron encrypted message.
(→{{header|Python}}: edit 32.11.18: removed the long message as there were issues with padding rsulting in wron encrypted message.) |
|||
Line 1,296:
=={{header|Python}}==
implemented like in the article linked in description. <br>
really good article btw
<lang Python>#!/usr/bin/python
#!/usr/bin/python
# Permutation tables and Sboxes
IP = (
Line 1,414 ⟶ 1,416:
22, 11, 4, 25
)
if key.bit_length() > 64:▼
if msg.bit_length() > 64:▼
def encrypt(msg, key, decrypt=False):
# only encrypt single blocks
assert isinstance(msg, int) and isinstance(key, int)
# permutate by table PC1
Line 1,482 ⟶ 1,454:
return cipher_block
def round_function(Ri, Ki):
Line 1,557 ⟶ 1,528:
k = 0x0e329232ea6d0d73 # 64 bit
k2 = 0x133457799BBCDFF1
m = 0x8787878787878787
m2 = 0x0123456789ABCDEF
def prove(key, msg):
print('key: {:x}'.format(key))
print('message: {:x}'.format(msg))
cipher_text =
print('encrypted: {:x}'.format(cipher_text))
plain_text =
print('decrypted: {:x}'.format(plain_text))
prove(k, m)
print('----------')
prove(
</lang>
{{Out}}
Note: This is just the algorithm for single 64-bit blocks. No padding or block chipher operation mode
<pre>key: e329232ea6d0d73
message: 8787878787878787
Line 1,578 ⟶ 1,552:
decrypted: 8787878787878787
----------
key:
message: 123456789abcdef
encrypted: 85e813540f0ab405
decrypted: 123456789abcdef</pre>
=={{header|REXX}}==
|