Skip to content

Instantly share code, notes, and snippets.

@rikaardhosein
Created July 14, 2013 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikaardhosein/5992879 to your computer and use it in GitHub Desktop.
Save rikaardhosein/5992879 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import base64
import struct
filename = sys.argv[1]
file_contents = open(filename,'rb').read()
base64_encoded_info = file_contents.split(' ')[1]
raw_bytes = base64.b64decode(base64_encoded_info)
length = struct.unpack('>I',raw_bytes[0:4])[0]
raw_bytes = raw_bytes[4:]
data = raw_bytes[0:length]
print 'Obtained string: %s'%(data)
raw_bytes = raw_bytes[length:]
exponent_size = struct.unpack('>I',raw_bytes[0:4])[0]
print 'Exponent size: %d'%(exponent_size)
raw_bytes = raw_bytes[4:]
exponent = 0
for i in range(0,exponent_size):
exponent<<=8
exponent += ord(raw_bytes[i])
print 'Exponent: '+str(exponent)
raw_bytes = raw_bytes[exponent_size:]
modulus_size = struct.unpack('>I',raw_bytes[0:4])[0]
raw_bytes = raw_bytes[4:]
print 'Modulus size: %d'%(modulus_size)
modulus = 0
for i in range(0,modulus_size):
modulus<<=8
modulus += ord(raw_bytes[i])
print 'Modulus: '+str(modulus)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment