Jump to content
Gabriel87

[Python] B64 Decoder/Encoder

Recommended Posts

Posted
#!/usr/bin/env python
#Name: b64.py
#Author: s3my0n

from base64 import b64decode
from base64 import b64encode
import sys

def Decode(enc_string):
try:
dec_string = b64decode(enc_string)
except TypeError:
print '\nTypeError: not a valid base64 hash'
sys.exit(1)
return dec_string

def Encode(string):
enc_string = b64encode(string)
return enc_string

if __name__ == '__main__':
opts = ('-de', '-en')
if (len(sys.argv) != 3) or (sys.argv[1] not in opts):
print '\nBase64 encoder/decoder'
print 'Coded by RuSH4ck3R aka s3my0n'
print '\nUsage: b64.py [-de, -en] [hash, string]'
print '\nExample: b64.py -en mypassword'
print ' b64.py -de bXlwYXNzd29yZA=='
sys.exit()
if sys.argv[1] == opts[0]:
print '%s' % (Decode(sys.argv[2]))
if sys.argv[1] == opts[1]:
print '%s' % (Encode(sys.argv[2]))

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...