Automatic B64 detection for decoding

py3
panki27 7 years ago
parent dd8084d7eb
commit 8bfd7b2468

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, string, types, hashlib, base64 import sys, string, types, hashlib, base64, re
LOWER_LETTERS = [chr(x) for x in range(97, 123)] LOWER_LETTERS = [chr(x) for x in range(97, 123)]
UPPER_LETTERS = [chr(x) for x in range(65, 91)] UPPER_LETTERS = [chr(x) for x in range(65, 91)]
@ -61,13 +61,13 @@ def translate(inputString, inputType, outputType):
result = chr(inputString) result = chr(inputString)
return result return result
def base64prompt(): def base64prompt():
choice = raw_input('Would you like to [e]ncode or [d]ecode? ') b64regex = '\S*=$'
if (choice == 'e'): inputString = raw_input('Please input your string: ')
inputString = raw_input("String to encode: ") match = re.match(b64regex, inputString)
print(base64.b64encode(inputString)) if (match):
else:
inputString = raw_input("String to decode: ")
print(base64.b64decode(inputString)) print(base64.b64decode(inputString))
else:
print(base64.b64encode(inputString))
def rotPrompt(): def rotPrompt():
@ -125,9 +125,7 @@ print("1: ROT/Ceasar Encryption")
print("2: Hashing functions") print("2: Hashing functions")
print("3: Translation") print("3: Translation")
print("4: Base64 Encoder/Decoder") print("4: Base64 Encoder/Decoder")
choice = input("Please make a selection: ") choice = input("Please make a selection: ")
if (choice == 1): if (choice == 1):
rotPrompt() rotPrompt()
elif (choice == 2): elif (choice == 2):

Loading…
Cancel
Save