Skip to content

Instantly share code, notes, and snippets.

@darkk
Last active August 29, 2015 14:04
Show Gist options
  • Save darkk/e1621ee784f081ffca76 to your computer and use it in GitHub Desktop.
Save darkk/e1621ee784f081ffca76 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
from Crypto.Cipher import DES, DES3
import struct
def run(des_k1):
shown_to_user = []
print "==> Shown to user"
for i in xrange(5):
enc_i = struct.unpack('>Q', des_k1.encrypt(struct.pack('>Q', i)))[0]
print repr(struct.pack('>Q', i)), repr(des_k1.encrypt(struct.pack('>Q', i))), enc_i
print enc_i
shown_to_user.append(enc_i)
print "==> In database"
for i in shown_to_user:
db_i = struct.unpack('>Q', des_k1.decrypt(struct.pack('>Q', i)))[0]
print db_i
# NB: DES3 requires better randomndess of key :-)
run(DES.new('P@ssw0rd', mode=DES.MODE_ECB))
run(DES3.new('P@ssw0rdP@ssw0rdP@ssw0rd', mode=DES3.MODE_ECB))
[18:20] *@* ~ 1 bg $ python int64des.py
==> Shown to user
'\x00\x00\x00\x00\x00\x00\x00\x00' ']\xdf\xeekh\x825\xab' 6764387310416049579
6764387310416049579
'\x00\x00\x00\x00\x00\x00\x00\x01' '=8Z\xe4`\xbe\xba\x92' 4411375771931556498
4411375771931556498
'\x00\x00\x00\x00\x00\x00\x00\x02' 'Di\x04\xff\xb9\x1e\xder' 4929476763502698098
4929476763502698098
'\x00\x00\x00\x00\x00\x00\x00\x03' '\xa2\xaaw\xdaRT+\xa1' 11721312759752960929
11721312759752960929
'\x00\x00\x00\x00\x00\x00\x00\x04' 'zx\xf2\xa5\x13\x0056' 8825070260634793270
8825070260634793270
==> In database
0
1
2
3
4
==> Shown to user
'\x00\x00\x00\x00\x00\x00\x00\x00' ']\xdf\xeekh\x825\xab' 6764387310416049579
6764387310416049579
'\x00\x00\x00\x00\x00\x00\x00\x01' '=8Z\xe4`\xbe\xba\x92' 4411375771931556498
4411375771931556498
'\x00\x00\x00\x00\x00\x00\x00\x02' 'Di\x04\xff\xb9\x1e\xder' 4929476763502698098
4929476763502698098
'\x00\x00\x00\x00\x00\x00\x00\x03' '\xa2\xaaw\xdaRT+\xa1' 11721312759752960929
11721312759752960929
'\x00\x00\x00\x00\x00\x00\x00\x04' 'zx\xf2\xa5\x13\x0056' 8825070260634793270
8825070260634793270
==> In database
0
1
2
3
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment