Jump to content
MrGrj

[Python] Simple Base64 Encryption / Decryption Tool

Recommended Posts

  • Active Members
Posted (edited)

Un programel simplu facut in pauza de masa. Enjoy:


__author__ = "MrGrj"

import binascii

def bas64decryption():
encoded_string = raw_input("Please insert the base64 encrypted text:")
decoded_string = encoded_string.decode('base64')

if encoded_string is None:
print 'You inserted a null string. Please enter a valid string next time !'
else:
print 'Your decoded string:' + ' ' + decoded_string

def base64encryption():
decoded_string = raw_input("Please insert the text that you want to encode:")
encoded_string = decoded_string.encode('base64')

if decoded_string is None:
print 'You inserted a null string. Please enter a valid string next time !'
else:
print 'Your encoded string:' + ' ' + encoded_string

if __name__ == "__main__":
menu = {}
menu['1'] = "Base 64 decryption."
menu['2'] = "Base 64 encryption."
menu['3'] = "Exit."
while True:
options = menu.keys()
options.sort()
for entry in options:
print entry, menu[entry]

selection = raw_input("What would you like to do? ")
if selection == "1":
try:
bas64decryption()
except binascii.Error:
print "This is not a base64 encoded string!"

elif selection == "2":
try:
base64encryption()
except binascii.Error:
print "Something went wrong! Please try again"

elif selection == "3":
print "Bye-bye"
break
else:
print "This is not a valid choice !"

O sa revin cu update-uri in topicul asta cu alte functii de decoding / encoding. Apoi, cu restul membrilor care stiu python sa facem ceva misto, optimizat, etc. Asta daca se vrea si eu timp. @MasterLight

Edited by MrGrj
Posted

M-am tot uitat si nu intelegeam de ce-ai importat binascii pentru asta, tinand cont ca pe stringuri ai functia built-in encode/decode. Apoi am vazut ca e pentru exceptie.

Heh, funny.

  • Active Members
Posted
O simpla observatie, de ce bas64encryption() decodeaza textul base64 si base64decryption(): il encodeaza? Nu ar trebui sa fie invers numele?

Da, typo. Thanks

@alecseu teoretic asta era ideea sa fac fara nici un import dar arata urat eroarea aia daca bagai un string aiurea :D

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...